protorw

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 3 Imported by: 0

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

func ReadMessage(r io.Reader, m Message) error

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

func WriteMessage

func WriteMessage(w io.Writer, m Message) error

WriteMessage marshals a given protobuf message and writes it into the given writer. The payload will be size prefixed by eight bytes to enable size delimited reading of the message.

Types

type Message

type Message proto.Message

Message is taken from the protobuf libary

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

New returns an implementation of the ProtoReadWriter interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL