Example #1
0
func (c *serverCodec) WriteResponse(r *rpc.Response, body interface{}) error {
	var param proto.Message
	if body != nil {
		var ok bool
		if param, ok = body.(proto.Message); !ok {
			return fmt.Errorf("%T does not implement proto.Message", body)
		}
	}

	var rsp protorpcpb.Response
	rsp.Method = proto.String(r.ServiceMethod)
	rsp.Seq = proto.Uint64(r.Seq)
	rsp.Err = proto.String(r.Error)
	return writeMessage(c.rwc, &rsp, param)
}
Example #2
0
func (c *clientCodec) ReadResponseHeader(r *rpc.Response) error {
	var rsp protorpcpb.Response
	if err := readFrame(c.rwc, &rsp); err != nil {
		return err
	}
	r.ServiceMethod = rsp.GetMethod()
	r.Seq = rsp.GetSeq()
	r.Error = rsp.GetErr()
	return nil
}