payload

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: Apache-2.0, BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const IdLength = 64

IdLength is the length of a data payload id.

View Source
const MaxDataPayloadSize = 64 * 1024

MaxDataPayloadSize defines the maximum size of a data payload.

View Source
const (
	// ObjectName defines the name of the data object.
	ObjectName = "data"
)

Variables

View Source
var DataType = Type(0)

DataType is the message type of a data payload.

View Source
var (
	// ErrMaximumPayloadSizeExceeded is returned if the payload exceeds the maximum size.
	ErrMaximumPayloadSizeExceeded = errors.New("maximum payload size exceeded")
)

Functions

func Name

func Name(payloadType Type) string

Name returns the name of a given payload type.

func RegisterType

func RegisterType(payloadType Type, payloadName string, unmarshaler Unmarshaler)

RegisterType registers a payload type with the given unmarshaler.

func SetGenericUnmarshalerFactory

func SetGenericUnmarshalerFactory(unmarshalerFactory func(payloadType Type) Unmarshaler)

SetGenericUnmarshalerFactory sets the generic unmarshaler.

Types

type Data

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

Data represents a payload which just contains a blob of data.

func DataFromBytes

func DataFromBytes(bytes []byte, optionalTargetObject ...*Data) (result *Data, err error, consumedBytes int)

DataFromBytes creates a new data payload from the given bytes.

func NewData

func NewData(data []byte) *Data

NewData creates new data payload.

func ParseData

func ParseData(marshalUtil *marshalutil.MarshalUtil, optionalTargetObject ...*Data) (result *Data, err error)

ParseData parses a new data payload out of the given marshal util.

func (*Data) Bytes

func (dataPayload *Data) Bytes() []byte

Bytes marshals the data payload into a sequence of bytes.

func (*Data) Data

func (dataPayload *Data) Data() []byte

Data returns the data of the data payload.

func (*Data) String

func (dataPayload *Data) String() string

func (*Data) Type

func (dataPayload *Data) Type() Type

func (*Data) Unmarshal

func (dataPayload *Data) Unmarshal(data []byte) (err error)

type Definition

type Definition struct {
	Name string
	Unmarshaler
}

Definition defines the properties of a payload type.

type Id

type Id [IdLength]byte

ID represents the id of a data payload.

func (Id) Bytes

func (id Id) Bytes() []byte

Bytes returns the id as a byte slice backed by the original array, therefore it should not be modified.

func (Id) String

func (id Id) String() string

type Payload

type Payload interface {
	// Type returns the type of the payload.
	Type() Type
	// Bytes returns the payload bytes.
	Bytes() []byte
	// Unmarshal unmarshals the payload from the given bytes.
	Unmarshal(bytes []byte) error
	// String returns a human-friendly representation of the payload.
	String() string
}

Payload represents some kind of payload of data which only gains meaning by having corresponding node logic processing payloads of a given type.

func FromBytes

func FromBytes(bytes []byte) (result Payload, consumedBytes int, err error)

FromBytes unmarshals bytes into a payload.

func Parse

func Parse(marshalUtil *marshalutil.MarshalUtil) (Payload, error)

Parse parses a payload by using the given marshal util.

type Type

type Type = uint32

Type represents the type id of a payload.

type Unmarshaler

type Unmarshaler func(data []byte) (Payload, error)

Unmarshaler takes some data and unmarshals it into a payload.

func GenericPayloadUnmarshalerFactory

func GenericPayloadUnmarshalerFactory(payloadType Type) Unmarshaler

GenericPayloadUnmarshalerFactory is an unmarshaler for the generic data payload type.

func GetUnmarshaler

func GetUnmarshaler(payloadType Type) Unmarshaler

GetUnmarshaler returns the unmarshaler for the given type if known or the generic unmarshaler if the given payload type has no associated unmarshaler.

Jump to

Keyboard shortcuts

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