payload

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: Apache-2.0, BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

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

	// MaxMessageSize defines the maximum size of a message.
	MaxMessageSize = 64 * 1024

	// MaxPayloadSize defines the maximum size of a payload.
	// trunkID + branchID + issuerPublicKey + issuingTime + sequenceNumber + nonce + signature
	MaxPayloadSize = MaxMessageSize - 64 - 64 - 32 - 8 - 8 - 8 - 64
)
View Source
const IDLength = 64

IDLength is the length of a data payload id.

Variables

View Source
var DataType = Type(0)

DataType is the message type of a data payload.

View Source
var (
	// ErrMaxPayloadSizeExceeded is returned if the maximum payload size is exceeded.
	ErrMaxPayloadSizeExceeded = fmt.Errorf("maximum payload size of %d bytes exceeded", MaxPayloadSize)
)

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, consumedBytes int, err error)

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

Type returns the payload type.

func (*Data) Unmarshal

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

Unmarshal unmarshalls the byte array to a data payload.

type Definition

type Definition struct {
	Name string
	Unmarshaler
}

Definition defines the properties of a payload type.

type ID added in v0.2.3

type ID [IDLength]byte

ID represents the id of a data payload.

func (ID) Bytes added in v0.2.3

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 added in v0.2.3

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