3 ms·
Are you referring to majewsky's encoding? How is that a Go-specific type tag? This is a really common encoding of sum types in unityped languages: the presence
by tree_of_item 9y ago
Are you referring to majewsky's encoding? How is that a Go-specific type tag? This is a really common encoding of sum types in unityped languages: the presence or absence of a key.
- KirinDave 9y agoThat kind of encoding is only the right call if you want for a message to be a foo, a bar, OR a foo+bar. If you've got an opcode, name it semantically with a name field. If you've got a type to serialize, do it semantically and don't just do like what the library I ported does and put the Golang type annotation in a string. And don't let objects inhabit a fusion like this. It leads to surprising behavior with malformed messages.
- tree_of_item 9y agoYour schema can simply say it is illegal for an object to have both of those tags once. I'm not sure how you'd do any better with a unityped system like JSON. Unless you're advocating using something other than JSON? What do you mean by "do it semantically"? What other alternative is there besides a field for a type tag?