|
@@ -44,33 +44,33 @@ import haxe.ds.List;
|
|
**/
|
|
**/
|
|
class Serializer {
|
|
class Serializer {
|
|
/**
|
|
/**
|
|
- Enables object caching during serialization to handle circular references and
|
|
|
|
|
|
+ Enables object caching during serialization to handle circular references and
|
|
repeated objects.
|
|
repeated objects.
|
|
-
|
|
|
|
- Set `USE_CACHE` to `true` if the values you are serializing may contain
|
|
|
|
- circular references or repeated objects. This prevents infinite loops and
|
|
|
|
|
|
+
|
|
|
|
+ Set `USE_CACHE` to `true` if the values you are serializing may contain
|
|
|
|
+ circular references or repeated objects. This prevents infinite loops and
|
|
ensures that shared references are preserved in the serialized output.
|
|
ensures that shared references are preserved in the serialized output.
|
|
-
|
|
|
|
- Enabling this option may also reduce the size of the resulting serialized
|
|
|
|
|
|
+
|
|
|
|
+ Enabling this option may also reduce the size of the resulting serialized
|
|
string, but can have a minor performance impact.
|
|
string, but can have a minor performance impact.
|
|
-
|
|
|
|
- This is a global default. You can override it per instance using the
|
|
|
|
|
|
+
|
|
|
|
+ This is a global default. You can override it per instance using the
|
|
`useCache` field on a `Serializer`.
|
|
`useCache` field on a `Serializer`.
|
|
*/
|
|
*/
|
|
public static var USE_CACHE = false;
|
|
public static var USE_CACHE = false;
|
|
|
|
|
|
/**
|
|
/**
|
|
Serializes enum values using constructor indices instead of names.
|
|
Serializes enum values using constructor indices instead of names.
|
|
-
|
|
|
|
- When `USE_ENUM_INDEX` is set to `true`, enum constructors are serialized by
|
|
|
|
- their numeric index. This can reduce the size of the serialized data,
|
|
|
|
|
|
+
|
|
|
|
+ When `USE_ENUM_INDEX` is set to `true`, enum constructors are serialized by
|
|
|
|
+ their numeric index. This can reduce the size of the serialized data,
|
|
especially for enums with long or frequently used constructor names.
|
|
especially for enums with long or frequently used constructor names.
|
|
-
|
|
|
|
- However, using indices makes serialized data more fragile for long-term
|
|
|
|
- storage. If enum definitions change (e.g., by adding or removing constructors),
|
|
|
|
|
|
+
|
|
|
|
+ However, using indices makes serialized data more fragile for long-term
|
|
|
|
+ storage. If enum definitions change (e.g., by adding or removing constructors),
|
|
the indices may no longer match the intended constructors.
|
|
the indices may no longer match the intended constructors.
|
|
-
|
|
|
|
- This is a global default. You can override it per instance using the
|
|
|
|
|
|
+
|
|
|
|
+ This is a global default. You can override it per instance using the
|
|
`useEnumIndex` field on a `Serializer`.
|
|
`useEnumIndex` field on a `Serializer`.
|
|
*/
|
|
*/
|
|
public static var USE_ENUM_INDEX = false;
|
|
public static var USE_ENUM_INDEX = false;
|
|
@@ -84,20 +84,20 @@ class Serializer {
|
|
var scount:Int;
|
|
var scount:Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
- Determines whether this `Serializer` instance uses object caching.
|
|
|
|
-
|
|
|
|
- When enabled, repeated references to the same object are serialized using references
|
|
|
|
- instead of duplicating data, reducing output size and preserving object identity.
|
|
|
|
-
|
|
|
|
- See `USE_CACHE` for a complete description.
|
|
|
|
- */
|
|
|
|
|
|
+ Determines whether this `Serializer` instance uses object caching.
|
|
|
|
+
|
|
|
|
+ When enabled, repeated references to the same object are serialized using references
|
|
|
|
+ instead of duplicating data, reducing output size and preserving object identity.
|
|
|
|
+
|
|
|
|
+ See `USE_CACHE` for a complete description.
|
|
|
|
+ */
|
|
public var useCache:Bool;
|
|
public var useCache:Bool;
|
|
|
|
|
|
/**
|
|
/**
|
|
Determines whether this `Serializer` instance serializes enum values using their index
|
|
Determines whether this `Serializer` instance serializes enum values using their index
|
|
instead of their constructor name.
|
|
instead of their constructor name.
|
|
|
|
|
|
- Using indexes can reduce the size of the serialized data but may be less readable and
|
|
|
|
|
|
+ Using indexes can reduce the size of the serialized data but may be less readable and
|
|
more fragile if enum definitions change.
|
|
more fragile if enum definitions change.
|
|
|
|
|
|
See `USE_ENUM_INDEX` for a complete description.
|
|
See `USE_ENUM_INDEX` for a complete description.
|
|
@@ -125,12 +125,12 @@ class Serializer {
|
|
|
|
|
|
/**
|
|
/**
|
|
Resets the internal state of the Serializer, allowing it to be reused.
|
|
Resets the internal state of the Serializer, allowing it to be reused.
|
|
-
|
|
|
|
|
|
+
|
|
This does not affect the `useCache` or `useEnumIndex` properties;
|
|
This does not affect the `useCache` or `useEnumIndex` properties;
|
|
their values will remain unchanged after calling this method.
|
|
their values will remain unchanged after calling this method.
|
|
**/
|
|
**/
|
|
public function reset() {
|
|
public function reset() {
|
|
- buf = new StringBuf();
|
|
|
|
|
|
+ buf.clear();
|
|
cache.resize(0);
|
|
cache.resize(0);
|
|
shash.clear();
|
|
shash.clear();
|
|
scount = 0;
|
|
scount = 0;
|