Documentation ¶
Overview ¶
package protorw solves the size delimination problem for protobuf messages. As the protobuf documentation (https://protobuf.dev/programming-guides/techniques/#streaming) states, "it is up to you to keep track of where one message ends and the next begins". The easiest solution for doing so, is to prefix every message with it's length/size. ProtoReadWriter implements this behavior
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadMessage ¶
ReadMessage reads a protobuf message from a given connection/reader. It assumes that the first eight byte are used for specifying the message's length
Types ¶
type ProtoReadWriter ¶
type ProtoReadWriter interface { io.ReadWriter // WriteMessage writes a message into the underlying WriteMessage(Message) error ReadMessage(Message) error }
ProtoReadWriter describes the interface to be fulfilled for a reader-writer with the purpose to be used for protobuf messages.
protoReadWriter implements a size delimiting mechanism on top of an reader-writer. The size is limtited by the limit of int64 which means that it needs 8 bytes to be encoded for transmission. It uses big endian to encode the size into bytes
For reading from that connection that means it will assume a 8-byte size prefixed message.
For writing this means that every message will get size prefixed by 8 bytes before writing the message itself.
func New ¶
func New(rw io.ReadWriter) ProtoReadWriter
New returns an implementation of the ProtoReadWriter interface