netstring

package
Version: v0.0.0-...-c8528d7 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package netstring provides the functions to read and write the netstring

Package netstring contains encoding and decoding functions in netstring format

Index

Constants

View Source
const (

	// CodeSubCommand is a special command used to define that the payload contains multiple netstrings
	CodeSubCommand = '0'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Netstring

type Netstring struct {
	Cmd        int
	Serialized []byte // the entire netstring array. e.g. "100:1 xxx...yyy,"
	Payload    []byte // the content section of a netstring. e.g. "xxx...yyy"
}

Netstring is a netstring packed, which consists of a command plus a payload

func NewNetstring

func NewNetstring(_reader io.Reader) (*Netstring, error)

NewNetstring creates a Netstring from the reader, reading exactly as many bytes as necessary

func NewNetstringEmbedded

func NewNetstringEmbedded(_netstrings []*Netstring) *Netstring

NewNetstringEmbedded embedds a set of Netstrings into a netstring

func NewNetstringFrom

func NewNetstringFrom(_cmd int, _payload []byte) *Netstring

NewNetstringFrom creates a Netstring from command and Payload

func SubNetstrings

func SubNetstrings(_ns *Netstring) ([]*Netstring, error)

SubNetstrings parses the embedded Netstrings

func (*Netstring) IsComposite

func (ns *Netstring) IsComposite() bool

IsComposite returns if the netstring is compisite, embedding multiple netstrings in it

type Reader

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

Reader decodes netstrings from a buffer

func NewNetstringReader

func NewNetstringReader(_reader io.Reader) *Reader

NewNetstringReader creates a Reader, that maintains the state for embedded Netstrings

func (*Reader) ReadNext

func (reader *Reader) ReadNext() (ns *Netstring, err error)

ReadNext returns the next Netstring from the stream. Note: in case of embedded netstrings, the Reader will buffer some Netstrings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL