polydawn / refmt

Object mapping for golang.
MIT License
48 stars 14 forks source link

Is it possible to defer unmarshaling? #20

Open whyrusleeping opened 6 years ago

whyrusleeping commented 6 years ago

I basically want the equivalent of https://golang.org/pkg/encoding/json/#RawMessage

I can look at implementing this if its not already possible.

warpfork commented 6 years ago

Nothing like it yet.

One implementation approach that might be interesting would be storing a []Token, in contrast to json.RawMessage's []byte approach. This would save tokenizing twice, assuming you're going to parse it later. On the other hand, the memory overhead might not be great; the token type is defined with a ton of fields and expected to be used like a union, because the way things work right now there's only ever one of the allocated and it's just used to pass messages back and forth. So, maybe it depends on what you're doing.

If you're angling to do something like http://eagain.net/articles/go-json-kind/ with this, there might be other options: docs/dev/code-layout.md proposed things like unmarshalMachinePolymorphicEnvelope, which also still needs implementation work, but would probably be the cleanest solution to those sorts of use case.