netstring

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 5 Imported by: 3

README

netstring

D. J. Bernstein's netstrings for Go

go get github.com/julianmorrison/netstring

Read and write netstrings.

Documentation

Overview

D. J. Bernstein's netstrings for Go.

Index

Constants

This section is empty.

Variables

View Source
var Garbled = errors.New("The netstring was not correctly formatted and could not be read")
View Source
var Incomplete = errors.New("The netstring is incomplete")

Functions

func MarshalFrom

func MarshalFrom(buf []byte) []byte

Convenience function, create a netstring representation of a []byte

Types

type Netstring

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

func ForReading

func ForReading() *Netstring

Construct an empty netstring, for input. n.IsComplete() will return false.

func From

func From(buf []byte) *Netstring

Construct a netstring wrapping a byte slice, for output. n.IsComplete() will return true.

func (*Netstring) Bytes

func (n *Netstring) Bytes() ([]byte, error)

Returns the bytes in the netstring if it is complete, otherwise returns Incomplete as an error.

func (*Netstring) IsComplete

func (n *Netstring) IsComplete() bool

Returns true if the number of bytes advertized in the netstring's length have been read into its buffer. Operations that require the netstring's contents will not be available until it is complete.

func (*Netstring) Length

func (n *Netstring) Length() int

Returns the advertized length of the netstring. If n.IsComplete() then this is the length of the data in the buffer, too. If this value is negative, in means that no length has been read yet.

func (*Netstring) Marshal

func (n *Netstring) Marshal() ([]byte, error)

Formats a netstring representation of the data in the buffer.

func (*Netstring) ReadFrom

func (n *Netstring) ReadFrom(input io.Reader) error

Read a netstring from input. Returns any errors from input except io.EOF. Returns Garbled if the input was not a valid netstring. Returns Incomplete if the input was shorter than a full netstring. To resume reading where you left off, call Readfrom(input) again. Calling Readfrom(input) on a complete netstring does nothing.

Jump to

Keyboard shortcuts

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