data encoding - SkycoinWikis/CXO GitHub Wiki
HOME » CX » CXO » DATA ENCODING
TODO update link when Skycoin/wiki is finished
Data Encoding
Encoding using the Skycoin Binary Encoding Format
Data
Int, Uint
All signed and unsigned integers encoded using little-endian order to bytes slice with appropriate size
- int8, uint8 - one byte
- int16, uint16 - 2 byte
- int32, uint32 - 4 byte
- int64, uint64 - 8 byte
That is obvious.
See LittleEndian and
ByteOrder of encoding/binary
Float32, Float64
For float point number used IEEE 754 binary representation.
Short words: float
-> uint
-> bytes (little-endian)
- float32 - 4 byte
- float64 - 8 byte
See math.Float32bits
,
math.Float32frombits
and
math.Float64bits
,
math.Float64frombits
methods
String
Strings are length-prefixed, where length is represented as encoded uint32
[4 byte length][string body, or nothing if the length is zero]
Arrays
Arrays is just encoded elements one by one
Slices
Slices are length-prefixed like strings
[4 byte length][elements one by one, or nothing if the length is zero]
Structures
Structures is encoded elements from first field to last
For example
type Age uint32
type User strut {
Age Age
Name string
}
should be encoded to
[4 byte of the Age]
[4 byte of the Name length][the Name in person]
That's all about data