amazon-ion / ion-go

A Go implementation of Amazon Ion.

Home Page:https://amazon-ion.github.io/ion-docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Marshalling Binary Symbols

matthewh-BQ opened this issue · comments

When marshalling symbols, e.g., $10, marshalling writes this out as a string. It should be writing this out as a symbol. Refer to: https://github.com/amzn/ion-go/blob/7c7b14b9dac9034d4831ffebbf4d4c54273b5447/ion/marshal.go#L172

There is encodeAs https://github.com/amzn/ion-go/blob/7c7b14b9dac9034d4831ffebbf4d4c54273b5447/ion/marshal.go#L129, but this seems to be a low level API.

Proposal would be for marshal to detect symbols and write it out as a symbol.

How do you know I didn't want to legitimately encode the string "$10"? It seems quite surprising if that secretly gets corrupted to whatever symbol happens to have ID 10. EncodeAs is not meant to be a low-level API, it's precisely for cases like this where you want to encode a value as a specific, non-default Ion type.

[edit: ahhh, low-level since it's EncodeAs not MarshalAs, I'm very likely an idiot. :) I'd be fine adding a MarshalAs function if it'd be useful for folks.]