Unserializer

haxe.Unserializer (Class)

The Unserializer class is the complement to the Serializer class. It parses a serialization String and creates objects from the contained data.

This class can be used in two ways:

  • create a new Unserializer() instance with a given serialization String, then call its unserialize() method until all values are extracted
  • call Unserializer.run() to unserialize a single value from a given String

The specification of the serialization format can be found here: https://haxe.org/manual/serialization/format

Static Members

DEFAULT_RESOLVER: TypeResolver

This value can be set to use custom type resolvers.

A type resolver finds a Class or Enum instance from a given String. By default, the Haxe Type Api is used.

A type resolver must provide two methods:

  1. resolveClass(name:String):Class<Dynamic> is called to determine a Class from a class name
  2. resolveEnum(name:String):Enum<Dynamic> is called to determine an Enum from an enum name

This value is applied when a new Unserializer instance is created. Changing it afterwards has no effect on previously created instances.

Instance Members

unserialize(): Dynamic

Unserializes the next part of this Unserializer instance and returns the according value.

This function may call this.resolver.resolveClass to determine a Class from a String, and this.resolver.resolveEnum to determine an Enum from a String.

If this Unserializer instance contains no more or invalid data, an exception is thrown.

This operation may fail on structurally valid data if a type cannot be resolved or if a field cannot be set. This can happen when unserializing Strings that were serialized on a different Haxe target, in which the serialization side has to make sure not to include platform-specific data.

Classes are created from Type.createEmptyInstance, which means their constructors are not called.

Returns
Dynamic

new(buf: String): Void

Creates a new Unserializer instance, with its internal buffer initialized to buf.

This does not parse buf immediately. It is parsed only when calls to this.unserialize are made.

Each Unserializer instance maintains its own cache.

Name Type
buf String

Private Members

BASE64: String

CODES: Null<Array<Int>>

buf: String

pos: Int

length: Int

cache: Array<Dynamic>

scache: Array<String>

resolver: TypeResolver

initCodes(): Array<Int>
Returns
Array<Int>

fastLength(s: String): Int
Name Type
s String
Returns
Int

fastCharAt(s: String, pos: Int): String
Name Type
s String
pos Int
Returns
String

fastSubstr(s: String, pos: Int, length: Int): String
Name Type
s String
pos Int
length Int
Returns
String

get(p: Int): Int
Name Type
p Int
Returns
Int

readDigits(): Int
Returns
Int

readFloat(): Float
Returns
Float

unserializeObject(o: AnonStruct): Void
Name Type
o AnonStruct

unserializeEnum(edecl: Enum<unserializeEnum.T>, tag: String): unserializeEnum.T
Name Type
edecl Enum<unserializeEnum.T>
tag String
Returns
unserializeEnum.T