message

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package message provides functions for managing data used by conditions and transforms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

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

Message is the data structure that is handled by transforms and interpreted by conditions.

Data in each message can be accessed and modified as JSON text or binary data:

  • JSON text is accessed using the GetValue, SetValue, and DeleteValue methods.
  • Binary data is accessed using the Data and SetData methods.

Metadata is an additional data field that is meant to store information about the message, but can be used for any purpose. For JSON text, metadata is accessed using the GetValue, SetValue, and DeleteValue methods with a key prefixed with "meta" (e.g. "meta foo"). Binary metadata is accessed using the Metadata and SetMetadata methods.

Messages can also be configured as "control messages." Control messages are used for flow control in Substation functions and applications, but can be used for any purpose depending on the needs of a transform or condition. These messages should not contain data or metadata.

func New

func New(opts ...func(*Message)) *Message

New returns a new Message.

func (*Message) AsControl

func (m *Message) AsControl() *Message

AsControl sets the message as a control message.

func (*Message) Data

func (m *Message) Data() []byte

Data returns the message data.

func (*Message) DeleteValue

func (m *Message) DeleteValue(key string) error

DeleteValue deletes a value in the message data or metadata.

If the key is prefixed with "meta" (e.g. "meta foo"), then the value is removed from the metadata field, otherwise it is removed from the data field.

This only works with JSON text. If the message data or metadata is not JSON text, then this method does nothing.

func (*Message) GetValue

func (m *Message) GetValue(key string) Value

GetValue returns a value from the message data or metadata.

If the key is prefixed with "meta" (e.g. "meta foo"), then the value is retrieved from the metadata field, otherwise it is retrieved from the data field.

This only works with JSON text. If the message data or metadata is not JSON text, then an empty value is returned.

func (*Message) IsControl

func (m *Message) IsControl() bool

IsControl returns true if the message is a control message.

func (*Message) Metadata

func (m *Message) Metadata() []byte

Metadata returns the message metadata.

func (*Message) SetData

func (m *Message) SetData(data []byte) *Message

SetData sets the message data.

func (*Message) SetMetadata

func (m *Message) SetMetadata(metadata []byte) *Message

SetMetadata sets the message metadata.

func (*Message) SetValue

func (m *Message) SetValue(key string, value interface{}) error

SetValue sets a value in the message data or metadata.

If the key is prefixed with "meta" (e.g. "meta foo"), then the value is placed into the metadata field, otherwise it is placed into the data field.

This only works with JSON text. If the message data or metadata is not JSON text, then this method does nothing.

func (*Message) String

func (m *Message) String() string

String returns the message data as a string.

type Value

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

Value is a wrapper around gjson.Result that provides a consistent interface for converting values from JSON text.

func (Value) Array

func (v Value) Array() []Value

Array returns the value as a slice of Value.

func (Value) Bool

func (v Value) Bool() bool

Bool returns the value as a bool.

func (Value) Bytes

func (v Value) Bytes() []byte

Bytes returns the value as a byte slice.

func (Value) Exists

func (v Value) Exists() bool

Exists returns true if the value exists.

func (Value) Float

func (v Value) Float() float64

Float returns the value as a float64.

func (Value) Int

func (v Value) Int() int64

Int returns the value as an int64.

func (Value) IsArray

func (v Value) IsArray() bool

IsArray returns true if the value is an array.

func (Value) Map

func (v Value) Map() map[string]Value

Map returns the value as a map of string to Value.

func (Value) String

func (v Value) String() string

String returns the value as a string.

func (Value) Uint

func (v Value) Uint() uint64

Uint returns the value as a uint64.

func (Value) Value

func (v Value) Value() any

Value returns the value as an interface{}.

Jump to

Keyboard shortcuts

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