Zyle Moore
04/19/2024, 6:30 AMPID=1.1
I made a serializable data class to represent this
@Serializable
data class Pid(
val first: Digits,
val second: Digits? = null,
)
If second
is absent, then the period and second number are not included.
Pid("1") == PID=1
Pid("1", "1") == PID=1.1
I'm making a hand-built custom serializer, but can't figure out how the descriptor aligns to the serialization and deserialization methods. Does second
become a substructure made up of separator value
".1"
Is it inline? Would it be elements[2]
of the base descriptor, or closer to elements[1][1]
?Adam S
04/19/2024, 7:22 AMAdam S
04/19/2024, 7:23 AMZyle Moore
04/19/2024, 11:17 PMPid
is Serializable. This is what the rest of the functional code is using. There's nothing special here except for with
specifying which serializer to use. The twist though, is that the properties from Pid
are never actually touched by the encoder.
The serializer, since it's hand built, is in control of what gets sent to the encoder. The first
and second
properties from Pid
are never passed as a parameter to any encodeX
method.
Instead, a new Serializable object, the PidDelegate
is created, whose value is the entire serialized output made up of the primitive; the whole formatted string, with the expected period and second string, in a single value.
Then it's just "serialize the `PidDelegate`", and since it's just a value class for a String, what gets sent to the encoder is the plain, full, singular string value.
Did I get that right?Adam S
04/20/2024, 8:00 AMZyle Moore
04/20/2024, 9:35 AMAdam S
04/20/2024, 9:58 AM