Haxe Serialization Format
You can find a complete implementation of the serializer in haxe/std/haxe/Serializer.hx and for the unserializer in haxe/std/haxe/Unserializer.hx
Each value is prefixed with a single char, followed by some extra data depending on the value :
null:n- Int :
zfor zero, orifollowed by the integer itself (ex :i465) - Float :
kforNaNmfor-Infandpfor+Infdfollowed by the float display (ex :d1.45e-8)
- Bool :
tfortruefforfalse
- String :
yfollowed by the url encoded string length, then:and the url encoded string
example :y10:hi%20therefor"hi there".
each String is then stored into a cache with a string number (starting from 0).
When we encounter a String that has already been serialized, we can store insteadR456where 456 is the index of this string in the cache. The string cache is always enabled, it is distinct from the object cache. - Structure :
ofollowed by a list of fields and ending withg
The list of fields consists in pairs of key (field name) / value, the key being stored as aString.
example :oy1:xi2y1:kngfor{ x : 2, k : null } List:lfollowed by the list of serialized items, and ending with ah(ex :lnnhfor a List containing two nulls)Array:afollowed by serialized items, and ending with ah
if there are several consecutive nulls, we can storeu5instead ofnnnnn
example :ai1i2u4i7ni9hfor[1,2,null,null,null,null,7,null,9]Date:vfollowed by the date itself (ex :d2010-01-01 12:45:10)Hash:bfollowed by the keys / values pairs and ending byh
example :by1:xi2y1:knhfor{ "x" => 2, "k" => null }IntHash:qfollowed by the keys/values pairs and ending byh. Each key is stored as:<int>.
example :q:4n:5i45:6i7hfor{ 4 => null, 5 => 45, 6 => 7 }haxe.io.Bytes:sfollowed by the length of base64 encoded bytes, then:and the bytes encoded in base64 using the codesA-Za-z0-9%:
example :s3:AAAfor 2 bytes equal to 0
other example :s10:SGVsbG8gIQforhaxe.io.Bytes.ofString("Hello !")- Exception :
xfollowed by the exception value - Class instance :
cfollowed by the class name (serialized asString) followed by a list of fields (see Structure) and ending byg
example :cy5:Pointy1:xzy1:yzgfornew Point(0,0)(having two integer fieldsxandy) - Enum (by name) :
wfollowed by the enum name, the constructor name (as String), the number of arguments and the arguments itself
example :wy3:Fooy1:A0forFoo.A(with no arguments)
example :wy3:Fooy1:B2i4nforFoo.B(4,null) - Enum (by index) : same as by name but using
jinstead ofwfor prefix, and<int>:instead of the constructor name :
example :wy3:Foo0:0forFoo.A(with no arguments)
example :wy3:Foo1:2i4nforFoo.B(4,null) - Custom :
Cfollowed by the class name, followed by custom serialized data, and ending withg
example :Cy18:MyCustomSerializerzzgfor example in serialization documentation. - Cached references : when object cache is enable, each object, class instance and enum instance (except String) is stored into a cache before serializing its content, and is assigned an unique index starting from 0. When an object which is already in the cache is serialized, we instead store
r<int>where<int>is the index into the cache.
version #15752, modified 2012-12-02 10:14:05 by ppelleti