This is more of a question to @BurntSushi i guess but anyone can help of-course.
The thing is I have several types, say Type0, … , Type6. So I implement the usual traits for them to encode their content. All these types come in with separate tags of their own which are
u64. Now at the deserialization end I do not know what i received. So what do you think is the best way:
<1> Try decoding it to all types Type0 - Type6 one by one till it succeeds. Is this slow or does it use some llvm name-mangler to quickly determine the discrepancy and abandon it giving error so that I can try decoding it to the next type etc ? Or is this going to be slow ? Or is this possible at all in the sense that if layouts of TypeX and TypeY are same (identical members) then serialized content of one can be deserialized into other ?
<2> I can put the tag i mentioned for the type separately like (pseudocode)
CborTagEncode::new(tag_u64, &(&self.name, &self.owner, &self.value)).encode(e). But now at the decoding end i want to extract
tag_u64 thingy separately before i decide what to decode the rest of the stream into. Is this possible ? If yes (which will be of tremendous help) how to do it ?
<3> This is obvious if the above two fail: So i serialize TypeX, get Vec then serialize this along with the tag. So while decoding i deserialise into tag and Vec and then depending on tag, deserialise Vec into the concrete type. This will and does work but i want to avoid this dual deserialization. Is it possible using
<2> or any other method ?