6 data "github.com/tendermint/go-wire/data"
9 /** These are some sample types to test parsing **/
11 type Fooer interface {
16 Name string `json:"name"`
19 func (b Bar) Foo() string {
20 return "Bar " + b.Name
24 Name string `json:"name"`
27 func (b Baz) Foo() string {
28 return strings.Replace(b.Name, "r", "z", -1)
32 Prefix string `json:"prefix"`
33 Sub FooerS `json:"sub"`
36 func (n Nested) Foo() string {
37 return n.Prefix + ": " + n.Sub.Foo()
40 /** This is parse code: todo - autogenerate **/
42 var fooersParser data.Mapper
48 func (f FooerS) MarshalJSON() ([]byte, error) {
49 return fooersParser.ToJSON(f.Fooer)
52 func (f *FooerS) UnmarshalJSON(data []byte) (err error) {
53 parsed, err := fooersParser.FromJSON(data)
55 f.Fooer = parsed.(Fooer)
60 // Set is a helper to deal with wrapped interfaces
61 func (f *FooerS) Set(foo Fooer) {
65 /** end TO-BE auto-generated code **/
67 /** This connects our code with the auto-generated helpers **/
69 // this init must come after the above init (which should be in a file from import)
71 fooersParser = data.NewMapper(FooerS{}).
72 RegisterImplementation(Bar{}, "bar", 0x01).
73 RegisterImplementation(Baz{}, "baz", 0x02).
74 RegisterImplementation(Nested{}, "nest", 0x03)