Documentation ¶
Index ¶
Constants ¶
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 )
const IDLength = 64
IDLength is the length of a data payload id.
Variables ¶
var DataType = Type(0)
DataType is the message type of a data payload.
var ( // ErrMaxPayloadSizeExceeded is returned if the maximum payload size is exceeded. ErrMaxPayloadSizeExceeded = fmt.Errorf("maximum payload size of %d bytes exceeded", MaxPayloadSize) )
Functions ¶
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 ParseData ¶
func ParseData(marshalUtil *marshalutil.MarshalUtil, optionalTargetObject ...*Data) (result *Data, err error)
ParseData parses a new data payload out of the given marshal util.
type Definition ¶
type Definition struct { Name string Unmarshaler }
Definition defines the properties of a payload type.
type ID ¶ added in v0.2.3
ID represents the id of a data payload.
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 Parse ¶
func Parse(marshalUtil *marshalutil.MarshalUtil) (Payload, error)
Parse parses a payload by using the given marshal util.
type Unmarshaler ¶
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.