Documentation
¶
Overview ¶
Package buffstreams provides a simple interface for creating and storing sockets that have a pre-defined set of behaviors, making them simple to use for consuming streaming protocol buffer messages over TCP
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatAddress ¶
FormatAddress is to cover the event that you want/need a programmtically correct way to format an address/port to use with StartListening or WriteTo
Types ¶
type BuffManager ¶
BuffManager represents the object used to govern interactions between tcp endpoints. You can use it to read from and write to streaming or non-streaming TCP connections and have it handle packaging data with a header describing the size of the data payload. This is to make it easy to work with wire formats like ProtocolBuffers, which require a custom-delimeter situation to be sent in a streaming fashion.
func New ¶
func New(cfg BuffManagerConfig) *BuffManager
New creates a new *BuffManager based on the provided BuffManagerConfig
func (*BuffManager) StartListening ¶
func (bm *BuffManager) StartListening(port string, cb ListenCallback) error
StartListening is an asyncrhonous, non-blocking method. It begins listening on the given port, and fire off a goroutine for every client connection it receives. That goroutine will read the fixed header, then the message payload, and then invoke the povided ListenCallbacl. In the event of an transport error, it will disconnect the client. It is the clients responsibility to re-connect if needed.
func (*BuffManager) WriteTo ¶
WriteTo allows you to dial to a remote or local TCP endpoint, and send either 1 or a stream of bytes as messages. Each array of bytes you pass in will be pre-pended with it's size within the size of the pre-defined maximum message size. If the connection isn't open yet, WriteTo will open it, and cache it. If for anyreason the connection breaks, it will be disposed and upon the next write, a new one will dial out.
type BuffManagerConfig ¶
type BuffManagerConfig struct { // Controls how large the largest Message may be. The server will reject any messages whose clients // header size does not match this configuration MaxMessageSize int // Controls the ability to enable logging errors occuring in the library EnableLogging bool }
BuffManagerConfig represents a set of options that the person building systems ontop of
type ListenCallback ¶
ListenCallback is a function type that calling code will need to implement in order to receive arrays of bytes from the socket. Each slice of bytes will be stripped of the size header, meaning you can directly serialize the raw slice. You would then perform your custom logic for interpretting the message, before returning. You can optionally return an error, which in turn will be logged if EnableLogging is set to true.