Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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(obj 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, obj 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(obj 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, obj 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.