message

package
v3.12.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2020 License: MIT Imports: 8 Imported by: 18

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

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

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

func GetAllBytes

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

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

func GetAllBytesLen

func GetAllBytesLen(m types.Message) int

GetAllBytesLen returns total length of message content in bytes

func GetContext

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

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

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

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

func ToBytes

func ToBytes(m types.Message) []byte

ToBytes serialises a message into a single byte array.

func WithContext

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

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

func NewPart(data []byte) *Part

NewPart initializes a new message part.

func (*Part) Copy

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

Copy creates a shallow copy of the message part.

func (*Part) DeepCopy

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

DeepCopy creates a new deep copy of the message part.

func (*Part) Get

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

Get returns the body of the message part.

func (*Part) IsEmpty

func (p *Part) IsEmpty() bool

IsEmpty returns true if the message part is empty.

func (*Part) JSON

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

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

func (*Part) Metadata

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

Metadata returns the metadata of the message part.

func (*Part) Set

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

Set the value of the message part.

func (*Part) SetJSON

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

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

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 batch provides tooling for creating and executing Benthos message batch policies.
Package batch provides tooling for creating and executing Benthos message batch policies.
Package io provides tooling for serialising and deserialising messages.
Package io provides tooling for serialising and deserialising messages.
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 roundtrip provides tooling for composing request/response behaviour through messages.
Package roundtrip provides tooling for composing request/response behaviour through messages.
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