Documentation ¶
Overview ¶
Package sdt contains the types needed to work with Structured Data on a message. In particular, two main data types are provided, sdt.Map and sdt.Stream. They can both be used as normal Golang maps and slices as well as can be passed as a payload on a message. When retrieved, a map will contain the converted data converted as per the table on sdt.Data. Furthermore, data types can be converted using the various getters such as GetBool which will attempt to convert the specified data into a builtin.bool.
Index ¶
- type Data
- type FormatConversionError
- type IllegalTypeError
- type KeyNotFoundError
- type Map
- func (sdtMap Map) GetBool(key string) (val bool, err error)
- func (sdtMap Map) GetByte(key string) (val byte, err error)
- func (sdtMap Map) GetByteArray(key string) (val []byte, err error)
- func (sdtMap Map) GetDestination(key string) (val resource.Destination, err error)
- func (sdtMap Map) GetFloat32(key string) (val float32, err error)
- func (sdtMap Map) GetFloat64(key string) (val float64, err error)
- func (sdtMap Map) GetInt(key string) (val int, err error)
- func (sdtMap Map) GetInt16(key string) (val int16, err error)
- func (sdtMap Map) GetInt32(key string) (val int32, err error)
- func (sdtMap Map) GetInt64(key string) (val int64, err error)
- func (sdtMap Map) GetInt8(key string) (val int8, err error)
- func (sdtMap Map) GetMap(key string) (val Map, err error)
- func (sdtMap Map) GetQueue(key string) (val *resource.Queue, err error)
- func (sdtMap Map) GetStream(key string) (val Stream, err error)
- func (sdtMap Map) GetString(key string) (val string, err error)
- func (sdtMap Map) GetTopic(key string) (val *resource.Topic, err error)
- func (sdtMap Map) GetUInt(key string) (val uint, err error)
- func (sdtMap Map) GetUInt16(key string) (val uint16, err error)
- func (sdtMap Map) GetUInt32(key string) (val uint32, err error)
- func (sdtMap Map) GetUInt64(key string) (val uint64, err error)
- func (sdtMap Map) GetUInt8(key string) (val uint8, err error)
- func (sdtMap Map) GetWChar(key string) (val WChar, err error)
- type OutOfBoundsError
- type Stream
- func (sdtStream Stream) GetBool(index int) (val bool, err error)
- func (sdtStream Stream) GetByte(index int) (val byte, err error)
- func (sdtStream Stream) GetByteArray(index int) (val []byte, err error)
- func (sdtStream Stream) GetDestination(index int) (val resource.Destination, err error)
- func (sdtStream Stream) GetFloat32(index int) (val float32, err error)
- func (sdtStream Stream) GetFloat64(index int) (val float64, err error)
- func (sdtStream Stream) GetInt(index int) (val int, err error)
- func (sdtStream Stream) GetInt16(index int) (val int16, err error)
- func (sdtStream Stream) GetInt32(index int) (val int32, err error)
- func (sdtStream Stream) GetInt64(index int) (val int64, err error)
- func (sdtStream Stream) GetInt8(index int) (val int8, err error)
- func (sdtStream Stream) GetMap(index int) (val Map, err error)
- func (sdtStream Stream) GetQueue(index int) (val *resource.Queue, err error)
- func (sdtStream Stream) GetStream(index int) (val Stream, err error)
- func (sdtStream Stream) GetString(index int) (val string, err error)
- func (sdtStream Stream) GetTopic(index int) (val *resource.Topic, err error)
- func (sdtStream Stream) GetUInt(index int) (val uint, err error)
- func (sdtStream Stream) GetUInt16(index int) (val uint16, err error)
- func (sdtStream Stream) GetUInt32(index int) (val uint32, err error)
- func (sdtStream Stream) GetUInt64(index int) (val uint64, err error)
- func (sdtStream Stream) GetUInt8(index int) (val uint8, err error)
- func (sdtStream Stream) GetWChar(index int) (val WChar, err error)
- type WChar
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data interface{}
Data represents valid types that can be used in sdt.Map and sdt.Stream instances. Valid types are: int, uint, nil, bool, uint8, uint16, uint32, uint64, int8, int16, int32, int64, string, rune, float32, float64, byte, []byte, sdt.WChar, resource.Destination, sdt.Map and sdt.Stream.
Message type mapping is as follows: solClient_fieldType Golang Type SOLCLIENT_BOOL bool SOLCLIENT_UINT8 uint8 SOLCLIENT_INT8 int8 SOLCLIENT_UINT16 uint16 SOLCLIENT_INT16 int16 SOLCLIENT_UINT32 uint32 SOLCLIENT_INT32 int32 SOLCLIENT_UINT64 uint64 SOLCLIENT_INT64 int64 SOLCLIENT_WCHAR sdt.WChar SOLCLIENT_STRING string SOLCLIENT_BYTEARRAY []byte SOLCLIENT_FLOAT float32 SOLCLIENT_DOUBLE float64 SOLCLIENT_MAP sdt.Map SOLCLIENT_STREAM sdt.Stream SOLCLIENT_NULL nil SOLCLIENT_DESTINATION solace.Destination (solace.Queue or solace.Topic) SOLCLIENT_UNKNOWN []byte
On outbound messages, the following additional types are supported with the following mappings:
byte SOLCLIENT_INT8 int SOLCLIENT_INT64 uint SOLCLIENT_UINT64 rune SOLCLIENT_INT32
Notes on mappings:
- int is always be converted to int64, even when on 32-bit architectures
- uint is always be converted to uint64, even when on 32-bit architectures
- byte is the same as int8 and is mapped accordingly
In addition to these mappings, client-side conversions may be made to retrieve data in the type you want. The following table is used to determine these conversions:
Type | bool | byte | int | uint | uint8 | int8 | uint16 | int16 | uint32 | int32 | uint64 | int64 | []byte | float32 | float64 | string | WChar | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bool | x x x x x x x x x x x x x byte | x x x x x x x x x x x x x int | x x x x x x x x x x x x x uint | x x x x x x x x x x x x x uint8 | x x x x x x x x x x x x x int8 | x x x x x x x x x x x x x uint16 | x x x x x x x x x x x x x int16 | x x x x x x x x x x x x x uint32 | x x x x x x x x x x x x x int32 | x x x x x x x x x x x x x uint64 | x x x x x x x x x x x x x int64 | x x x x x x x x x x x x x []byte | x x float32 | x x float64 | x x string | x x WChar | x x x x
For each integer-type conversion, the value will be converted if it is within the range of the requested type, otherwise a conversion error will be thrown indicating that the value is outside the domain. String types will be converted to integers using strconv.Stoi and then returned if it is within the range of the requested type. For boolean conversions from integer types, all non-zero values map to true. For boolean conversion from strings, "true" and "1" map to true, "false" and "0" map to false, and all other strings are not converted. WChar conversion converts strings of length 1 into a WChar. All other strings are rejected.
In addition, the following one-to-one conversions are used:
sdt.Map, sdt.Stream
Lastly, Destination is mapped with these getters:
GetQueue, GetTopic, and GetDestination
type FormatConversionError ¶
type FormatConversionError struct { // Message is the message of the error Message string // Data is the data that could not be converted. Data interface{} }
FormatConversionError is returned if there is an error converting stored data to a specified return type.
func (*FormatConversionError) Error ¶
func (err *FormatConversionError) Error() string
Error implements the error interface and returns the error message as string.
type IllegalTypeError ¶
type IllegalTypeError struct {
Data interface{}
}
IllegalTypeError is returned if an error occurs while encoding a stored type to a message when setting a payload or user property.
func (*IllegalTypeError) Error ¶
func (err *IllegalTypeError) Error() string
Error implements the error interface and returns the error message as string.
type KeyNotFoundError ¶
type KeyNotFoundError struct { // Key is the key that was being accessed and does not exist. Key string }
KeyNotFoundError is returned if the requested key is not found.
func (*KeyNotFoundError) Error ¶
func (err *KeyNotFoundError) Error() string
type Map ¶
Map represents a map between strings and values that can be converted into structured data types in a message payload. Accepts any valid sdt.Data types.
func (Map) GetBool ¶
GetBool retrieves the data using the specified key and attempts to convert the data into a boolean form, if necessary. Returns the boolean value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into boolean form.
func (Map) GetByte ¶
GetByte retrieves the data at the specified key and attempt to convert the data into byte form if necessary. Returns the byte value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into byte form.
func (Map) GetByteArray ¶
GetByteArray retrieves the data at the specified key and attempt to convert the data into []byte form if necessary. Returns the []byte value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into []byte form.
func (Map) GetDestination ¶
func (sdtMap Map) GetDestination(key string) (val resource.Destination, err error)
GetDestination retrieves the data at the specified key as a Destination. One of the following errors may occur:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data is not of type Destination.
func (Map) GetFloat32 ¶
GetFloat32 retrieves the data at the specified key and attempt to convert the data into float32 form if necessary. Returns the float32 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into float32 form.
func (Map) GetFloat64 ¶
GetFloat64 retrieves the data at the specified key and attempt to convert the data into float64 form if necessary. Returns the float64 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into float64 form.
func (Map) GetInt ¶
GetInt retrieves the data at the specified key and attempt to convert the data into int form if necessary. Returns the int value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into int form.
func (Map) GetInt16 ¶
GetInt16 retrieves the data at the specified key and attempt to convert the data into int16 form if necessary. Returns the int16 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into int16 form.
func (Map) GetInt32 ¶
GetInt32 retrieves the data at the specified key and attempt to convert the data into int32 form if necessary. Returns the int32 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into int32 form.
func (Map) GetInt64 ¶
GetInt64 retrieves the data at the specified key and attempt to convert the data into int64 form if necessary. Returns the int64 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into int64 form.
func (Map) GetInt8 ¶
GetInt8 retrieves the data at the specified key and attempt to convert the data into int8 form if necessary. Returns the int8 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into int8 form.
func (Map) GetMap ¶
GetMap retrieves the data at the specified key as an sdt.Map. One of the following errors may occur:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data is not of type sdt.Map.
func (Map) GetQueue ¶
GetQueue retrieves the data at the specified key as a Queue. One of the following errors may occur:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data is not of type Queue.
func (Map) GetStream ¶
GetStream retrieves the data at the specified key as an sdt.Stream. One of the following errors may occur:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data is not of type sdt.Stream.
func (Map) GetString ¶
GetString retrieves the data at the specified key and attempt to convert the data into string form if necessary. Returns the string value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into string form.
func (Map) GetTopic ¶
GetTopic retrieves the data at the specified key as a Topic. One of the following errors may occur:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data is not of type Topic.
func (Map) GetUInt ¶
GetUInt retrieves the data at the specified key and attempt to convert the data into uint form if necessary. Returns the uint value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into uint form.
func (Map) GetUInt16 ¶
GetUInt16 retrieves the data at the specified key and attempt to convert the data into uint16 form if necessary. Returns the uint16 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError if a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into uint16 form.
func (Map) GetUInt32 ¶
GetUInt32 retrieves the data at the specified key and attempt to convert the data into uint32 form if necessary. Returns the uint32 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError if the data cannot be converted into uint32 form.
func (Map) GetUInt64 ¶
GetUInt64 retrieves the data at the specified key and attempt to convert the data into uint64 form if necessary. Returns the uint64 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into uint64 form
func (Map) GetUInt8 ¶
GetUInt8 retrieves the data at the specified key and attempt to convert the data into uint8 form if necessary. Returns the uint8 value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into uint8 form.
func (Map) GetWChar ¶
GetWChar retrieves the data at the specified key and attempt to convert the data into WChar form if necessary. Returns the WChar value of the field, and one of the following errors if it occurred:
- sdt.KeyNotFoundError - If a mapping for the specified key was not found.
- sdt.FormatConversionError - If the data cannot be converted into WChar form.
type OutOfBoundsError ¶
type OutOfBoundsError struct {
Index int
}
OutOfBoundsError is returned if the specified index is out of bounds.
func (*OutOfBoundsError) Error ¶
func (err *OutOfBoundsError) Error() string
type Stream ¶
type Stream []Data
Stream represents a stream of data that can be converted into structured data types in a message payload. Accepts any valid sdt.Data types.
func (Stream) GetBool ¶
GetBool retrieves the data at the specified index and attempt to convert the data into boolean form if necessary. Returns the boolean value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into boolean form.
func (Stream) GetByte ¶
GetByte retrieves the data at the specified index and attempt to convert the data into byte form if necessary. Returns the byte value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into byte form.
func (Stream) GetByteArray ¶
GetByteArray retrieves the data at the specified index and attempt to convert the data into []byte form if necessary. Returns the []byte value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into []byte form.
func (Stream) GetDestination ¶
func (sdtStream Stream) GetDestination(index int) (val resource.Destination, err error)
GetDestination retrieves the data at the specified index as a Destination. One of the following errors may occur:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data is not of type Destination.
func (Stream) GetFloat32 ¶
GetFloat32 retrieves the data at the specified index and attempt to convert the data into float32 form if necessary. Returns the float32 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into float32 form.
func (Stream) GetFloat64 ¶
GetFloat64 retrieves the data at the specified index and attempt to convert the data into float64 form if necessary. Returns the float64 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into float64 form.
func (Stream) GetInt ¶
GetInt retrieves the data at the specified index and attempt to convert the data into int form if necessary. Returns the int value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into int form.
func (Stream) GetInt16 ¶
GetInt16 retrieves the data at the specified index and attempt to convert the data into int16 form if necessary. Returns the int16 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into int16 form.
func (Stream) GetInt32 ¶
GetInt32 retrieves the data at the specified index and attempt to convert the data into int32 form if necessary. Returns the int32 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into int32 form.
func (Stream) GetInt64 ¶
GetInt64 retrieves the data at the specified index and attempt to convert the data into int64 form if necessary. Returns the int64 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into int64 form.
func (Stream) GetInt8 ¶
GetInt8 retrieves the data at the specified index and attempt to convert the data into int8 form if necessary. Returns the int8 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into int8 form.
func (Stream) GetMap ¶
GetMap retrieves the data at the specified index as an sdt.Map. One of the following errors may occur:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data is not of type sdt.Map.
func (Stream) GetQueue ¶
GetQueue retrieves the data at the specified index as a Queue. One of the following errors may occur:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data is not of type Queue.
func (Stream) GetStream ¶
GetStream retrieves the data at the specified index as an sdt.Stream. One of the following errors may occur:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data is not of type sdt.Stream.
func (Stream) GetString ¶
GetString retrieves the data at the specified index and attempt to convert the data into string form if necessary. Returns the string value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into string form.
func (Stream) GetTopic ¶
GetTopic retrieves the data at the specified index as a Topic. One of the following errors may occur:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data is not of type Topic.
func (Stream) GetUInt ¶
GetUInt retrieves the data at the specified index and attempt to convert the data into uint form if necessary. Returns the uint value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into uint form.
func (Stream) GetUInt16 ¶
GetUInt16 retrieves the data at the specified index and attempt to convert the data into uint16 form if necessary. Returns the uint16 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into uint16 form.
func (Stream) GetUInt32 ¶
GetUInt32 retrieves the data at the specified index and attempt to convert the data into uint32 form if necessary. Returns the uint32 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into uint32 form.
func (Stream) GetUInt64 ¶
GetUInt64 retrieves the data at the specified index and attempt to convert the data into uint64 form if necessary. Returns the uint64 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into uint64 form.
func (Stream) GetUInt8 ¶
GetUInt8 retrieves the data at the specified index and attempt to convert the data into uint8 form if necessary. Returns the uint8 value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into uint8 form.
func (Stream) GetWChar ¶
GetWChar retrieves the data at the specified index and attempt to convert the data into WChar form if necessary. Returns the WChar value of the field, and one of the following errors if it occurred:
- sdt.OutOfBoundsError - If the specified index is out of the stream's bounds.
- sdt.FormatConversionError - If the data cannot be converted into WChar form.