Beispiel #1
0
func testEchoPlugin(cc net.Conn, c *C) {
	bps := []byte{1, 2, 3, 4, 5}
	m := msg.CreateWithName("test-name")
	m.SetHeader("hdr1", "val1")
	m.SetHeader("hdr2", "val2")
	m.SetBodyPart("bp1", bps)

	err := msg.Serialize(m, cc)
	printCause(c, err)
	c.Assert(err, IsNil)

	m2, err := msg.Deserialize(cc)
	c.Assert(err, IsNil)
	c.Assert(m2.GetName(), Equals, m.GetName())
	c.Assert(m2.Header("hdr1"), Equals, m.Header("hdr1"))
	c.Assert(m2.Header("hdr2"), Equals, m.Header("hdr2"))
	c.Assert(m2.BodyPart("bp1"), DeepEquals, bps)
}
Beispiel #2
0
func (b *bridge) makePluginsHandler(listener string) Handler {
	return func(conn net.Conn) {
		m, err := msg.Deserialize(conn)
		if err != nil {
			log.Printf("Bridge local plugin handler message deserialization error: %t", err)
			return
		}

		for _, p := range b.plugins {
			if p.SupportsMessage(m.GetName()) {
				rm := p.HandleMessage(m, b)
				if err := msg.Serialize(rm, conn); err != nil {
					log.Printf("Bridge local plugin handler message serialization error: %v", err)
					break
				}
				break
			}
		}
	}
}