Esempio n. 1
0
func (c *clientCodec) ReadHeader(m *codec.Message) error {
	c.resp.reset()
	if err := c.dec.Decode(&c.resp); err != nil {
		return err
	}

	c.Lock()
	m.Method = c.pending[c.resp.ID]
	delete(c.pending, c.resp.ID)
	c.Unlock()

	m.Error = ""
	m.Id = c.resp.ID
	if c.resp.Error != nil {
		x, ok := c.resp.Error.(string)
		if !ok {
			return fmt.Errorf("invalid error %v", c.resp.Error)
		}
		if x == "" {
			x = "unspecified error"
		}
		m.Error = x
	}
	return nil
}
Esempio n. 2
0
func (s *serverCodec) ReadHeader(m *codec.Message) error {
	r := &request{}
	if err := bson.UnmarshalFromStream(s.rwc, r); err != nil {
		return err
	}
	m.Id = r.Seq
	m.Method = r.ServiceMethod
	return nil
}
Esempio n. 3
0
func (c *clientCodec) ReadHeader(m *codec.Message) error {
	r := &response{}
	if err := bson.UnmarshalFromStream(c.rwc, r); err != nil {
		return err
	}
	m.Id = r.Seq
	m.Method = r.ServiceMethod
	m.Error = r.Error
	return nil
}
Esempio n. 4
0
// ReadHeader reads the header from the wire.
func (c *msgpackCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {
	c.mt = mt

	switch mt {
	case codec.Request:
		var h Request

		if err := msgp.Decode(c.rwc, &h); err != nil {
			return err
		}

		c.body = h.hasBody
		m.Id = uint64(h.ID)
		m.Method = h.Method

	case codec.Response:
		var h Response

		if err := msgp.Decode(c.rwc, &h); err != nil {
			return err
		}

		c.body = h.hasBody
		m.Id = uint64(h.ID)
		m.Error = h.Error

	case codec.Publication:
		var h Notification

		if err := msgp.Decode(c.rwc, &h); err != nil {
			return err
		}

		c.body = h.hasBody
		m.Method = h.Method

	default:
		return errors.New("Unrecognized message type")
	}

	return nil
}
Esempio n. 5
0
func (c *protoCodec) ReadHeader(m *codec.Message, mt codec.MessageType) error {
	c.buf.Reset()
	c.mt = mt

	switch mt {
	case codec.Request:
		data, err := ReadNetString(c.rwc)
		if err != nil {
			return err
		}
		rtmp := new(Request)
		err = proto.Unmarshal(data, rtmp)
		if err != nil {
			return err
		}
		m.Method = *rtmp.ServiceMethod
		m.Id = *rtmp.Seq
	case codec.Response:
		data, err := ReadNetString(c.rwc)
		if err != nil {
			return err
		}
		rtmp := new(Response)
		err = proto.Unmarshal(data, rtmp)
		if err != nil {
			return err
		}
		m.Method = *rtmp.ServiceMethod
		m.Id = *rtmp.Seq
		m.Error = *rtmp.Error
	case codec.Publication:
		io.Copy(c.buf, c.rwc)
	default:
		return fmt.Errorf("Unrecognised message type: %v", mt)
	}
	return nil
}
Esempio n. 6
0
func (c *serverCodec) ReadHeader(m *codec.Message) error {
	c.req.reset()
	if err := c.dec.Decode(&c.req); err != nil {
		return err
	}
	m.Method = c.req.Method

	c.Lock()
	c.seq++
	c.pending[c.seq] = c.req.ID
	c.req.ID = nil
	m.Id = c.seq
	c.Unlock()

	return nil
}