Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadProto ¶
func ReadProto(r ProtoReader, pb interface{}) error
ReadProto reads a uvarint size and then a protobuf from r. If the size read is zero, nothing more is read.
func WriteProto ¶
WriteProto writes a uvarint size and then a protobuf to w. If the data takes no space (like rpc.InvalidRequest), only a zero size is written.
Types ¶
type ClientCodec ¶
type ClientCodec struct {
// contains filtered or unexported fields
}
ClientCodec implements the rpc.ClientCodec interface for generic protobufs. The same implementation works for all protobufs because it defers the encoding of a protocol buffer to the proto package and it uses a set header that is the same regardless of the protobuf being used for the RPC.
func NewClientCodec ¶
func NewClientCodec(conn net.Conn) *ClientCodec
NewClientCodec returns a ClientCodec for communicating with the ServerCodec on the other end of the conn.
func (*ClientCodec) Close ¶
func (c *ClientCodec) Close() error
Close closes the underlying connection.
func (*ClientCodec) ReadResponseBody ¶
func (c *ClientCodec) ReadResponseBody(pb interface{}) error
ReadResponseBody reads a uvarint from the connection and decodes that many subsequent bytes into the given protobuf (which should be a pointer to a struct that is generated by the proto package). If the uvarint size read is zero, nothing is done (this indicates an error condition, which was encapsulated in the header)
func (*ClientCodec) ReadResponseHeader ¶
func (c *ClientCodec) ReadResponseHeader(resp *rpc.Response) error
ReadResponseHeader reads the header protobuf (which is prefixed by a uvarint indicating its size) from the connection, decodes it, and stores the fields in the given request.
func (*ClientCodec) WriteRequest ¶
func (c *ClientCodec) WriteRequest(req *rpc.Request, pb interface{}) error
WriteRequest writes the appropriate header protobuf and the given protobuf to the connection (each prefixed with a uvarint indicating its size).
type ProtoReader ¶
type ProtoReader interface { io.Reader io.ByteReader }
type ServerCodec ¶
type ServerCodec struct {
// contains filtered or unexported fields
}
ServerCodec implements the rpc.ServerCodec interface for generic protobufs. The same implementation works for all protobufs because it defers the decoding of a protocol buffer to the proto package and it uses a set header that is the same regardless of the protobuf being used for the RPC.
func NewServerCodec ¶
func NewServerCodec(conn net.Conn) *ServerCodec
NewServerCodec returns a ServerCodec that communicates with the ClientCodec on the other end of the given conn.
func (*ServerCodec) Close ¶
func (s *ServerCodec) Close() error
Close closes the underlying conneciton.
func (*ServerCodec) ReadRequestBody ¶
func (s *ServerCodec) ReadRequestBody(pb interface{}) error
ReadRequestBody reads a uvarint from the connection and decodes that many subsequent bytes into the given protobuf (which should be a pointer to a struct that is generated by the proto package).
func (*ServerCodec) ReadRequestHeader ¶
func (s *ServerCodec) ReadRequestHeader(req *rpc.Request) error
ReadRequestHeader reads the header protobuf (which is prefixed by a uvarint indicating its size) from the connection, decodes it, and stores the fields in the given request.
func (*ServerCodec) WriteResponse ¶
func (s *ServerCodec) WriteResponse(resp *rpc.Response, pb interface{}) error
WriteResponse writes the appropriate header protobuf and the given protobuf to the connection (each prefixed with a uvarint indicating its size). If the response was invalid, the size of the body of the resp is reported as having size zero and is not sent.