You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes it is necessary to decode values of any type or that can take on any structure; unfortunately Swift’s Codable is not well suited for this purpose. PotentCodables provides AnyValue to fill the gap.
But I suspect it only works for tree-structured values with no shared object references. I was looking here because I'd love to replace my own solution for this.
In my particular limited case I have large immutable class instances (the storage for SourceFile instances) that are repeatedly copied within the data structure being serialized, and they need to be encoded/decode just once.
So the structure forms a DAG, not a tree, and I need a to maintain a registry of the objects serialized/deserialized so far (the EncodingState or DecodingState) which you can see in action here. Yes indeed, it's awkward, but as you say, “unfortunately Swift’s Codable is not well suited for this purpose.”
If in fact you don't have support for stateful coding and the object graph reconstruction that can be built on top of that, and you'd like to leverage my work, you're welcome to it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The
AnyValue
docs say:But I suspect it only works for tree-structured values with no shared object references. I was looking here because I'd love to replace my own solution for this.
It is built on the idea of stateful coding with usage here.
In my particular limited case I have large immutable class instances (the storage for
SourceFile
instances) that are repeatedly copied within the data structure being serialized, and they need to be encoded/decode just once.So the structure forms a DAG, not a tree, and I need a to maintain a registry of the objects serialized/deserialized so far (the
EncodingState
orDecodingState
) which you can see in action here. Yes indeed, it's awkward, but as you say, “unfortunately Swift’s Codable is not well suited for this purpose.”If in fact you don't have support for stateful coding and the object graph reconstruction that can be built on top of that, and you'd like to leverage my work, you're welcome to it.
Beta Was this translation helpful? Give feedback.
All reactions