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 }
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 }
// 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 }
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 }