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.
Relating to #395, when working with data in a way equivalent to
codec.Raw
orjson.RawMessage
, it's useful to know what encoding is being encoded to or decoded from.codec.Selfer
methods don't have this ability, since neithercodec.Encoder
norcodec.Decoder
expose either thecodec.Handle
or itsName
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
andDecoder
a method which returns theHandle.Name()
value would provide sufficient information to satisfy this need.