Documentation ¶
Index ¶
- Constants
- func CreateTimeFromUnixMicro(usec int64) time.Time
- func Float32bits(f float32) uint32
- func Float32frombits(b uint32) float32
- func Float64bits(f float64) uint64
- func Float64frombits(b uint64) float64
- func GetUnixMicro(t time.Time) int64
- func Marshal(v interface{}) ([]byte, error)
- func PutFury(fury *Fury)
- func SnakeCase(camel string) string
- func Unmarshal(data []byte, v interface{}) error
- type BufferCallback
- type BufferObject
- type ByteBuffer
- func (b *ByteBuffer) GetByteSlice(start, end int) []byte
- func (b *ByteBuffer) GetData() []byte
- func (b *ByteBuffer) PutInt32(index int, value int32)
- func (b *ByteBuffer) Read(p []byte) (n int, err error)
- func (b *ByteBuffer) ReadBinary(length int) []byte
- func (b *ByteBuffer) ReadBool() bool
- func (b *ByteBuffer) ReadByte() (byte, error)
- func (b *ByteBuffer) ReadByte_() byte
- func (b *ByteBuffer) ReadFloat32() float32
- func (b *ByteBuffer) ReadFloat64() float64
- func (b *ByteBuffer) ReadInt16() int16
- func (b *ByteBuffer) ReadInt32() int32
- func (b *ByteBuffer) ReadInt64() int64
- func (b *ByteBuffer) ReadInt8() int8
- func (b *ByteBuffer) ReadLength() int
- func (b *ByteBuffer) ReadUint32() uint32
- func (b *ByteBuffer) ReadUint64() uint64
- func (b *ByteBuffer) ReadVarInt32() int32
- func (b *ByteBuffer) ReaderIndex() int
- func (b *ByteBuffer) Reset()
- func (b *ByteBuffer) SetReaderIndex(index int)
- func (b *ByteBuffer) SetWriterIndex(index int)
- func (b *ByteBuffer) Slice(start, length int) *ByteBuffer
- func (b *ByteBuffer) Write(p []byte) (n int, err error)
- func (b *ByteBuffer) WriteBinary(p []byte)
- func (b *ByteBuffer) WriteBool(value bool)
- func (b *ByteBuffer) WriteByte(value byte) error
- func (b *ByteBuffer) WriteByte_(value byte)
- func (b *ByteBuffer) WriteFloat32(value float32)
- func (b *ByteBuffer) WriteFloat64(value float64)
- func (b *ByteBuffer) WriteInt16(value int16)
- func (b *ByteBuffer) WriteInt32(value int32)
- func (b *ByteBuffer) WriteInt64(value int64)
- func (b *ByteBuffer) WriteInt8(value int8)
- func (b *ByteBuffer) WriteLength(value int)
- func (b *ByteBuffer) WriteVarInt32(value int32) int8
- func (b *ByteBuffer) WriterIndex() int
- type ByteSliceBufferObject
- type Date
- type Float32Slice
- type Float64Slice
- type Fury
- func (f *Fury) Deserialize(buf *ByteBuffer, v interface{}, buffers []*ByteBuffer) error
- func (f *Fury) Marshal(v interface{}) ([]byte, error)
- func (f *Fury) ReadBufferObject(buffer *ByteBuffer) (*ByteBuffer, error)
- func (f *Fury) ReadReferencable(buffer *ByteBuffer, value reflect.Value) error
- func (f *Fury) RegisterTagType(tag string, v interface{}) error
- func (f *Fury) Reset()
- func (f *Fury) Serialize(buf *ByteBuffer, v interface{}, callback BufferCallback) error
- func (f *Fury) SetLanguage(language Language)
- func (f *Fury) SetReferenceTracking(referenceTracking bool)
- func (f *Fury) Unmarshal(data []byte, v interface{}) error
- func (f *Fury) Write(buffer *ByteBuffer, v interface{}) (err error)
- func (f *Fury) WriteBufferObject(buffer *ByteBuffer, bufferObject BufferObject) error
- func (f *Fury) WriteByte_(buffer *ByteBuffer, v interface{})
- func (f *Fury) WriteFloat32(buffer *ByteBuffer, v interface{})
- func (f *Fury) WriteFloat64(buffer *ByteBuffer, v interface{})
- func (f *Fury) WriteInt16(buffer *ByteBuffer, v interface{})
- func (f *Fury) WriteInt32(buffer *ByteBuffer, v interface{})
- func (f *Fury) WriteInt64(buffer *ByteBuffer, v interface{})
- func (f *Fury) WriteReferencable(buffer *ByteBuffer, value reflect.Value) error
- type GenericSet
- type Int16Slice
- type Int32Slice
- type Int64Slice
- type Int8Slice
- type Language
- type Marshaller
- type RefResolver
- func (r *RefResolver) GetCurrentReadObject() reflect.Value
- func (r *RefResolver) GetReadObject(refId int32) reflect.Value
- func (r *RefResolver) PreserveRefId() (int32, error)
- func (r *RefResolver) ReadRefOrNull(buffer *ByteBuffer) int8
- func (r *RefResolver) Reference(value reflect.Value)
- func (r *RefResolver) SetReadObject(refId int32, value reflect.Value)
- func (r *RefResolver) TryPreserveRefId(buffer *ByteBuffer) (int32, error)
- func (r *RefResolver) WriteRefOrNull(buffer *ByteBuffer, value reflect.Value) (refWritten bool, err error)
- type Serializer
- type TypeId
Examples ¶
Constants ¶
const ( NullFlag int8 = -3 // RefFlag indicates that object is a not-null value. // We don't use another byte to indicate REF, so that we can save one byte. RefFlag int8 = -2 // NotNullValueFlag indicates that the object is a non-null value. NotNullValueFlag int8 = -1 // RefValueFlag indicates that the object is a referencable and first read. RefValueFlag int8 = 0 )
const ( // NA A NullFlag type having no physical storage NA TypeId = iota // NA = 0 // BOOL Boolean as 1 bit LSB bit-packed ordering BOOL // UINT8 Unsigned 8-bit little-endian integer UINT8 // INT8 Signed 8-bit little-endian integer INT8 // UINT16 Unsigned 16-bit little-endian integer UINT16 // INT16 Signed 16-bit little-endian integer INT16 // UINT32 Unsigned 32-bit little-endian integer UINT32 // INT32 Signed 32-bit little-endian integer INT32 // UINT64 Unsigned 64-bit little-endian integer UINT64 // INT64 Signed 64-bit little-endian integer INT64 // HALF_FLOAT 2-byte floating point value HALF_FLOAT // FLOAT 4-byte floating point value FLOAT // DOUBLE 8-byte floating point value DOUBLE // STRING UTF8 variable-length string as List<Char> STRING // BINARY Variable-length bytes (no guarantee of UTF8-ness) BINARY // FIXED_SIZE_BINARY Fixed-size binary. Each value occupies the same number of bytes FIXED_SIZE_BINARY // DATE32 int32_t days since the UNIX epoch DATE32 // DATE64 int64_t milliseconds since the UNIX epoch DATE64 // TIMESTAMP Exact timestamp encoded with int64 since UNIX epoch // Default unit millisecond TIMESTAMP // TIME32 Time as signed 32-bit integer representing either seconds or // milliseconds since midnight TIME32 // TIME64 Time as signed 64-bit integer representing either microseconds or // nanoseconds since midnight TIME64 // INTERVAL_MONTHS YEAR_MONTH interval in SQL style INTERVAL_MONTHS // INTERVAL_DAY_TIME DAY_TIME interval in SQL style INTERVAL_DAY_TIME // DECIMAL128 Precision- and scale-based decimal type with 128 bits. DECIMAL128 // DECIMAL256 Precision- and scale-based decimal type with 256 bits. DECIMAL256 // LIST A list of some logical data type LIST // STRUCT Struct of logical types STRUCT // SPARSE_UNION Sparse unions of logical types SPARSE_UNION // DENSE_UNION Dense unions of logical types DENSE_UNION // DICTIONARY Dictionary-encoded type also called "categorical" or "factor" // in other programming languages. Holds the dictionary value // type but not the dictionary itself which is part of the // ArrayData struct DICTIONARY // MAP Map a repeated struct logical type MAP // EXTENSION Custom data type implemented by user EXTENSION // FIXED_SIZE_LIST Fixed size list of some logical type FIXED_SIZE_LIST // DURATION Measure of elapsed time in either seconds milliseconds microseconds // or nanoseconds. DURATION // LARGE_STRING Like STRING but with 64-bit offsets LARGE_STRING // LARGE_BINARY Like BINARY but with 64-bit offsets LARGE_BINARY // LARGE_LIST Like LIST but with 64-bit offsets LARGE_LIST // MAX_ID Leave this at the end MAX_ID DECIMAL = DECIMAL128 // Fury added type for cross-language serialization. // FURY_TYPE_TAG for type idendified by the tag FURY_TYPE_TAG = 256 FURY_SET = 257 FURY_PRIMITIVE_BOOL_ARRAY = 258 FURY_PRIMITIVE_SHORT_ARRAY = 259 FURY_PRIMITIVE_INT_ARRAY = 260 FURY_PRIMITIVE_LONG_ARRAY = 261 FURY_PRIMITIVE_FLOAT_ARRAY = 262 FURY_PRIMITIVE_DOUBLE_ARRAY = 263 FURY_STRING_ARRAY = 264 FURY_SERIALIZED_OBJECT = 265 FURY_BUFFER = 266 FURY_ARROW_RECORD_BATCH = 267 FURY_ARROW_TABLE = 268 )
const ( MaxInt = 1<<(intSize-1) - 1 MinInt = -1 << (intSize - 1) MaxInt8 = 1<<7 - 1 MinInt8 = -1 << 7 MaxInt16 = 1<<15 - 1 MinInt16 = -1 << 15 MaxInt32 = 1<<31 - 1 MinInt32 = -1 << 31 MaxInt64 = 1<<63 - 1 MinInt64 = -1 << 63 MaxUint = 1<<intSize - 1 MaxUint8 = 1<<8 - 1 MaxUint16 = 1<<16 - 1 MaxUint32 = 1<<32 - 1 MaxUint64 = 1<<64 - 1 )
Integer limit values.
const (
NotSupportCrossLanguage = 0
)
Variables ¶
This section is empty.
Functions ¶
func CreateTimeFromUnixMicro ¶
CreateTimeFromUnixMicro returns the local Time corresponding to the given Unix time, usec microseconds since January 1, 1970 UTC.
func Float32bits ¶
Float32bits returns the IEEE 754 binary representation of f, with the sign bit of f and the result in the same bit position. Float32bits(Float32frombits(x)) == x.
func Float32frombits ¶
Float32frombits returns the floating-point number corresponding to the IEEE 754 binary representation b, with the sign bit of b and the result in the same bit position. Float32frombits(Float32bits(x)) == x.
func Float64bits ¶
Float64bits returns the IEEE 754 binary representation of f, with the sign bit of f and the result in the same bit position, and Float64bits(Float64frombits(x)) == x.
func Float64frombits ¶
Float64frombits returns the floating-point number corresponding to the IEEE 754 binary representation b, with the sign bit of b and the result in the same bit position. Float64frombits(Float64bits(x)) == x.
func GetUnixMicro ¶
GetUnixMicro returns t as a Unix time, the number of microseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in microseconds cannot be represented by an int64 (a date before year -290307 or after year 294246). The result does not depend on the location associated with t.
func Marshal ¶
Marshal returns the MessagePack encoding of v.
Example ¶
list := []interface{}{true, false, "str", -1.1, 1, make([]int32, 5), make([]float64, 5)} bytes, err := Marshal(list) if err != nil { panic(err) } var newValue interface{} // bytes can be data serialized by other languages. if err := Unmarshal(bytes, &newValue); err != nil { panic(err) } fmt.Println(newValue) dict := map[string]interface{}{ "k1": "v1", "k2": list, "k3": -1, } bytes, err = Marshal(dict) if err != nil { panic(err) } // bytes can be data serialized by other languages. if err := Unmarshal(bytes, &newValue); err != nil { panic(err) } fmt.Println(newValue)
Output: [true false str -1.1 1 [0 0 0 0 0] [0 0 0 0 0]] map[k1:v1 k2:[true false str -1.1 1 [0 0 0 0 0] [0 0 0 0 0]] k3:-1]
Types ¶
type BufferCallback ¶
type BufferCallback = func(o BufferObject) bool
BufferCallback to check whether write buffer in band. If the callback returns false, the given buffer is out-of-band; otherwise the buffer is serialized in-band, i.e. inside the serialized stream.
type BufferObject ¶
type BufferObject interface { TotalBytes() int WriteTo(buf *ByteBuffer) ToBuffer() *ByteBuffer }
type ByteBuffer ¶
func NewByteBuffer ¶
func NewByteBuffer(data []byte) *ByteBuffer
func (*ByteBuffer) GetByteSlice ¶
func (b *ByteBuffer) GetByteSlice(start, end int) []byte
func (*ByteBuffer) GetData ¶
func (b *ByteBuffer) GetData() []byte
func (*ByteBuffer) PutInt32 ¶
func (b *ByteBuffer) PutInt32(index int, value int32)
func (*ByteBuffer) ReadBinary ¶
func (b *ByteBuffer) ReadBinary(length int) []byte
func (*ByteBuffer) ReadBool ¶
func (b *ByteBuffer) ReadBool() bool
func (*ByteBuffer) ReadByte ¶
func (b *ByteBuffer) ReadByte() (byte, error)
func (*ByteBuffer) ReadByte_ ¶
func (b *ByteBuffer) ReadByte_() byte
func (*ByteBuffer) ReadFloat32 ¶
func (b *ByteBuffer) ReadFloat32() float32
func (*ByteBuffer) ReadFloat64 ¶
func (b *ByteBuffer) ReadFloat64() float64
func (*ByteBuffer) ReadInt16 ¶
func (b *ByteBuffer) ReadInt16() int16
func (*ByteBuffer) ReadInt32 ¶
func (b *ByteBuffer) ReadInt32() int32
func (*ByteBuffer) ReadInt64 ¶
func (b *ByteBuffer) ReadInt64() int64
func (*ByteBuffer) ReadInt8 ¶
func (b *ByteBuffer) ReadInt8() int8
func (*ByteBuffer) ReadLength ¶
func (b *ByteBuffer) ReadLength() int
func (*ByteBuffer) ReadUint32 ¶
func (b *ByteBuffer) ReadUint32() uint32
func (*ByteBuffer) ReadUint64 ¶
func (b *ByteBuffer) ReadUint64() uint64
func (*ByteBuffer) ReadVarInt32 ¶
func (b *ByteBuffer) ReadVarInt32() int32
ReadVarInt32 reads the 1-5 byte int part of a varint.
func (*ByteBuffer) ReaderIndex ¶
func (b *ByteBuffer) ReaderIndex() int
func (*ByteBuffer) Reset ¶
func (b *ByteBuffer) Reset()
func (*ByteBuffer) SetReaderIndex ¶
func (b *ByteBuffer) SetReaderIndex(index int)
func (*ByteBuffer) SetWriterIndex ¶
func (b *ByteBuffer) SetWriterIndex(index int)
func (*ByteBuffer) Slice ¶
func (b *ByteBuffer) Slice(start, length int) *ByteBuffer
func (*ByteBuffer) WriteBinary ¶
func (b *ByteBuffer) WriteBinary(p []byte)
func (*ByteBuffer) WriteBool ¶
func (b *ByteBuffer) WriteBool(value bool)
func (*ByteBuffer) WriteByte ¶
func (b *ByteBuffer) WriteByte(value byte) error
func (*ByteBuffer) WriteByte_ ¶
func (b *ByteBuffer) WriteByte_(value byte)
func (*ByteBuffer) WriteFloat32 ¶
func (b *ByteBuffer) WriteFloat32(value float32)
func (*ByteBuffer) WriteFloat64 ¶
func (b *ByteBuffer) WriteFloat64(value float64)
func (*ByteBuffer) WriteInt16 ¶
func (b *ByteBuffer) WriteInt16(value int16)
func (*ByteBuffer) WriteInt32 ¶
func (b *ByteBuffer) WriteInt32(value int32)
func (*ByteBuffer) WriteInt64 ¶
func (b *ByteBuffer) WriteInt64(value int64)
func (*ByteBuffer) WriteInt8 ¶
func (b *ByteBuffer) WriteInt8(value int8)
func (*ByteBuffer) WriteLength ¶
func (b *ByteBuffer) WriteLength(value int)
func (*ByteBuffer) WriteVarInt32 ¶
func (b *ByteBuffer) WriteVarInt32(value int32) int8
WriteVarInt32 WritePositiveVarInt writes a 1-9 byte int, returns the number of bytes written.
func (*ByteBuffer) WriterIndex ¶
func (b *ByteBuffer) WriterIndex() int
type ByteSliceBufferObject ¶
type ByteSliceBufferObject struct {
// contains filtered or unexported fields
}
func (*ByteSliceBufferObject) ToBuffer ¶
func (o *ByteSliceBufferObject) ToBuffer() *ByteBuffer
func (*ByteSliceBufferObject) TotalBytes ¶
func (o *ByteSliceBufferObject) TotalBytes() int
func (*ByteSliceBufferObject) WriteTo ¶
func (o *ByteSliceBufferObject) WriteTo(buf *ByteBuffer)
type Date ¶
type Date struct { Year int // Year. E.g., 2009. Month time.Month // Month is 1 - 12. 0 means unspecified. Day int }
Date represents an imprecise date.
type Float32Slice ¶
type Float32Slice []float64
type Float64Slice ¶
type Float64Slice []float64
type Fury ¶
type Fury struct {
// contains filtered or unexported fields
}
func (*Fury) Deserialize ¶
func (f *Fury) Deserialize(buf *ByteBuffer, v interface{}, buffers []*ByteBuffer) error
func (*Fury) ReadBufferObject ¶
func (f *Fury) ReadBufferObject(buffer *ByteBuffer) (*ByteBuffer, error)
func (*Fury) ReadReferencable ¶
func (f *Fury) ReadReferencable(buffer *ByteBuffer, value reflect.Value) error
func (*Fury) RegisterTagType ¶
func (*Fury) Serialize ¶
func (f *Fury) Serialize(buf *ByteBuffer, v interface{}, callback BufferCallback) error
func (*Fury) SetLanguage ¶
func (*Fury) SetReferenceTracking ¶
func (*Fury) Write ¶
func (f *Fury) Write(buffer *ByteBuffer, v interface{}) (err error)
func (*Fury) WriteBufferObject ¶
func (f *Fury) WriteBufferObject(buffer *ByteBuffer, bufferObject BufferObject) error
func (*Fury) WriteByte_ ¶
func (f *Fury) WriteByte_(buffer *ByteBuffer, v interface{})
func (*Fury) WriteFloat32 ¶
func (f *Fury) WriteFloat32(buffer *ByteBuffer, v interface{})
func (*Fury) WriteFloat64 ¶
func (f *Fury) WriteFloat64(buffer *ByteBuffer, v interface{})
func (*Fury) WriteInt16 ¶
func (f *Fury) WriteInt16(buffer *ByteBuffer, v interface{})
func (*Fury) WriteInt32 ¶
func (f *Fury) WriteInt32(buffer *ByteBuffer, v interface{})
func (*Fury) WriteInt64 ¶
func (f *Fury) WriteInt64(buffer *ByteBuffer, v interface{})
func (*Fury) WriteReferencable ¶
func (f *Fury) WriteReferencable(buffer *ByteBuffer, value reflect.Value) error
type GenericSet ¶
type GenericSet map[interface{}]bool
GenericSet type. TODO use golang generics; support more concrete key types
func (GenericSet) Add ¶
func (s GenericSet) Add(values ...interface{})
type Int16Slice ¶
type Int16Slice []int16
type Int32Slice ¶
type Int32Slice []int32
type Int64Slice ¶
type Int64Slice []int64
type Marshaller ¶
type Marshaller interface { ExtId() int16 MarshalFury(f *Fury, buf *ByteBuffer) error UnmarshalFury(f *Fury, buf *ByteBuffer) error }
type RefResolver ¶
type RefResolver struct {
// contains filtered or unexported fields
}
RefResolver class is used to track objects that have already been read or written.
func (*RefResolver) GetCurrentReadObject ¶
func (r *RefResolver) GetCurrentReadObject() reflect.Value
func (*RefResolver) GetReadObject ¶
func (r *RefResolver) GetReadObject(refId int32) reflect.Value
GetReadObject returns the object for the specified id.
func (*RefResolver) PreserveRefId ¶
func (r *RefResolver) PreserveRefId() (int32, error)
PreserveRefId preserve a ref id, which is used by Reference / SetReadObject to set up reference for object that is first deserialized. Returns a ref id or -1 if reference is not enabled.
func (*RefResolver) ReadRefOrNull ¶
func (r *RefResolver) ReadRefOrNull(buffer *ByteBuffer) int8
ReadRefOrNull returns RefFlag if a ref to a previously read object was read. Returns NullFlag if the object is null. Returns RefValueFlag if the object is not null and ref tracking is not enabled or the object is first read.
func (*RefResolver) Reference ¶
func (r *RefResolver) Reference(value reflect.Value)
Reference tracking references relationship. Call this method immediately after composited object such as object array/map/collection/bean is created so that circular reference can be deserialized correctly.
func (*RefResolver) SetReadObject ¶
func (r *RefResolver) SetReadObject(refId int32, value reflect.Value)
SetReadObject sets the id for an object that has been read. id: The id from {@link #NextReadRefId}. object: the object that has been read
func (*RefResolver) TryPreserveRefId ¶
func (r *RefResolver) TryPreserveRefId(buffer *ByteBuffer) (int32, error)
func (*RefResolver) WriteRefOrNull ¶
func (r *RefResolver) WriteRefOrNull(buffer *ByteBuffer, value reflect.Value) (refWritten bool, err error)
WriteRefOrNull write reference and tag for the value if the value has been written previously, write null/not-null tag otherwise. Returns true if no bytes need to be written for the object. See https://go101.org/article/value-part.html for internal structure definitions of common types. Note that for slice and substring, if the start addr or length are different, we take two objects as different references.