Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Handle.Name() in some form through Encoder and Decoder for use by codec.Selfer #396

Closed
extemporalgenome opened this issue Jul 4, 2023 · 1 comment

Comments

@extemporalgenome
Copy link
Contributor

Relating to #395, when working with data in a way equivalent to codec.Raw or json.RawMessage, it's useful to know what encoding is being encoded to or decoded from. codec.Selfer methods don't have this ability, since neither codec.Encoder nor codec.Decoder expose either the codec.Handle or its Name method.

For example, if I have a type which works similarly to codec.Raw, which may at any time contain either JSON or CBOR, I want to be able to optimistically represent the contained data in the same format, for example:

If encoding to JSON, and the contained data is already encoded in JSON, behave the same as json.RawMessage. Otherwise, re-encode as JSON.

The equivalent behavior would apply when encoding to other formats (pass-through or re-encode then pass-through).

Giving Encoder and Decoder a method which returns the Handle.Name() value would provide sufficient information to satisfy this need.

@ugorji
Copy link
Owner

ugorji commented Nov 28, 2023

Thought through this. We can add this without any adverse effects.

@ugorji ugorji closed this as completed in 48ba79b Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants