Esempio n. 1
0
func (s *codec) writeHeaderData(header *rpc4.Header, data []byte) (err error) {
	if len(data) > 0 {
		header.PayloadPresent = proto.Bool(true)
	}

	if err = writeProto(s.w, header); err == nil && header.GetPayloadPresent() {
		err = writeData(s.w, data)
	}
	return
}
Esempio n. 2
0
func (s *codec) WriteResponse(resp *rpc.Response, pb interface{}) error {
	var header rpc4.Header
	header.Method, header.Sequence, header.MessageType = &resp.ServiceMethod, &resp.Seq, rpc4.Header_RESPONSE.Enum()

	var data []byte

	if resp.Error == "" {
		var err error
		if data, err = proto.Marshal(pb.(proto.Message)); err != nil {
			resp.Error = err.Error()
		}
	}

	if resp.Error != "" {
		header.MessageType = rpc4.Header_ERROR.Enum()
		data = []byte(resp.Error)
	}

	return s.writeHeaderData(&header, data)
}
Esempio n. 3
0
func (s *codec) ReadResponseHeader(resp *rpc.Response) error {
	if s.Shutdown {
		return rpc.ErrShutdown
	}

	var header rpc4.Header
	if err := readProto(s.r, &header); err != nil {
		return err
	}
	if header.GetMethod() == "" {
		return fmt.Errorf("header missing method: %s", header)
	}

	resp.ServiceMethod = header.GetMethod()
	resp.Seq = header.GetSequence()

	s.responsePayload = header.GetPayloadPresent()
	return nil
}