serialization

package
v0.0.0-...-4027d08 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodeDict = make(map[byte]*CustomType)
View Source
var TypeDict = make(map[reflect.Type]*CustomType)

Functions

func DeserializeFloat

func DeserializeFloat(source []byte, offset int) (result float32, newOffset int)

func DeserializeInt

func DeserializeInt(source []byte, offset int) (result int, newOffset int)

func DeserializeShort

func DeserializeShort(source []byte, offset int) (result int16, newOffset int)

func SerializeFloat

func SerializeFloat(value float32, target []byte, targetOffset int) ([]byte, int)

func SerializeInt

func SerializeInt(value int, target []byte, targetOffset int) ([]byte, int)

func SerializeShort

func SerializeShort(value int16, target []byte, targetOffset int) ([]byte, int)

func TryRegisterType

func TryRegisterType(
	myType reflect.Type,
	typeCode byte,
	serializeFunc func(customObject interface{}) []byte,
	deserializeFunc func(serializedCustomObject []byte) interface{}) bool

func TryRegisteringStreamType

func TryRegisteringStreamType(
	myType reflect.Type,
	typeCode byte,
	serializeFunc func(customObject interface{}, outStream *StreamBuffer) int16,
	deserializeFunc func(buffer *StreamBuffer, length int16) interface{}) bool

Types

type ByteArraySlice

type ByteArraySlice struct {
	io.Closer
	Buffer []byte
	Offset int
	Count  int
	// contains filtered or unexported fields
}

func NewByteArraySlice

func NewByteArraySlice(returnPool *ByteArraySlicePool, stackIndex int) *ByteArraySlice

func (*ByteArraySlice) Dispose

func (slice *ByteArraySlice) Dispose()

func (*ByteArraySlice) Release

func (slice *ByteArraySlice) Release() bool

type ByteArraySlicePool

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

func NewByteArraySlicePool

func NewByteArraySlicePool() *ByteArraySlicePool

func (*ByteArraySlicePool) Acquire

func (pool *ByteArraySlicePool) Acquire(minByteCount int) *ByteArraySlice

func (*ByteArraySlicePool) PopOrCreate

func (pool *ByteArraySlicePool) PopOrCreate(stack *Stack, stackIndex int) *ByteArraySlice

func (*ByteArraySlicePool) Release

func (pool *ByteArraySlicePool) Release(slice *ByteArraySlice, stackIndex int) bool

type CustomType

type CustomType struct {
	Code                    byte
	DeserializeMethod       func(serializedCustomObject []byte) interface{}
	DeserializeStreamMethod func(buffer *StreamBuffer, length int16) interface{}
	SerializeMethod         func(customObject interface{}) []byte
	SerializeStreamMethod   func(customObject interface{}, outStream *StreamBuffer) int16
	Type                    reflect.Type
}

func NewCustomStreamType

func NewCustomStreamType(
	myType reflect.Type,
	code byte,
	serializeStreamFunction func(customObject interface{}, outStream *StreamBuffer) int16,
	deserializeStreamFunction func(buffer *StreamBuffer, length int16) interface{}) *CustomType

func NewCustomType

func NewCustomType(
	myType reflect.Type,
	code byte,
	serializeFunction func(customObject interface{}) []byte,
	deserializeFunction func(serializedCustomObject []byte) interface{}) *CustomType

type DisconnectMessage

type DisconnectMessage struct {
	Code         int16
	DebugMessage string
	Parameters   map[byte]interface{}
}

type EventData

type EventData struct {
	Code          byte
	Parameters    map[byte]interface{}
	SenderKey     byte
	Sender        int
	CustomDataKey byte
	CustomData    interface{}
}

func NewEventData

func NewEventData() *EventData

func (*EventData) Get

func (e *EventData) Get(key byte) interface{}

func (*EventData) GetCustomData

func (e *EventData) GetCustomData() interface{}

func (*EventData) GetSender

func (e *EventData) GetSender() int

func (*EventData) Reset

func (e *EventData) Reset()

func (*EventData) ToString

func (e *EventData) ToString() string

type IProtocol

type IProtocol interface {
	GetProtocolBase() *ProtocolBase
	Serialize(dout *StreamBuffer, obj interface{}, setType bool)
	SerializeOperationRequest(stream *StreamBuffer, operationCode byte, parameters map[byte]interface{}, setType bool)
	SerializeOperationResponse(stream *StreamBuffer, value *OperationResponse, setType bool)
	SerializeShort(dout *StreamBuffer, value int16, setType bool)
	SerializeString(dout *StreamBuffer, value string, setType bool)
	SerializeEventData(stream *StreamBuffer, value *EventData, setType bool)
	Deserialize(din *StreamBuffer, theType byte, flags constants.DeserializationFlags) interface{}
	DeserializeEventData(din *StreamBuffer, target *EventData, flags constants.DeserializationFlags) *EventData
	DeserializeOperationRequest(din *StreamBuffer, flags constants.DeserializationFlags) *OperationRequest
	DeserializeOperationResponse(stream *StreamBuffer, flags constants.DeserializationFlags) *OperationResponse
	DeserializeDisconnectMessage(stream *StreamBuffer) *DisconnectMessage
	DeserializeShort(din *StreamBuffer) int16
	DeserializeByte(din *StreamBuffer) byte
}

type OperationRequest

type OperationRequest struct {
	OperationCode byte
	Parameters    map[byte]interface{}
}

type OperationResponse

type OperationResponse struct {
	OperationCode byte
	ReturnCode    int16
	DebugMessage  string
	Parameters    map[byte]interface{}
}

func NewOperationResponse

func NewOperationResponse() *OperationResponse

func (*OperationResponse) Get

func (res *OperationResponse) Get(parameterCode byte) interface{}

Get the Parameter for a given parameterCode. Returns nil if the parameterCode is not found.

type Protocol18

type Protocol18 struct {
	*ProtocolBase
	// contains filtered or unexported fields
}

func NewProtocol18

func NewProtocol18() *Protocol18

func (*Protocol18) DecodeZigZag32

func (pr *Protocol18) DecodeZigZag32(value uint) int

func (*Protocol18) DecodeZigZag64

func (pr *Protocol18) DecodeZigZag64(value uint64) int64

func (*Protocol18) Deserialize

func (pr *Protocol18) Deserialize(din *StreamBuffer, theType byte, flags constants.DeserializationFlags) interface{}

func (*Protocol18) DeserializeByte

func (pr *Protocol18) DeserializeByte(din *StreamBuffer) byte

func (*Protocol18) DeserializeDisconnectMessage

func (pr *Protocol18) DeserializeDisconnectMessage(stream *StreamBuffer) *DisconnectMessage

func (*Protocol18) DeserializeEventData

func (pr *Protocol18) DeserializeEventData(din *StreamBuffer, target *EventData, flags constants.DeserializationFlags) *EventData

func (*Protocol18) DeserializeOperationRequest

func (pr *Protocol18) DeserializeOperationRequest(din *StreamBuffer, flags constants.DeserializationFlags) *OperationRequest

func (*Protocol18) DeserializeOperationResponse

func (pr *Protocol18) DeserializeOperationResponse(stream *StreamBuffer, flags constants.DeserializationFlags) *OperationResponse

func (*Protocol18) DeserializeShort

func (pr *Protocol18) DeserializeShort(din *StreamBuffer) int16

func (*Protocol18) EncodeZigZag32

func (pr *Protocol18) EncodeZigZag32(value int) uint

func (*Protocol18) EncodeZigZag64

func (pr *Protocol18) EncodeZigZag64(value int64) uint64

func (*Protocol18) GetAllowedDictionaryKeyTypes

func (pr *Protocol18) GetAllowedDictionaryKeyTypes(gpType constants.GpType18) reflect.Kind

func (*Protocol18) GetClrArrayType

func (pr *Protocol18) GetClrArrayType(gpType constants.GpType18) reflect.Kind

func (*Protocol18) GetCodeOfType

func (pr *Protocol18) GetCodeOfType(myType reflect.Kind, item interface{}, typee reflect.Type) constants.GpType18

func (*Protocol18) GetDictArrayType

func (pr *Protocol18) GetDictArrayType(stream *StreamBuffer) reflect.Kind

func (*Protocol18) GetProtocolBase

func (pr *Protocol18) GetProtocolBase() *ProtocolBase

func (*Protocol18) Read

func (pr *Protocol18) Read(stream *StreamBuffer, gpType byte, flags constants.DeserializationFlags, parameters map[byte]interface{}) interface{}

func (*Protocol18) Read2

func (pr *Protocol18) Read2(stream *StreamBuffer, flags constants.DeserializationFlags, parameters map[byte]interface{}) interface{}

func (*Protocol18) ReadArrayInArray

func (pr *Protocol18) ReadArrayInArray(stream *StreamBuffer, flags constants.DeserializationFlags, parameters map[byte]interface{}) []interface{}

func (*Protocol18) ReadBoolean

func (pr *Protocol18) ReadBoolean(stream *StreamBuffer) bool

func (*Protocol18) ReadBooleanArray

func (pr *Protocol18) ReadBooleanArray(stream *StreamBuffer) []bool

func (*Protocol18) ReadByte

func (pr *Protocol18) ReadByte(stream *StreamBuffer) byte

func (*Protocol18) ReadByteArray

func (pr *Protocol18) ReadByteArray(stream *StreamBuffer) []byte

func (*Protocol18) ReadCompressedInt32

func (pr *Protocol18) ReadCompressedInt32(stream *StreamBuffer) uint

func (*Protocol18) ReadCompressedInt32Array

func (pr *Protocol18) ReadCompressedInt32Array(stream *StreamBuffer) []int

func (*Protocol18) ReadCompressedInt64

func (pr *Protocol18) ReadCompressedInt64(stream *StreamBuffer) int64

func (*Protocol18) ReadCompressedInt64Array

func (pr *Protocol18) ReadCompressedInt64Array(stream *StreamBuffer) []int64

func (*Protocol18) ReadCompressedUInt32

func (pr *Protocol18) ReadCompressedUInt32(stream *StreamBuffer) uint

func (*Protocol18) ReadCompressedUInt64

func (pr *Protocol18) ReadCompressedUInt64(stream *StreamBuffer) uint64

func (*Protocol18) ReadCustomType

func (pr *Protocol18) ReadCustomType(stream *StreamBuffer, gpType byte) interface{}

func (*Protocol18) ReadCustomTypeArray

func (pr *Protocol18) ReadCustomTypeArray(stream *StreamBuffer) interface{}

func (*Protocol18) ReadDictionary

func (pr *Protocol18) ReadDictionary(stream *StreamBuffer, flags constants.DeserializationFlags, parameters map[byte]interface{}) map[interface{}]interface{}

func (*Protocol18) ReadDictionaryArray

func (pr *Protocol18) ReadDictionaryArray(stream *StreamBuffer, flags constants.DeserializationFlags, parameters map[byte]interface{}) []map[interface{}]interface{}

func (*Protocol18) ReadDictionaryElements

func (pr *Protocol18) ReadDictionaryElements(stream *StreamBuffer, keyReadType constants.GpType18, valueReadType constants.GpType18, dictionary map[interface{}]interface{}, flags constants.DeserializationFlags, parameters map[byte]interface{}) map[interface{}]interface{}

func (*Protocol18) ReadDictionaryType

func (pr *Protocol18) ReadDictionaryType(stream *StreamBuffer, keyType *constants.GpType18, valueType *constants.GpType18) (reflect.Kind, reflect.Kind)

func (*Protocol18) ReadDictionaryType2

func (pr *Protocol18) ReadDictionaryType2(stream *StreamBuffer) reflect.Kind

func (*Protocol18) ReadDouble

func (pr *Protocol18) ReadDouble(stream *StreamBuffer) float64

func (*Protocol18) ReadDoubleArray

func (pr *Protocol18) ReadDoubleArray(stream *StreamBuffer) []float64

func (*Protocol18) ReadHashTable

func (pr *Protocol18) ReadHashTable(stream *StreamBuffer, flags constants.DeserializationFlags, parameters map[byte]interface{}) map[interface{}]interface{}

func (*Protocol18) ReadHashtableArray

func (pr *Protocol18) ReadHashtableArray(stream *StreamBuffer, flags constants.DeserializationFlags, parameters map[byte]interface{}) []map[interface{}]interface{}

func (*Protocol18) ReadInt1

func (pr *Protocol18) ReadInt1(stream *StreamBuffer, signNegative bool) int

func (*Protocol18) ReadInt16

func (pr *Protocol18) ReadInt16(stream *StreamBuffer) int16

func (*Protocol18) ReadInt16Array

func (pr *Protocol18) ReadInt16Array(stream *StreamBuffer) []int16

func (*Protocol18) ReadInt2

func (pr *Protocol18) ReadInt2(stream *StreamBuffer, signNegative bool) int

func (*Protocol18) ReadNonAllocByteArray

func (pr *Protocol18) ReadNonAllocByteArray(stream *StreamBuffer) *ByteArraySlice

func (*Protocol18) ReadObjectArray

func (pr *Protocol18) ReadObjectArray(stream *StreamBuffer, flags constants.DeserializationFlags, parameters map[byte]interface{}) []interface{}

func (*Protocol18) ReadParameterDictionary

func (pr *Protocol18) ReadParameterDictionary(stream *StreamBuffer, params map[byte]interface{}, flags constants.DeserializationFlags) map[byte]interface{}

func (*Protocol18) ReadSingle

func (pr *Protocol18) ReadSingle(stream *StreamBuffer) float32

func (*Protocol18) ReadSingleArray

func (pr *Protocol18) ReadSingleArray(stream *StreamBuffer) []float32

func (*Protocol18) ReadString

func (pr *Protocol18) ReadString(stream *StreamBuffer) string

func (*Protocol18) ReadStringArray

func (pr *Protocol18) ReadStringArray(stream *StreamBuffer) []string

func (*Protocol18) ReadUShort

func (pr *Protocol18) ReadUShort(stream *StreamBuffer) uint16

func (*Protocol18) Serialize

func (pr *Protocol18) Serialize(dout *StreamBuffer, obj interface{}, setType bool)

func (*Protocol18) SerializeEventData

func (pr *Protocol18) SerializeEventData(stream *StreamBuffer, value *EventData, setType bool)

func (*Protocol18) SerializeOperationRequest

func (pr *Protocol18) SerializeOperationRequest(stream *StreamBuffer, operationCode byte, parameters map[byte]interface{}, setType bool)

func (*Protocol18) SerializeOperationResponse

func (pr *Protocol18) SerializeOperationResponse(stream *StreamBuffer, value *OperationResponse, setType bool)

func (*Protocol18) SerializeShort

func (pr *Protocol18) SerializeShort(dout *StreamBuffer, value int16, setType bool)

func (*Protocol18) SerializeString

func (pr *Protocol18) SerializeString(stream *StreamBuffer, value string, setType bool)

func (*Protocol18) Write

func (pr *Protocol18) Write(stream *StreamBuffer, value interface{}, gpType constants.GpType18, writeType bool)

func (*Protocol18) Write1

func (pr *Protocol18) Write1(stream *StreamBuffer, obj interface{}, setType bool)

func (*Protocol18) WriteArrayHeader

func (pr *Protocol18) WriteArrayHeader(stream *StreamBuffer, typee reflect.Type) bool

func (*Protocol18) WriteArrayInArray

func (pr *Protocol18) WriteArrayInArray(stream *StreamBuffer, value interface{}, writeType bool)

func (*Protocol18) WriteArrayType

func (pr *Protocol18) WriteArrayType(stream *StreamBuffer, typee reflect.Type, writeType *constants.GpType18) bool

func (*Protocol18) WriteBoolean

func (pr *Protocol18) WriteBoolean(stream *StreamBuffer, value bool, writeType bool)

func (*Protocol18) WriteByte

func (pr *Protocol18) WriteByte(stream *StreamBuffer, value byte, writeType bool)

func (*Protocol18) WriteByteArray

func (pr *Protocol18) WriteByteArray(stream *StreamBuffer, value []byte, writeType bool)

func (*Protocol18) WriteByteArraySlice

func (pr *Protocol18) WriteByteArraySlice(stream *StreamBuffer, buffer *ByteArraySlice, writeType bool)

func (*Protocol18) WriteCompressedInt32

func (pr *Protocol18) WriteCompressedInt32(stream *StreamBuffer, value int, writeType bool)

func (*Protocol18) WriteCompressedInt64

func (pr *Protocol18) WriteCompressedInt64(stream *StreamBuffer, value int64, writeType bool)

func (*Protocol18) WriteCompressedUInt32

func (pr *Protocol18) WriteCompressedUInt32(stream *StreamBuffer, value uint32)

func (*Protocol18) WriteCompressedUInt32Buffer

func (pr *Protocol18) WriteCompressedUInt32Buffer(buffer []byte, value uint32) int

func (*Protocol18) WriteCompressedUInt64

func (pr *Protocol18) WriteCompressedUInt64(stream *StreamBuffer, value uint64)

func (*Protocol18) WriteCustomType

func (pr *Protocol18) WriteCustomType(stream *StreamBuffer, value interface{}, writeType bool)

func (*Protocol18) WriteCustomTypeBody

func (pr *Protocol18) WriteCustomTypeBody(customType *CustomType, stream *StreamBuffer, value interface{})

func (*Protocol18) WriteDictionary

func (pr *Protocol18) WriteDictionary(stream *StreamBuffer, dict interface{}, setType bool)

func (*Protocol18) WriteDictionaryElements

func (pr *Protocol18) WriteDictionaryElements(stream *StreamBuffer, dictionary map[interface{}]interface{}, keyWriteType constants.GpType18, valueWriteType constants.GpType18)

func (*Protocol18) WriteDictionaryHeader

func (pr *Protocol18) WriteDictionaryHeader(stream *StreamBuffer, dict map[interface{}]interface{}, keyWriteType *constants.GpType18, valueWriteType *constants.GpType18)

func (*Protocol18) WriteDouble

func (pr *Protocol18) WriteDouble(stream *StreamBuffer, value float64, writeType bool)

func (*Protocol18) WriteHashTable

func (pr *Protocol18) WriteHashTable(stream *StreamBuffer, value interface{}, writeType bool)

func (*Protocol18) WriteInt16

func (pr *Protocol18) WriteInt16(stream *StreamBuffer, value int16, writeType bool)

func (*Protocol18) WriteInt32ArrayCompressed

func (pr *Protocol18) WriteInt32ArrayCompressed(stream *StreamBuffer, value []int, writeType bool)

func (*Protocol18) WriteIntLength

func (pr *Protocol18) WriteIntLength(stream *StreamBuffer, value int)

func (*Protocol18) WriteParameterTable

func (pr *Protocol18) WriteParameterTable(stream *StreamBuffer, parameters map[byte]interface{})

func (*Protocol18) WriteSingle

func (pr *Protocol18) WriteSingle(stream *StreamBuffer, value float32, writeType bool)

func (*Protocol18) WriteString

func (pr *Protocol18) WriteString(stream *StreamBuffer, value string, writeType bool)

func (*Protocol18) WriteStringArray

func (pr *Protocol18) WriteStringArray(stream *StreamBuffer, value []string, writeType bool)

func (*Protocol18) WriteUShort

func (pr *Protocol18) WriteUShort(stream *StreamBuffer, value uint16)

type ProtocolBase

type ProtocolBase struct {
	ProtocolType string
	VersionBytes []byte
	// contains filtered or unexported fields
}

func (*ProtocolBase) Deserialize

func (base *ProtocolBase) Deserialize(serializedData []byte) interface{}

func (*ProtocolBase) DeserializeMessage

func (base *ProtocolBase) DeserializeMessage(stream *StreamBuffer) interface{}

func (*ProtocolBase) Serialize

func (base *ProtocolBase) Serialize(obj interface{}) []byte

func (*ProtocolBase) SerializeMessage

func (base *ProtocolBase) SerializeMessage(ms *StreamBuffer, msg interface{})

type Stack

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

func New

func New() *Stack

New Creates a new stack

func (*Stack) Len

func (s *Stack) Len() int

Len Returns the number of items in the stack

func (*Stack) Peek

func (s *Stack) Peek() interface{}

Peek Views the top item on the stack

func (*Stack) Pop

func (s *Stack) Pop() interface{}

Pop the top item of the stack and return it

func (*Stack) Push

func (s *Stack) Push(value interface{})

Push a value onto the top of the stack

type StreamBuffer

type StreamBuffer struct {
	sync.RWMutex
	DefaultInitialSize int
	Pos                int
	Len                int
	Buf                []byte
}

func NewStreamBufferFromBuffer

func NewStreamBufferFromBuffer(buf []byte) *StreamBuffer

func NewStreamBufferFromSize

func NewStreamBufferFromSize(size int) *StreamBuffer

func (*StreamBuffer) CheckSize

func (sb *StreamBuffer) CheckSize(size int) bool

func (*StreamBuffer) Compact

func (sb *StreamBuffer) Compact()

func (*StreamBuffer) GetBufferAndAdvance

func (sb *StreamBuffer) GetBufferAndAdvance(length int, offset int) ([]byte, int)

func (*StreamBuffer) IsAvailable

func (sb *StreamBuffer) IsAvailable() int

func (*StreamBuffer) Read

func (sb *StreamBuffer) Read(buffer []byte, dstOffset int, count int) (int, []byte)

func (*StreamBuffer) ReadByte

func (sb *StreamBuffer) ReadByte() (byte, error)

func (*StreamBuffer) Seek

func (sb *StreamBuffer) Seek(offset int64, origin constants.SeekOrigin) (int64, error)

func (*StreamBuffer) SetCapacityMinimum

func (sb *StreamBuffer) SetCapacityMinimum(neededSize int)

func (*StreamBuffer) SetLength

func (sb *StreamBuffer) SetLength(length int64)

func (*StreamBuffer) SetPos

func (sb *StreamBuffer) SetPos(pos int)

func (*StreamBuffer) ToArray

func (sb *StreamBuffer) ToArray() []byte

func (*StreamBuffer) ToArrayFromPos

func (sb *StreamBuffer) ToArrayFromPos() []byte

func (*StreamBuffer) Write

func (sb *StreamBuffer) Write(buffer []byte, srcOffset int, count int)

func (*StreamBuffer) WriteByte

func (sb *StreamBuffer) WriteByte(value byte)

func (*StreamBuffer) WriteBytes

func (sb *StreamBuffer) WriteBytes(v0 byte, v1 byte)

type UnknownType

type UnknownType struct {
	Data     []byte
	Size     int
	TypeCode byte
}

func NewUnknownType

func NewUnknownType(size int, typeCode byte) *UnknownType

Jump to

Keyboard shortcuts

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