stream

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package json provides a client that can be used on a *uds.Client or *uds.Conn to send streaming JSON values. This package uses chunk underneath and therefore expects the other side to understand its data format.

This is for decoding a single message type that can be made up of sub-messages. If you wish to decode JSON dicts inside a dict stream or arbitrary JSON messages, simply wrap *uds.Client or *uds.Conn with json.Decoder instead of using this package.

This handles streams beautifully if you define a simple master message containing sub-messages. Aka:

type Message struct {
	Type int8
	SubMessage1 SubMessage1
	SubMessage2 SubMessage2
}
...

Where Type will indicate what message field is set.  Streaming this via client.Write() calls allows
adding new types of messages any time and receivers detecting types a client may not support.
0 should indicate that the Message is the zero value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides a wrapper around an *uds.Client or *uds.Server that can send and receive JSON messages.

func New

func New(rwc io.ReadWriteCloser, options ...Option) (*Client, error)

New is the constructor for Client. rwc must be a *uds.Client or *uds.Conn.

func (*Client) Read

func (c *Client) Read(v interface{}) error

Read reads the next JSON message into value v.

func (*Client) Write

func (c *Client) Write(v interface{}) error

Write writes v as a JSON value into the socket.

type Option

type Option func(c *Client)

Option is an optional argument to New.

func MaxSize

func MaxSize(size int64) Option

MaxSize is the maximum size a read message is allowed to be. If a message is larger than this, Next() will fail and the underlying connection will be closed.

func SharedPool

func SharedPool(pool *chunk.Pool) Option

SharedPool allows the use of a shared pool of buffers between Client instead of a pool per client. This is useful when clients are short lived and have similar message sizes. Client will panic if the pool does not return a *[]byte object.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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