Esempio n. 1
0
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	c.resp.reset()
	if err := c.dec.Decode(&c.resp); err != nil {
		return err
	}

	c.mutex.Lock()
	r.ServiceMethod = c.pending[c.resp.Id]
	delete(c.pending, c.resp.Id)
	c.mutex.Unlock()

	r.Error = ""
	r.Seq = 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"
		}
		r.Error = x
	}
	return nil
}
Esempio n. 2
0
// ReadResponseHeader - implement rpc.ClientCodec interface.
func (c *pbClientCodec) ReadResponseHeader(r *rpc.Response) error {
	data, err := ReadNetString(c.rwc)
	if err != nil {
		return err
	}
	rtmp := new(Response)
	err = proto.Unmarshal(data, rtmp)
	if err != nil {
		return err
	}
	r.ServiceMethod = *rtmp.ServiceMethod
	r.Seq = *rtmp.Seq
	r.Error = *rtmp.Error
	return nil
}