xdr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 3 Imported by: 0

README

xdr

Coverage Status API Documentation MIT License

This is an XDR marshalling/unmarshalling library. It uses code generation and not reflection.

Documentation

Overview

Package xdr implements an XDR (RFC 4506) marshaller/unmarshaller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElementSizeExceeded

func ElementSizeExceeded(field string, size, limit int) error

ElementSizeExceeded returns an error describing the violated size constraint. This function is used by the generated marshalling code.

func Padding

func Padding(l int) int

Padding returns the number of bytes that should be added to an item of length l bytes to conform to the XDR padding standard. This function is used by the generated marshalling code.

func SizeOfSlice

func SizeOfSlice(ss interface{}) int

SizeOfSlice returns the XDR encoded size of the given []T. Supported types for T are string, []byte and types implementing Sizer. SizeOfSlice panics if the parameter is not a slice or if T is not one of the supported types. This function is used by the generated marshalling code.

Types

type Marshaller

type Marshaller struct {
	Data  []byte
	Error error
	// contains filtered or unexported fields
}

Marshaller is a thin wrapper around a byte buffer. The buffer must be of sufficient size to hold the complete marshalled object, or an io.ErrShortBuffer error will result. The Marshal... methods don't individually return an error - the intention is that multiple fields are marshalled in rapid succession, followed by a check of the Error field on the Marshaller.

func (*Marshaller) MarshalBool

func (m *Marshaller) MarshalBool(v bool)

MarshalBool appends the bool to the buffer, as an uint32.

func (*Marshaller) MarshalBytes

func (m *Marshaller) MarshalBytes(bs []byte)

MarshalBytes appends the bytes to the buffer, with a size prefix and correct padding.

func (*Marshaller) MarshalRaw

func (m *Marshaller) MarshalRaw(bs []byte)

MarshalRaw copies the raw bytes to the buffer, without a size prefix or padding. This is suitable for appending data already in XDR format from another source.

func (*Marshaller) MarshalString

func (m *Marshaller) MarshalString(s string)

MarshalString appends the string to the buffer, with a size prefix and correct padding.

func (*Marshaller) MarshalUint16

func (m *Marshaller) MarshalUint16(v uint16)

MarshalUint16 appends the uint16 to the buffer, as an uint32.

func (*Marshaller) MarshalUint32

func (m *Marshaller) MarshalUint32(v uint32)

MarshalUint32 appends the uint32 to the buffer.

func (*Marshaller) MarshalUint64

func (m *Marshaller) MarshalUint64(v uint64)

MarshalUint64 appends the uint64 to the buffer.

func (*Marshaller) MarshalUint8

func (m *Marshaller) MarshalUint8(v uint8)

MarshalUint8 appends the uint8 to the buffer, as an uint32.

type Sizer

type Sizer interface {
	XDRSize() int
}

Sizer is a value that can return its XDR serialized size.

type Unmarshaller

type Unmarshaller struct {
	Error error
	Data  []byte
}

Unmarshaller is a thin wrapper around a byte buffer. The Unmarshal... methods don't individually return an error - the intention is that multiple fields are unmarshalled in rapid succession, followed by a check of the Error field on the Unmarshaller.

func (*Unmarshaller) UnmarshalBool

func (u *Unmarshaller) UnmarshalBool() bool

UnmarshalBool returns a bool from the buffer.

func (*Unmarshaller) UnmarshalBytes

func (u *Unmarshaller) UnmarshalBytes() []byte

UnmarshalBytes returns a byte slice from the buffer.

func (*Unmarshaller) UnmarshalBytesMax

func (u *Unmarshaller) UnmarshalBytesMax(max int) []byte

UnmarshalBytesMax returns a byte slice up to a max length from the buffer.

func (*Unmarshaller) UnmarshalRaw

func (u *Unmarshaller) UnmarshalRaw(l int) []byte

UnmarshalRaw returns a byte slice of length l from the buffer, without a size prefix or padding. This is suitable for retrieving data already in XDR format.

func (*Unmarshaller) UnmarshalString

func (u *Unmarshaller) UnmarshalString() string

UnmarshalString returns a string from the buffer.

func (*Unmarshaller) UnmarshalStringMax

func (u *Unmarshaller) UnmarshalStringMax(max int) string

UnmarshalStringMax returns a string up to a max length from the buffer.

func (*Unmarshaller) UnmarshalUint16

func (u *Unmarshaller) UnmarshalUint16() uint16

UnmarshalUint16 returns a uint16 from the buffer.

func (*Unmarshaller) UnmarshalUint32

func (u *Unmarshaller) UnmarshalUint32() uint32

UnmarshalUint32 returns a uint32 from the buffer.

func (*Unmarshaller) UnmarshalUint64

func (u *Unmarshaller) UnmarshalUint64() uint64

UnmarshalUint64 returns a uint64 from the buffer.

func (*Unmarshaller) UnmarshalUint8

func (u *Unmarshaller) UnmarshalUint8() uint8

UnmarshalUint8 returns a uint8 from the buffer.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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