message

package
v1.20.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: MIT Imports: 7 Imported by: 14

Documentation

Overview

Package message contains implementations of types.Message.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMessagePartNotExist = errors.New("target message part does not exist")
	ErrBadMessageBytes     = errors.New("serialised message bytes were in unexpected format")
	ErrBlockCorrupted      = errors.New("serialised messages block was in unexpected format")
)

Errors returned by the message type.

Functions

func CopyJSON added in v0.37.4

func CopyJSON(root interface{}) (interface{}, error)

CopyJSON recursively creates a deep copy of a JSON structure extracted from a message part.

func GetAllBytes added in v0.23.0

func GetAllBytes(m types.Message) [][]byte

GetAllBytes returns a 2D byte slice representing the raw byte content of the parts of a message.

func GetContext added in v1.6.0

func GetContext(p types.Part) context.Context

GetContext either returns a context attached to the message part, or context.Background() if one hasn't been previously attached.

func Lock

func Lock(msg types.Message, part int) types.Message

Lock wraps a message into a read only type that restricts access to only a single message part, accessible either by index 0 or -1.

func MetaPartCopy added in v1.6.0

func MetaPartCopy(p types.Part) types.Part

MetaPartCopy creates a new empty message part by copying any meta fields (metadata, context, etc) from a reference part.

func SetAllMetadata added in v0.23.0

func SetAllMetadata(m types.Message, meta types.Metadata)

SetAllMetadata sets the metadata of all message parts to match a provided metadata implementation.

func ToBytes added in v0.23.1

func ToBytes(m types.Message) []byte

ToBytes serialises a message into a single byte array.

func WithContext added in v1.6.0

func WithContext(ctx context.Context, p types.Part) types.Part

WithContext returns the same message part wrapped with a context, this context can subsequently be received with GetContext.

Types

type Part added in v0.23.0

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

Part is an implementation of types.Part, containing the contents and metadata of a message part.

func NewPart added in v0.23.0

func NewPart(data []byte) *Part

NewPart initializes a new message part.

func (*Part) Copy added in v0.23.0

func (p *Part) Copy() types.Part

Copy creates a shallow copy of the message part.

func (*Part) DeepCopy added in v0.23.0

func (p *Part) DeepCopy() types.Part

DeepCopy creates a new deep copy of the message part.

func (*Part) Get added in v0.23.0

func (p *Part) Get() []byte

Get returns the body of the message part.

func (*Part) IsEmpty added in v0.37.3

func (p *Part) IsEmpty() bool

IsEmpty returns true if the message part is empty.

func (*Part) JSON added in v0.23.0

func (p *Part) JSON() (interface{}, error)

JSON attempts to parse the message part as a JSON document and returns the result.

func (*Part) Metadata added in v0.23.0

func (p *Part) Metadata() types.Metadata

Metadata returns the metadata of the message part.

func (*Part) Set added in v0.23.0

func (p *Part) Set(data []byte) types.Part

Set the value of the message part.

func (*Part) SetJSON added in v0.23.0

func (p *Part) SetJSON(jObj interface{}) error

SetJSON attempts to marshal a JSON document into a byte slice and stores the result as the contents of the message part.

func (*Part) SetMetadata added in v0.23.0

func (p *Part) SetMetadata(meta types.Metadata) types.Part

SetMetadata sets the metadata of a message part.

type Type

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

Type is the standard implementation of types.Message, containing a multiple part message.

func FromBytes

func FromBytes(b []byte) (*Type, error)

FromBytes deserialises a Message from a byte array.

func New

func New(bslice [][]byte) *Type

New initializes a new message from a 2D byte slice, the slice can be nil.

func (*Type) Append

func (m *Type) Append(b ...types.Part) int

Append adds a new message part to the message.

func (*Type) Copy added in v0.23.0

func (m *Type) Copy() types.Message

Copy creates a new shallow copy of the message. Parts can be re-arranged in the new copy and JSON parts can be get/set without impacting other message copies. However, it is still unsafe to edit the raw content of message parts.

func (*Type) CreatedAt

func (m *Type) CreatedAt() time.Time

CreatedAt returns a timestamp whereby the message was created.

func (*Type) DeepCopy

func (m *Type) DeepCopy() types.Message

DeepCopy creates a new deep copy of the message. This can be considered an entirely new object that is safe to use anywhere.

func (*Type) Get

func (m *Type) Get(index int) types.Part

Get returns a message part at a particular index, indexes can be negative.

func (*Type) Iter

func (m *Type) Iter(f func(i int, p types.Part) error) error

Iter will iterate all parts of the message, calling f for each.

func (*Type) Len

func (m *Type) Len() int

Len returns the length of the message in parts.

func (*Type) SetAll

func (m *Type) SetAll(parts []types.Part)

SetAll changes the entire set of message parts.

Directories

Path Synopsis
Package mapper implements ways of splicing and mapping batches of messages so that their derivative parts can be processed individually and merged back into the original batch.
Package mapper implements ways of splicing and mapping batches of messages so that their derivative parts can be processed individually and merged back into the original batch.
Package metadata contains implementations of types.Metadata.
Package metadata contains implementations of types.Metadata.
Package tracing implements utility functions for recording opentracing events for messages.
Package tracing implements utility functions for recording opentracing events for messages.

Jump to

Keyboard shortcuts

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