writeValue method
- WriteBuffer buffer,
- Object? value
Writes value to buffer by first writing a type discriminator
byte, then the value itself.
This method may be called recursively to serialize container values.
Type discriminators 0 through 127 inclusive are reserved for use by the base class, as follows:
- null = 0
- true = 1
- false = 2
- 32 bit integer = 3
- 64 bit integer = 4
- larger integers = 5 (see below)
- 64 bit floating-point number = 6
- String = 7
- Uint8List = 8
- Int32List = 9
- Int64List = 10
- Float64List = 11
- List = 12
- Map = 13
- Float32List = 14
- Reserved for future expansion: 15..127
The codec can be extended by overriding this method, calling super for values that the extension does not handle. Type discriminators used by extensions must be greater than or equal to 128 in order to avoid clashes with any later extensions to the base class.
The "larger integers" type, 5, is never used by writeValue. A subclass
could represent big integers from another package using that type. The
format is first the type byte (0x05), then the actual number as an ASCII
string giving the hexadecimal representation of the integer, with the
string's length as encoded by writeSize followed by the string bytes. On
Android, that would get converted to a java.math.BigInteger object. On
iOS, the string representation is returned.
Implementation
@override
void writeValue(WriteBuffer buffer, Object? value) {
if (value is int) {
buffer.putUint8(4);
buffer.putInt64(value);
} else if (value is OrnamentPosition) {
buffer.putUint8(129);
writeValue(buffer, value.index);
} else if (value is ScrollMode) {
buffer.putUint8(130);
writeValue(buffer, value.index);
} else if (value is PuckBearing) {
buffer.putUint8(131);
writeValue(buffer, value.index);
} else if (value is ModelScaleMode) {
buffer.putUint8(132);
writeValue(buffer, value.index);
} else if (value is ModelElevationReference) {
buffer.putUint8(133);
writeValue(buffer, value.index);
} else if (value is DistanceUnits) {
buffer.putUint8(134);
writeValue(buffer, value.index);
} else if (value is ScreenCoordinate) {
buffer.putUint8(135);
writeValue(buffer, value.encode());
} else if (value is GesturesSettings) {
buffer.putUint8(136);
writeValue(buffer, value.encode());
} else if (value is LocationPuck2D) {
buffer.putUint8(137);
writeValue(buffer, value.encode());
} else if (value is LocationPuck3D) {
buffer.putUint8(138);
writeValue(buffer, value.encode());
} else if (value is LocationPuck) {
buffer.putUint8(139);
writeValue(buffer, value.encode());
} else if (value is LocationComponentSettings) {
buffer.putUint8(140);
writeValue(buffer, value.encode());
} else if (value is ScaleBarSettings) {
buffer.putUint8(141);
writeValue(buffer, value.encode());
} else if (value is CompassSettings) {
buffer.putUint8(142);
writeValue(buffer, value.encode());
} else if (value is AttributionSettings) {
buffer.putUint8(143);
writeValue(buffer, value.encode());
} else if (value is LogoSettings) {
buffer.putUint8(144);
writeValue(buffer, value.encode());
} else if (value is IndoorSelectorSettings) {
buffer.putUint8(145);
writeValue(buffer, value.encode());
} else {
super.writeValue(buffer, value);
}
}