message

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: MIT Imports: 5 Imported by: 0

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

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

CloneGeneric is a utility function that recursively copies a generic structure usually resulting from a JSON parse.

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.

Types

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(parts [][]byte) *Type

New initializes a new message.

func (*Type) Append

func (m *Type) Append(b ...[]byte) int

Append adds a new message part to the message.

func (*Type) Bytes

func (m *Type) Bytes() []byte

Bytes serialises the message into a single byte array.

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) DeleteMetadata

func (m *Type) DeleteMetadata(key string)

DeleteMetadata removes a metadata key from the message.

func (*Type) Get

func (m *Type) Get(index int) []byte

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

func (*Type) GetAll

func (m *Type) GetAll() [][]byte

GetAll returns all message parts as a 2D byte slice, the contents of this slice should NOT be modified.

func (*Type) GetJSON

func (m *Type) GetJSON(part int) (interface{}, error)

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

func (*Type) GetMetadata

func (m *Type) GetMetadata(key string) string

GetMetadata returns a metadata field from its key.

func (*Type) Iter

func (m *Type) Iter(f func(i int, b []byte) error) error

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

func (*Type) IterMetadata

func (m *Type) IterMetadata(f func(k, v string) error) error

IterMetadata iterates each metadata key/value pair, calling f for each pair.

func (*Type) LazyCondition

func (m *Type) LazyCondition(label string, cond types.Condition) bool

LazyCondition resolves a particular condition on the message, if the condition has already been applied to this message the cached result is returned instead. When a message is altered in any way the conditions cache is cleared.

func (*Type) Len

func (m *Type) Len() int

Len returns the length of the message in parts.

func (*Type) Set

func (m *Type) Set(index int, b []byte)

Set the value of a message part by its index. Indexes can be negative.

func (*Type) SetAll

func (m *Type) SetAll(p [][]byte)

SetAll changes the entire set of message parts.

func (*Type) SetJSON

func (m *Type) SetJSON(part int, jObj interface{}) error

SetJSON attempts to marshal an object into a JSON string and sets a message part to the result.

func (*Type) SetMetadata

func (m *Type) SetMetadata(key, value string)

SetMetadata sets the value of a metadata key.

func (*Type) ShallowCopy

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

ShallowCopy 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 content of 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.

Jump to

Keyboard shortcuts

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