...

Package td

import "github.com/Diarkis/diarkis/td"
Overview
Index

Overview ▾

Package td ▷

td package: TransportData package represents data structure for transportation between servers.

TransportData encodes the data representation to []byte and decodes from it back to the data representation.

[IMPORTANT] TransportData is meant to be used as mesh message data

How to use TransportData

In order to use TransportData, you must "define" how your data should be structured.

The example below shows how you would define a TransportData:

car := td.DefineTransportData([]td.Property{
	td.Property{ Name: "Name", Type: td.String },
	td.Property{ Name: "EngineModel", Type: td.Uint8 },
	td.Property{ Name: "BodyColorCode", Type: td.Uint16 },
})

How to use defined TransportData

goodCar := car.New()
goodCar.SetAsString("Name", "SL Roadster")
goodCar.SetAsUint8("EngineModel", 17)
goodCar.SetAsUint16("BodyColorCode", 1048)

How to encode and decode TransportData

To encode:

encoded := goodCar.Pack()

To decode:

goodCarCopy := car.New()
goodCarCopy.Unpack(encoded)

name, err := goodCarCopy.GetAsString("Name")                   // SL Roadster
engineModule, err := goodCarCopy.GetAsUint8("EngineModel")     // 17
bodyColorCode, err := goodCarCopy.GetAsUint16("BodyColorCode") //1048

Index ▾

Constants
func TestTransportData()
type Property
type TransportData
    func (s *TransportData) GetAllPropertyNames() []string
    func (s *TransportData) GetAsBool(name string) (bool, error)
    func (s *TransportData) GetAsBoolArray(name string) ([]bool, error)
    func (s *TransportData) GetAsBytes(name string) ([]byte, error)
    func (s *TransportData) GetAsBytesArray(name string) ([][]byte, error)
    func (s *TransportData) GetAsFloat32(name string) (float32, error)
    func (s *TransportData) GetAsFloat32Array(name string) ([]float32, error)
    func (s *TransportData) GetAsFloat64(name string) (float64, error)
    func (s *TransportData) GetAsFloat64Array(name string) ([]float64, error)
    func (s *TransportData) GetAsInt(name string) (int, error)
    func (s *TransportData) GetAsInt16(name string) (int16, error)
    func (s *TransportData) GetAsInt16Array(name string) ([]int16, error)
    func (s *TransportData) GetAsInt32(name string) (int32, error)
    func (s *TransportData) GetAsInt32Array(name string) ([]int32, error)
    func (s *TransportData) GetAsInt64(name string) (int64, error)
    func (s *TransportData) GetAsInt64Array(name string) ([]int64, error)
    func (s *TransportData) GetAsInt8(name string) (int8, error)
    func (s *TransportData) GetAsInt8Array(name string) ([]int8, error)
    func (s *TransportData) GetAsIntArray(name string) ([]int, error)
    func (s *TransportData) GetAsString(name string) (string, error)
    func (s *TransportData) GetAsStringArray(name string) ([]string, error)
    func (s *TransportData) GetAsUint(name string) (uint, error)
    func (s *TransportData) GetAsUint16(name string) (uint16, error)
    func (s *TransportData) GetAsUint16Array(name string) ([]uint16, error)
    func (s *TransportData) GetAsUint32(name string) (uint32, error)
    func (s *TransportData) GetAsUint32Array(name string) ([]uint32, error)
    func (s *TransportData) GetAsUint64(name string) (uint64, error)
    func (s *TransportData) GetAsUint64Array(name string) ([]uint64, error)
    func (s *TransportData) GetAsUint8(name string) (uint8, error)
    func (s *TransportData) GetAsUint8Array(name string) ([]uint8, error)
    func (s *TransportData) GetAsUintArray(name string) ([]uint, error)
    func (s *TransportData) Pack() []byte
    func (s *TransportData) SetAsBool(name string, value bool) error
    func (s *TransportData) SetAsBoolArray(name string, value []bool) error
    func (s *TransportData) SetAsBytes(name string, value []byte) error
    func (s *TransportData) SetAsBytesArray(name string, value [][]byte) error
    func (s *TransportData) SetAsFloat32(name string, value float32) error
    func (s *TransportData) SetAsFloat32Array(name string, value []float32) error
    func (s *TransportData) SetAsFloat64(name string, value float64) error
    func (s *TransportData) SetAsFloat64Array(name string, value []float64) error
    func (s *TransportData) SetAsInt(name string, value int) error
    func (s *TransportData) SetAsInt16(name string, value int16) error
    func (s *TransportData) SetAsInt16Array(name string, value []int16) error
    func (s *TransportData) SetAsInt32(name string, value int32) error
    func (s *TransportData) SetAsInt32Array(name string, value []int32) error
    func (s *TransportData) SetAsInt64(name string, value int64) error
    func (s *TransportData) SetAsInt64Array(name string, value []int64) error
    func (s *TransportData) SetAsInt8(name string, value int8) error
    func (s *TransportData) SetAsInt8Array(name string, value []int8) error
    func (s *TransportData) SetAsIntArray(name string, value []int) error
    func (s *TransportData) SetAsString(name string, value string) error
    func (s *TransportData) SetAsStringArray(name string, value []string) error
    func (s *TransportData) SetAsUint(name string, value uint) error
    func (s *TransportData) SetAsUint16(name string, value uint16) error
    func (s *TransportData) SetAsUint16Array(name string, value []uint16) error
    func (s *TransportData) SetAsUint32(name string, value uint32) error
    func (s *TransportData) SetAsUint32Array(name string, value []uint32) error
    func (s *TransportData) SetAsUint64(name string, value uint64) error
    func (s *TransportData) SetAsUint64Array(name string, value []uint64) error
    func (s *TransportData) SetAsUint8(name string, value uint8) error
    func (s *TransportData) SetAsUint8Array(name string, value []uint8) error
    func (s *TransportData) SetAsUintArray(name string, value []uint) error
    func (s *TransportData) String() string
    func (s *TransportData) Unpack(bytes []byte)
type TransportDataDefinition
    func DefineTransportData(properties []Property) *TransportDataDefinition
    func (s *TransportDataDefinition) New() *TransportData

Constants

Bool represents bool

const Bool = 40

BoolArray represents []bool

const BoolArray = 140

Bytes represents []byte

const Bytes = 50

BytesArray represents [][]byte

const BytesArray = 150

Float32 represents float32

const Float32 = 20

Float32Array represents []float32

const Float32Array = 120

Float64 represents float64

const Float64 = 21

Float64Array represents []float64

const Float64Array = 121

Int represents int

const Int = 1

Int16 represents int16

const Int16 = 3

Int16Array represents []int16

const Int16Array = 103

Int32 represents int32

const Int32 = 4

Int32Array represents []int32

const Int32Array = 104

Int64 represents int64

const Int64 = 5

Int64Array represents []int64

const Int64Array = 105

Int8 represents int8

const Int8 = 2

Int8Array represents []int8

const Int8Array = 102

IntArray represents []int

const IntArray = 100

String represents string

const String = 30

StringArray represents []string

const StringArray = 130

Uint represents uint

const Uint = 10

Uint16 represents uint16

const Uint16 = 12

Uint16Array represents []uint16

const Uint16Array = 112

Uint32 represents uint32

const Uint32 = 13

Uint32Array represents []uint32

const Uint32Array = 113

Uint64 represents uint64

const Uint64 = 14

Uint64Array represents []uint64

const Uint64Array = 114

Uint8 represents uint8

const Uint8 = 11

Uint8Array represents []uint8

const Uint8Array = 111

UintArray represents []uint

const UintArray = 110

func TestTransportData

func TestTransportData()

TestTransportData executes tests on TransportData. If the test fails it throws a panic.

type Property

Property represents a property of a TransportData.

type Property struct {
    Name string
    Type int
}

type TransportData

TransportData represents the data to be sent and received by remote server nodes.

type TransportData struct {
    sync.RWMutex
    // contains filtered or unexported fields
}

func (*TransportData) GetAllPropertyNames

func (s *TransportData) GetAllPropertyNames() []string

GetAllPropertyNames returns all defined property names as an array.

func (*TransportData) GetAsBool

func (s *TransportData) GetAsBool(name string) (bool, error)

GetAsBool returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsBoolArray

func (s *TransportData) GetAsBoolArray(name string) ([]bool, error)

GetAsBoolArray returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsBytes

func (s *TransportData) GetAsBytes(name string) ([]byte, error)

GetAsBytes returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsBytesArray

func (s *TransportData) GetAsBytesArray(name string) ([][]byte, error)

GetAsBytesArray returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsFloat32

func (s *TransportData) GetAsFloat32(name string) (float32, error)

GetAsFloat32 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsFloat32Array

func (s *TransportData) GetAsFloat32Array(name string) ([]float32, error)

GetAsFloat32Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsFloat64

func (s *TransportData) GetAsFloat64(name string) (float64, error)

GetAsFloat64 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsFloat64Array

func (s *TransportData) GetAsFloat64Array(name string) ([]float64, error)

GetAsFloat64Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt

func (s *TransportData) GetAsInt(name string) (int, error)

GetAsInt returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt16

func (s *TransportData) GetAsInt16(name string) (int16, error)

GetAsInt16 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt16Array

func (s *TransportData) GetAsInt16Array(name string) ([]int16, error)

GetAsInt16Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt32

func (s *TransportData) GetAsInt32(name string) (int32, error)

GetAsInt32 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt32Array

func (s *TransportData) GetAsInt32Array(name string) ([]int32, error)

GetAsInt32Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt64

func (s *TransportData) GetAsInt64(name string) (int64, error)

GetAsInt64 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt64Array

func (s *TransportData) GetAsInt64Array(name string) ([]int64, error)

GetAsInt64Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt8

func (s *TransportData) GetAsInt8(name string) (int8, error)

GetAsInt8 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsInt8Array

func (s *TransportData) GetAsInt8Array(name string) ([]int8, error)

GetAsInt8Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsIntArray

func (s *TransportData) GetAsIntArray(name string) ([]int, error)

GetAsIntArray returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsString

func (s *TransportData) GetAsString(name string) (string, error)

GetAsString returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsStringArray

func (s *TransportData) GetAsStringArray(name string) ([]string, error)

GetAsStringArray returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint

func (s *TransportData) GetAsUint(name string) (uint, error)

GetAsUint returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint16

func (s *TransportData) GetAsUint16(name string) (uint16, error)

GetAsUint16 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint16Array

func (s *TransportData) GetAsUint16Array(name string) ([]uint16, error)

GetAsUint16Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint32

func (s *TransportData) GetAsUint32(name string) (uint32, error)

GetAsUint32 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint32Array

func (s *TransportData) GetAsUint32Array(name string) ([]uint32, error)

GetAsUint32Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint64

func (s *TransportData) GetAsUint64(name string) (uint64, error)

GetAsUint64 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint64Array

func (s *TransportData) GetAsUint64Array(name string) ([]uint64, error)

GetAsUint64Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint8

func (s *TransportData) GetAsUint8(name string) (uint8, error)

GetAsUint8 returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUint8Array

func (s *TransportData) GetAsUint8Array(name string) ([]uint8, error)

GetAsUint8Array returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) GetAsUintArray

func (s *TransportData) GetAsUintArray(name string) ([]uint, error)

GetAsUintArray returns the value of the given name. It returns false if the given name has not been defined.

func (*TransportData) Pack

func (s *TransportData) Pack() []byte

Pack encodes the data into byte array.

func (*TransportData) SetAsBool

func (s *TransportData) SetAsBool(name string, value bool) error

SetAsBool assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsBoolArray

func (s *TransportData) SetAsBoolArray(name string, value []bool) error

SetAsBoolArray assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsBytes

func (s *TransportData) SetAsBytes(name string, value []byte) error

SetAsBytes assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsBytesArray

func (s *TransportData) SetAsBytesArray(name string, value [][]byte) error

SetAsBytesArray assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsFloat32

func (s *TransportData) SetAsFloat32(name string, value float32) error

SetAsFloat32 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsFloat32Array

func (s *TransportData) SetAsFloat32Array(name string, value []float32) error

SetAsFloat32Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsFloat64

func (s *TransportData) SetAsFloat64(name string, value float64) error

SetAsFloat64 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsFloat64Array

func (s *TransportData) SetAsFloat64Array(name string, value []float64) error

SetAsFloat64Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt

func (s *TransportData) SetAsInt(name string, value int) error

SetAsInt assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt16

func (s *TransportData) SetAsInt16(name string, value int16) error

SetAsInt16 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt16Array

func (s *TransportData) SetAsInt16Array(name string, value []int16) error

SetAsInt16Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt32

func (s *TransportData) SetAsInt32(name string, value int32) error

SetAsInt32 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt32Array

func (s *TransportData) SetAsInt32Array(name string, value []int32) error

SetAsInt32Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt64

func (s *TransportData) SetAsInt64(name string, value int64) error

SetAsInt64 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt64Array

func (s *TransportData) SetAsInt64Array(name string, value []int64) error

SetAsInt64Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt8

func (s *TransportData) SetAsInt8(name string, value int8) error

SetAsInt8 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsInt8Array

func (s *TransportData) SetAsInt8Array(name string, value []int8) error

SetAsInt8Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsIntArray

func (s *TransportData) SetAsIntArray(name string, value []int) error

SetAsIntArray assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsString

func (s *TransportData) SetAsString(name string, value string) error

SetAsString assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsStringArray

func (s *TransportData) SetAsStringArray(name string, value []string) error

SetAsStringArray assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint

func (s *TransportData) SetAsUint(name string, value uint) error

SetAsUint assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint16

func (s *TransportData) SetAsUint16(name string, value uint16) error

SetAsUint16 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint16Array

func (s *TransportData) SetAsUint16Array(name string, value []uint16) error

SetAsUint16Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint32

func (s *TransportData) SetAsUint32(name string, value uint32) error

SetAsUint32 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint32Array

func (s *TransportData) SetAsUint32Array(name string, value []uint32) error

SetAsUint32Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint64

func (s *TransportData) SetAsUint64(name string, value uint64) error

SetAsUint64 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint64Array

func (s *TransportData) SetAsUint64Array(name string, value []uint64) error

SetAsUint64Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint8

func (s *TransportData) SetAsUint8(name string, value uint8) error

SetAsUint8 assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUint8Array

func (s *TransportData) SetAsUint8Array(name string, value []uint8) error

SetAsUint8Array assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) SetAsUintArray

func (s *TransportData) SetAsUintArray(name string, value []uint) error

SetAsUintArray assigns a value to the given name.

It will fail (return an error) if you pass the name and/or type that has not been defined by DefineTransportData.

func (*TransportData) String

func (s *TransportData) String() string

String returns a string encoded TransportData's internal data.

func (*TransportData) Unpack

func (s *TransportData) Unpack(bytes []byte)

Unpack decodes the encoded TransportData byte array.

type TransportDataDefinition

TransportDataDefinition represents the definition of a TransportData.

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

func DefineTransportData

func DefineTransportData(properties []Property) *TransportDataDefinition

DefineTransportData creates a data structure definition and returns an instance of TransportDataDefinition.

With the returned instance of TransportDataDefinition, you may create instances of TransportData to create transport data for mesh message delivery.

func (*TransportDataDefinition) New

func (s *TransportDataDefinition) New() *TransportData

New returns an instance of TransportData with the data structure of the defined TransportDataDefinition.