Serializer
The Serializer class can be used to encode values and objects into a String
,
from which the Unserializer
class can recreate the original representation.
This class can be used in two ways:
- create a
new Serializer()
instance, call itsserialize()
method with any argument and finally retrieve the String representation fromtoString()
- call
Serializer.run()
to obtain the serialized representation of a single argument
Serialization is guaranteed to work for all haxe-defined classes, but may or may not work for instances of external/native classes.
The specification of the serialization format can be found here: https://haxe.org/manual/std-serialization-format.html
Static Members
USE_CACHE: Bool
If the values you are serializing can contain circular references or
objects repetitions, you should set USE_CACHE
to true to prevent
infinite loops.
This may also reduce the size of serialization Strings at the expense of performance.
This value can be changed for individual instances of Serializer
by
setting their useCache
field.
USE_ENUM_INDEX: Bool
Use constructor indexes for enums instead of names.
This may reduce the size of serialization Strings, but makes them less suited for long-term storage: If constructors are removed or added from the enum, the indices may no longer match.
This value can be changed for individual instances of Serializer
by
setting their useEnumIndex
field.
Instance Members
useCache: Bool
The individual cache setting for this
Serializer instance.
See USE_CACHE
for a complete description.
useEnumIndex: Bool
The individual enum index setting for this
Serializer instance.
See USE_ENUM_INDEX
for a complete description.
toString(): String
Return the String representation of this
Serializer.
The exact format specification can be found here: https://haxe.org/manual/serialization/format
Returns |
---|
String |
Serializes v
.
All haxe-defined values and objects with the exception of functions can be serialized. Serialization of external/native objects is not guaranteed to work.
The values of this.useCache
and this.useEnumIndex
may affect
serialization output.
Name | Type |
---|---|
v |
Dynamic |
new(): Void
Creates a new Serializer instance.
Subsequent calls to this.serialize
will append values to the
internal buffer of this String. Once complete, the contents can be
retrieved through a call to this.toString
.
Each Serializer
instance maintains its own cache if this.useCache
is
true
.
Private Members
BASE64: String
BASE64_CODES: Null<haxe.ds.Vector<Null<Int>>>
buf: StringBuf
shash: haxe.ds.StringMap<Int>
scount: Int
Name | Type |
---|---|
s |
String |
Name | Type |
---|---|
v |
Dynamic |
Returns |
---|
Bool |
serializeFields(v: AnonStruct): Void
Name | Type |
---|---|
v |
AnonStruct |