3 // Directive: +gen on FooInner
8 "github.com/tendermint/go-wire/data"
11 // Auto-generated adapters for happily unmarshaling interfaces
13 // Copyright (c) 2017 Ethan Frey (ethan.frey@tendermint.com)
16 FooInner "json:\"unwrap\""
19 var FooMapper = data.NewMapper(Foo{})
21 func (h Foo) MarshalJSON() ([]byte, error) {
22 return FooMapper.ToJSON(h.FooInner)
25 func (h *Foo) UnmarshalJSON(data []byte) (err error) {
26 parsed, err := FooMapper.FromJSON(data)
27 if err == nil && parsed != nil {
28 h.FooInner = parsed.(FooInner)
33 // Unwrap recovers the concrete interface safely (regardless of levels of embeds)
34 func (h Foo) Unwrap() FooInner {
36 for wrap, ok := hi.(Foo); ok; wrap, ok = hi.(Foo) {
42 func (h Foo) Empty() bool {
43 return h.FooInner == nil
46 /*** below are bindings for each implementation ***/
49 FooMapper.RegisterImplementation(Bling{}, "blng", 0x1)
52 func (hi Bling) Wrap() Foo {
57 FooMapper.RegisterImplementation(&Fuzz{}, "fzz", 0x2)
60 func (hi *Fuzz) Wrap() Foo {