OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / go-wire / gen / ex / fooinner_wrapper.go
1 // Generated by: main
2 // TypeWriter: wrapper
3 // Directive: +gen on FooInner
4
5 package ex
6
7 import (
8         "github.com/tendermint/go-wire/data"
9 )
10
11 // Auto-generated adapters for happily unmarshaling interfaces
12 // Apache License 2.0
13 // Copyright (c) 2017 Ethan Frey (ethan.frey@tendermint.com)
14
15 type Foo struct {
16         FooInner "json:\"unwrap\""
17 }
18
19 var FooMapper = data.NewMapper(Foo{})
20
21 func (h Foo) MarshalJSON() ([]byte, error) {
22         return FooMapper.ToJSON(h.FooInner)
23 }
24
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)
29         }
30         return err
31 }
32
33 // Unwrap recovers the concrete interface safely (regardless of levels of embeds)
34 func (h Foo) Unwrap() FooInner {
35         hi := h.FooInner
36         for wrap, ok := hi.(Foo); ok; wrap, ok = hi.(Foo) {
37                 hi = wrap.FooInner
38         }
39         return hi
40 }
41
42 func (h Foo) Empty() bool {
43         return h.FooInner == nil
44 }
45
46 /*** below are bindings for each implementation ***/
47
48 func init() {
49         FooMapper.RegisterImplementation(Bling{}, "blng", 0x1)
50 }
51
52 func (hi Bling) Wrap() Foo {
53         return Foo{hi}
54 }
55
56 func init() {
57         FooMapper.RegisterImplementation(&Fuzz{}, "fzz", 0x2)
58 }
59
60 func (hi *Fuzz) Wrap() Foo {
61         return Foo{hi}
62 }