github.com/glycerine/zebrapack@v4.1.1-0.20181107023619-e955d028f9bf+incompatible/testdata/headerplus.go (about)

     1  package testdata
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/glycerine/zebrapack/msgp"
     8  )
     9  
    10  //go:generate zebrapack
    11  
    12  // interface testing
    13  type Familiar interface {
    14  	Name() string
    15  
    16  	msgp.Decodable
    17  	msgp.Encodable
    18  	msgp.Marshaler
    19  	msgp.Unmarshaler
    20  	msgp.Sizer
    21  }
    22  
    23  type Dog struct {
    24  	Nm string `zid:"0"`
    25  }
    26  
    27  func (d *Dog) Name() string { return d.Nm }
    28  
    29  type Owl struct {
    30  	Nm string `zid:"0"`
    31  }
    32  
    33  func (o *Owl) Name() string { return o.Nm }
    34  
    35  type Header struct {
    36  	S1 string `zid:"0"`
    37  	S2 string `zid:"1"`
    38  	C  int64  `zid:"2"`
    39  }
    40  
    41  type Plus struct {
    42  	Tm    time.Time  `zid:"0"`
    43  	N     int64      `zid:"1"`
    44  	S     string     `zid:"2"`
    45  	F     float64    `zid:"3"`
    46  	Pet   Familiar   `msg:",iface" zid:"4"`
    47  	Flock []Familiar `msg:",iface" zid:"5"`
    48  }
    49  
    50  func (pl *Plus) NewValueAsInterface(zid int64, typename string) interface{} {
    51  	//fmt.Printf("\n DEBUG! NewValueAsInterface called with typename='%s'\n", typename)
    52  	switch typename {
    53  	case "Dog":
    54  		return &Dog{}
    55  	case "Owl":
    56  		return &Owl{}
    57  	}
    58  	panic(fmt.Sprintf("unknown typename '%s'", typename))
    59  }