encoding

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: MIT, MIT Imports: 9 Imported by: 0

Documentation

Overview

Copyright (C) 2017 Kale Blankenship Portions Copyright (c) Microsoft Corporation

Copyright (C) 2017 Kale Blankenship Portions Copyright (c) Microsoft Corporation

Copyright (C) 2017 Kale Blankenship Portions Copyright (c) Microsoft Corporation

Index

Constants

Variables

This section is empty.

Functions

func Marshal

func Marshal(wr *buffer.Buffer, i interface{}) error

func MarshalComposite

func MarshalComposite(wr *buffer.Buffer, code AMQPType, fields []MarshalField) error

marshalComposite is a helper for us in a composite's marshal() function.

The returned bytes include the composite header and fields. Fields with omit set to true will be encoded as null or omitted altogether if there are no non-null fields after them.

func PeekMessageType

func PeekMessageType(buf []byte) (uint8, uint8, error)

peekMessageType reads the message type without modifying any data.

func ReadAny

func ReadAny(r *buffer.Buffer) (interface{}, error)

func ReadString

func ReadString(r *buffer.Buffer) (string, error)

func ReadUbyte

func ReadUbyte(r *buffer.Buffer) (uint8, error)

func Unmarshal

func Unmarshal(r *buffer.Buffer, i interface{}) error

unmarshal decodes AMQP encoded data into i.

The decoding method is based on the type of i.

If i implements unmarshaler, i.Unmarshal() will be called.

Pointers to primitive types will be decoded via the appropriate read[Type] function.

If i is a pointer to a pointer (**Type), it will be dereferenced and a new instance of (*Type) is allocated via reflection.

Common map types (map[string]string, map[Symbol]interface{}, and map[interface{}]interface{}), will be decoded via conversion to the mapStringAny, mapSymbolAny, and mapAnyAny types.

func UnmarshalComposite

func UnmarshalComposite(r *buffer.Buffer, type_ AMQPType, fields ...UnmarshalField) error

unmarshalComposite is a helper for use in a composite's unmarshal() function.

The composite from r will be unmarshaled into zero or more fields. An error will be returned if typ does not match the decoded type.

func ValidateExpiryPolicy

func ValidateExpiryPolicy(e ExpiryPolicy) error

func WriteBinary

func WriteBinary(wr *buffer.Buffer, bin []byte) error

func WriteDescriptor

func WriteDescriptor(wr *buffer.Buffer, code AMQPType)

Types

type AMQPType

type AMQPType uint8
const (
	TypeCodeNull AMQPType = 0x40

	// Bool
	TypeCodeBool      AMQPType = 0x56 // boolean with the octet 0x00 being false and octet 0x01 being true
	TypeCodeBoolTrue  AMQPType = 0x41
	TypeCodeBoolFalse AMQPType = 0x42

	// Unsigned
	TypeCodeUbyte      AMQPType = 0x50 // 8-bit unsigned integer (1)
	TypeCodeUshort     AMQPType = 0x60 // 16-bit unsigned integer in network byte order (2)
	TypeCodeUint       AMQPType = 0x70 // 32-bit unsigned integer in network byte order (4)
	TypeCodeSmallUint  AMQPType = 0x52 // unsigned integer value in the range 0 to 255 inclusive (1)
	TypeCodeUint0      AMQPType = 0x43 // the uint value 0 (0)
	TypeCodeUlong      AMQPType = 0x80 // 64-bit unsigned integer in network byte order (8)
	TypeCodeSmallUlong AMQPType = 0x53 // unsigned long value in the range 0 to 255 inclusive (1)
	TypeCodeUlong0     AMQPType = 0x44 // the ulong value 0 (0)

	// Signed
	TypeCodeByte      AMQPType = 0x51 // 8-bit two's-complement integer (1)
	TypeCodeShort     AMQPType = 0x61 // 16-bit two's-complement integer in network byte order (2)
	TypeCodeInt       AMQPType = 0x71 // 32-bit two's-complement integer in network byte order (4)
	TypeCodeSmallint  AMQPType = 0x54 // 8-bit two's-complement integer (1)
	TypeCodeLong      AMQPType = 0x81 // 64-bit two's-complement integer in network byte order (8)
	TypeCodeSmalllong AMQPType = 0x55 // 8-bit two's-complement integer

	// Decimal
	TypeCodeFloat      AMQPType = 0x72 // IEEE 754-2008 binary32 (4)
	TypeCodeDouble     AMQPType = 0x82 // IEEE 754-2008 binary64 (8)
	TypeCodeDecimal32  AMQPType = 0x74 // IEEE 754-2008 decimal32 using the Binary Integer Decimal encoding (4)
	TypeCodeDecimal64  AMQPType = 0x84 // IEEE 754-2008 decimal64 using the Binary Integer Decimal encoding (8)
	TypeCodeDecimal128 AMQPType = 0x94 // IEEE 754-2008 decimal128 using the Binary Integer Decimal encoding (16)

	// Other
	TypeCodeChar      AMQPType = 0x73 // a UTF-32BE encoded Unicode character (4)
	TypeCodeTimestamp AMQPType = 0x83 // 64-bit two's-complement integer representing milliseconds since the unix epoch
	TypeCodeUUID      AMQPType = 0x98 // UUID as defined in section 4.1.2 of RFC-4122

	// Variable Length
	TypeCodeVbin8  AMQPType = 0xa0 // up to 2^8 - 1 octets of binary data (1 + variable)
	TypeCodeVbin32 AMQPType = 0xb0 // up to 2^32 - 1 octets of binary data (4 + variable)
	TypeCodeStr8   AMQPType = 0xa1 // up to 2^8 - 1 octets worth of UTF-8 Unicode (with no byte order mark) (1 + variable)
	TypeCodeStr32  AMQPType = 0xb1 // up to 2^32 - 1 octets worth of UTF-8 Unicode (with no byte order mark) (4 +variable)
	TypeCodeSym8   AMQPType = 0xa3 // up to 2^8 - 1 seven bit ASCII characters representing a symbolic value (1 + variable)
	TypeCodeSym32  AMQPType = 0xb3 // up to 2^32 - 1 seven bit ASCII characters representing a symbolic value (4 + variable)

	// Compound
	TypeCodeList0   AMQPType = 0x45 // the empty list (i.e. the list with no elements) (0)
	TypeCodeList8   AMQPType = 0xc0 // up to 2^8 - 1 list elements with total size less than 2^8 octets (1 + compound)
	TypeCodeList32  AMQPType = 0xd0 // up to 2^32 - 1 list elements with total size less than 2^32 octets (4 + compound)
	TypeCodeMap8    AMQPType = 0xc1 // up to 2^8 - 1 octets of encoded map data (1 + compound)
	TypeCodeMap32   AMQPType = 0xd1 // up to 2^32 - 1 octets of encoded map data (4 + compound)
	TypeCodeArray8  AMQPType = 0xe0 // up to 2^8 - 1 array elements with total size less than 2^8 octets (1 + array)
	TypeCodeArray32 AMQPType = 0xf0 // up to 2^32 - 1 array elements with total size less than 2^32 octets (4 + array)

	// Composites
	TypeCodeOpen        AMQPType = 0x10
	TypeCodeBegin       AMQPType = 0x11
	TypeCodeAttach      AMQPType = 0x12
	TypeCodeFlow        AMQPType = 0x13
	TypeCodeTransfer    AMQPType = 0x14
	TypeCodeDisposition AMQPType = 0x15
	TypeCodeDetach      AMQPType = 0x16
	TypeCodeEnd         AMQPType = 0x17
	TypeCodeClose       AMQPType = 0x18

	TypeCodeSource AMQPType = 0x28
	TypeCodeTarget AMQPType = 0x29
	TypeCodeError  AMQPType = 0x1d

	TypeCodeMessageHeader         AMQPType = 0x70
	TypeCodeDeliveryAnnotations   AMQPType = 0x71
	TypeCodeMessageAnnotations    AMQPType = 0x72
	TypeCodeMessageProperties     AMQPType = 0x73
	TypeCodeApplicationProperties AMQPType = 0x74
	TypeCodeApplicationData       AMQPType = 0x75
	TypeCodeAMQPSequence          AMQPType = 0x76
	TypeCodeAMQPValue             AMQPType = 0x77
	TypeCodeFooter                AMQPType = 0x78

	TypeCodeStateReceived AMQPType = 0x23
	TypeCodeStateAccepted AMQPType = 0x24
	TypeCodeStateRejected AMQPType = 0x25
	TypeCodeStateReleased AMQPType = 0x26
	TypeCodeStateModified AMQPType = 0x27

	TypeCodeSASLMechanism AMQPType = 0x40
	TypeCodeSASLInit      AMQPType = 0x41
	TypeCodeSASLChallenge AMQPType = 0x42
	TypeCodeSASLResponse  AMQPType = 0x43
	TypeCodeSASLOutcome   AMQPType = 0x44

	TypeCodeDeleteOnClose             AMQPType = 0x2b
	TypeCodeDeleteOnNoLinks           AMQPType = 0x2c
	TypeCodeDeleteOnNoMessages        AMQPType = 0x2d
	TypeCodeDeleteOnNoLinksOrMessages AMQPType = 0x2e
)

Type codes

type Annotations

type Annotations map[interface{}]interface{}

Annotations keys must be of type string, int, or int64.

String keys are encoded as AMQP Symbols.

func (Annotations) Marshal

func (a Annotations) Marshal(wr *buffer.Buffer) error

func (*Annotations) Unmarshal

func (a *Annotations) Unmarshal(r *buffer.Buffer) error

type ArrayUByte

type ArrayUByte []uint8

ArrayUByte allows encoding []uint8/[]byte as an array rather than binary data.

func (ArrayUByte) Marshal

func (a ArrayUByte) Marshal(wr *buffer.Buffer) error

func (*ArrayUByte) Unmarshal

func (a *ArrayUByte) Unmarshal(r *buffer.Buffer) error

type DeliveryState

type DeliveryState interface {
	// contains filtered or unexported methods
}

DeliveryState encapsulates the various concrete delivery states. http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#section-delivery-state TODO: http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transactions-v1.0-os.html#type-declared

type DescribedType

type DescribedType struct {
	Descriptor interface{}
	Value      interface{}
}

func (DescribedType) Marshal

func (t DescribedType) Marshal(wr *buffer.Buffer) error

func (DescribedType) String

func (t DescribedType) String() string

func (*DescribedType) Unmarshal

func (t *DescribedType) Unmarshal(r *buffer.Buffer) error

type Durability

type Durability uint32

Durability specifies the durability of a link.

const (
	// No terminus state is retained durably.
	DurabilityNone Durability = 0

	// Only the existence and configuration of the terminus is
	// retained durably.
	DurabilityConfiguration Durability = 1

	// In addition to the existence and configuration of the
	// terminus, the unsettled state for durable messages is
	// retained durably.
	DurabilityUnsettledState Durability = 2
)

Durability Policies

func (Durability) Marshal

func (d Durability) Marshal(wr *buffer.Buffer) error

func (*Durability) String

func (d *Durability) String() string

func (*Durability) Unmarshal

func (d *Durability) Unmarshal(r *buffer.Buffer) error

type Error

type Error struct {
	// A symbolic value indicating the error condition.
	Condition ErrorCondition

	// descriptive text about the error condition
	//
	// This text supplies any supplementary details not indicated by the condition field.
	// This text can be logged as an aid to resolving issues.
	Description string

	// map carrying information about the error condition
	Info map[string]interface{}
}

Error is an AMQP error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Marshal

func (e *Error) Marshal(wr *buffer.Buffer) error

func (*Error) String

func (e *Error) String() string

func (*Error) Unmarshal

func (e *Error) Unmarshal(r *buffer.Buffer) error

type ErrorCondition

type ErrorCondition string

ErrorCondition is one of the error conditions defined in the AMQP spec.

func (ErrorCondition) Marshal

func (ec ErrorCondition) Marshal(wr *buffer.Buffer) error

func (*ErrorCondition) Unmarshal

func (ec *ErrorCondition) Unmarshal(r *buffer.Buffer) error

type ExpiryPolicy

type ExpiryPolicy Symbol

ExpiryPolicy specifies when the expiry timer of a terminus starts counting down from the timeout value.

If the link is subsequently re-attached before the terminus is expired, then the count down is aborted. If the conditions for the terminus-expiry-policy are subsequently re-met, the expiry timer restarts from its originally configured timeout value.

const (
	// The expiry timer starts when terminus is detached.
	ExpiryLinkDetach ExpiryPolicy = "link-detach"

	// The expiry timer starts when the most recently
	// associated session is ended.
	ExpirySessionEnd ExpiryPolicy = "session-end"

	// The expiry timer starts when most recently associated
	// connection is closed.
	ExpiryConnectionClose ExpiryPolicy = "connection-close"

	// The terminus never expires.
	ExpiryNever ExpiryPolicy = "never"
)

Expiry Policies

func (ExpiryPolicy) Marshal

func (e ExpiryPolicy) Marshal(wr *buffer.Buffer) error

func (*ExpiryPolicy) String

func (e *ExpiryPolicy) String() string

func (*ExpiryPolicy) Unmarshal

func (e *ExpiryPolicy) Unmarshal(r *buffer.Buffer) error

type Filter

type Filter map[Symbol]*DescribedType

func (Filter) Marshal

func (f Filter) Marshal(wr *buffer.Buffer) error

func (*Filter) Unmarshal

func (f *Filter) Unmarshal(r *buffer.Buffer) error

type LifetimePolicy

type LifetimePolicy uint8

func (LifetimePolicy) Marshal

func (p LifetimePolicy) Marshal(wr *buffer.Buffer) error

func (*LifetimePolicy) Unmarshal

func (p *LifetimePolicy) Unmarshal(r *buffer.Buffer) error

type MarshalField

type MarshalField struct {
	Value interface{} // value to be marshaled, use pointers to avoid interface conversion overhead
	Omit  bool        // indicates that this field should be omitted (set to null)
}

marshalField is a field to be marshaled

type Milliseconds

type Milliseconds time.Duration

func (Milliseconds) Marshal

func (m Milliseconds) Marshal(wr *buffer.Buffer) error

func (*Milliseconds) Unmarshal

func (m *Milliseconds) Unmarshal(r *buffer.Buffer) error

type MultiSymbol

type MultiSymbol []Symbol

multiSymbol can decode a single symbol or an array.

func (MultiSymbol) Marshal

func (ms MultiSymbol) Marshal(wr *buffer.Buffer) error

func (*MultiSymbol) Unmarshal

func (ms *MultiSymbol) Unmarshal(r *buffer.Buffer) error

type NullHandler

type NullHandler func() error

nullHandler is a function to be called when a composite's field is null.

type ReceiverSettleMode

type ReceiverSettleMode uint8

ReceiverSettleMode specifies how the receiver will settle messages.

const (
	// Receiver will spontaneously settle all incoming transfers.
	ModeFirst ReceiverSettleMode = 0

	// Receiver will only settle after sending the disposition to the
	// sender and receiving a disposition indicating settlement of
	// the delivery from the sender.
	ModeSecond ReceiverSettleMode = 1
)

Receiver Settlement Modes

func (ReceiverSettleMode) Marshal

func (m ReceiverSettleMode) Marshal(wr *buffer.Buffer) error

func (ReceiverSettleMode) Ptr added in v1.1.0

func (*ReceiverSettleMode) String

func (m *ReceiverSettleMode) String() string

func (*ReceiverSettleMode) Unmarshal

func (m *ReceiverSettleMode) Unmarshal(r *buffer.Buffer) error

type Role

type Role bool
const (
	RoleSender   Role = false
	RoleReceiver Role = true
)

func (Role) Marshal

func (rl Role) Marshal(wr *buffer.Buffer) error

func (Role) String

func (rl Role) String() string

func (*Role) Unmarshal

func (rl *Role) Unmarshal(r *buffer.Buffer) error

type SASLCode

type SASLCode uint8
const (
	CodeSASLOK      SASLCode = iota // Connection authentication succeeded.
	CodeSASLAuth                    // Connection authentication failed due to an unspecified problem with the supplied credentials.
	CodeSASLSysPerm                 // Connection authentication failed due to a system error that is unlikely to be corrected without intervention.
)

SASL Codes

func (SASLCode) Marshal

func (s SASLCode) Marshal(wr *buffer.Buffer) error

func (*SASLCode) Unmarshal

func (s *SASLCode) Unmarshal(r *buffer.Buffer) error

type SenderSettleMode

type SenderSettleMode uint8

SenderSettleMode specifies how the sender will settle messages.

const (
	// Sender will send all deliveries initially unsettled to the receiver.
	ModeUnsettled SenderSettleMode = 0

	// Sender will send all deliveries settled to the receiver.
	ModeSettled SenderSettleMode = 1

	// Sender MAY send a mixture of settled and unsettled deliveries to the receiver.
	ModeMixed SenderSettleMode = 2
)

Sender Settlement Modes

func (SenderSettleMode) Marshal

func (m SenderSettleMode) Marshal(wr *buffer.Buffer) error

func (SenderSettleMode) Ptr added in v1.1.0

func (*SenderSettleMode) String

func (m *SenderSettleMode) String() string

func (*SenderSettleMode) Unmarshal

func (m *SenderSettleMode) Unmarshal(r *buffer.Buffer) error

type StateAccepted

type StateAccepted struct{}

func (*StateAccepted) Marshal

func (sa *StateAccepted) Marshal(wr *buffer.Buffer) error

func (*StateAccepted) String

func (sa *StateAccepted) String() string

func (*StateAccepted) Unmarshal

func (sa *StateAccepted) Unmarshal(r *buffer.Buffer) error

type StateModified

type StateModified struct {
	// count the transfer as an unsuccessful delivery attempt
	//
	// If the delivery-failed flag is set, any messages modified
	// MUST have their delivery-count incremented.
	DeliveryFailed bool

	// prevent redelivery
	//
	// If the undeliverable-here is set, then any messages released MUST NOT
	// be redelivered to the modifying link endpoint.
	UndeliverableHere bool

	// message attributes
	// Map containing attributes to combine with the existing message-annotations
	// held in the message's header section. Where the existing message-annotations
	// of the message contain an entry with the same key as an entry in this field,
	// the value in this field associated with that key replaces the one in the
	// existing headers; where the existing message-annotations has no such value,
	// the value in this map is added.
	MessageAnnotations Annotations
}

func (*StateModified) Marshal

func (sm *StateModified) Marshal(wr *buffer.Buffer) error

func (*StateModified) String

func (sm *StateModified) String() string

func (*StateModified) Unmarshal

func (sm *StateModified) Unmarshal(r *buffer.Buffer) error

type StateReceived

type StateReceived struct {
	// When sent by the sender this indicates the first section of the message
	// (with section-number 0 being the first section) for which data can be resent.
	// Data from sections prior to the given section cannot be retransmitted for
	// this delivery.
	//
	// When sent by the receiver this indicates the first section of the message
	// for which all data might not yet have been received.
	SectionNumber uint32

	// When sent by the sender this indicates the first byte of the encoded section
	// data of the section given by section-number for which data can be resent
	// (with section-offset 0 being the first byte). Bytes from the same section
	// prior to the given offset section cannot be retransmitted for this delivery.
	//
	// When sent by the receiver this indicates the first byte of the given section
	// which has not yet been received. Note that if a receiver has received all of
	// section number X (which contains N bytes of data), but none of section number
	// X + 1, then it can indicate this by sending either Received(section-number=X,
	// section-offset=N) or Received(section-number=X+1, section-offset=0). The state
	// Received(section-number=0, section-offset=0) indicates that no message data
	// at all has been transferred.
	SectionOffset uint64
}

func (*StateReceived) Marshal

func (sr *StateReceived) Marshal(wr *buffer.Buffer) error

func (*StateReceived) Unmarshal

func (sr *StateReceived) Unmarshal(r *buffer.Buffer) error

type StateRejected

type StateRejected struct {
	Error *Error
}

func (*StateRejected) Marshal

func (sr *StateRejected) Marshal(wr *buffer.Buffer) error

func (*StateRejected) String

func (sr *StateRejected) String() string

func (*StateRejected) Unmarshal

func (sr *StateRejected) Unmarshal(r *buffer.Buffer) error

type StateReleased

type StateReleased struct{}

func (*StateReleased) Marshal

func (sr *StateReleased) Marshal(wr *buffer.Buffer) error

func (*StateReleased) String

func (sr *StateReleased) String() string

func (*StateReleased) Unmarshal

func (sr *StateReleased) Unmarshal(r *buffer.Buffer) error

type Symbol

type Symbol string

symbol is an AMQP symbolic string.

func (Symbol) Marshal

func (s Symbol) Marshal(wr *buffer.Buffer) error

type UUID

type UUID [16]byte

UUID is a 128 bit identifier as defined in RFC 4122.

func (UUID) Marshal

func (u UUID) Marshal(wr *buffer.Buffer) error

func (UUID) String

func (u UUID) String() string

String returns the hex encoded representation described in RFC 4122, Section 3.

func (*UUID) Unmarshal

func (u *UUID) Unmarshal(r *buffer.Buffer) error

type UnmarshalField

type UnmarshalField struct {
	Field      interface{}
	HandleNull NullHandler
}

unmarshalField is a struct that contains a field to be unmarshaled into.

An optional nullHandler can be set. If the composite field being unmarshaled is null and handleNull is not nil, nullHandler will be called.

type Unsettled

type Unsettled map[string]DeliveryState

func (Unsettled) Marshal

func (u Unsettled) Marshal(wr *buffer.Buffer) error

func (*Unsettled) Unmarshal

func (u *Unsettled) Unmarshal(r *buffer.Buffer) error

Jump to

Keyboard shortcuts

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