package evtsm import ( "fmt" "io" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" ) // Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. var _ = xerrors.Errorf func (t *TestState) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } if _, err := w.Write([]byte{162}); err != nil { return err } // t.A (uint64) (uint64) if len("A") > cbg.MaxLength { return xerrors.Errorf("Value in field \"A\" was too long") } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("A")))); err != nil { return err } if _, err := w.Write([]byte("A")); err != nil { return err } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.A))); err != nil { return err } // t.B (uint64) (uint64) if len("B") > cbg.MaxLength { return xerrors.Errorf("Value in field \"B\" was too long") } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("B")))); err != nil { return err } if _, err := w.Write([]byte("B")); err != nil { return err } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.B))); err != nil { return err } return nil } func (t *TestState) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) maj, extra, err := cbg.CborReadHeader(br) if err != nil { return err } if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } if extra != 2 { return fmt.Errorf("cbor input had wrong number of fields") } var name string // t.A (uint64) (uint64) { sval, err := cbg.ReadString(br) if err != nil { return err } name = string(sval) } if name != "A" { return fmt.Errorf("expected struct map entry %s to be A", name) } maj, extra, err = cbg.CborReadHeader(br) if err != nil { return err } if maj != cbg.MajUnsignedInt { return fmt.Errorf("wrong type for uint64 field") } t.A = uint64(extra) // t.B (uint64) (uint64) { sval, err := cbg.ReadString(br) if err != nil { return err } name = string(sval) } if name != "B" { return fmt.Errorf("expected struct map entry %s to be B", name) } maj, extra, err = cbg.CborReadHeader(br) if err != nil { return err } if maj != cbg.MajUnsignedInt { return fmt.Errorf("wrong type for uint64 field") } t.B = uint64(extra) return nil } func (t *TestEvent) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } if _, err := w.Write([]byte{162}); err != nil { return err } // t.A (string) (string) if len("A") > cbg.MaxLength { return xerrors.Errorf("Value in field \"A\" was too long") } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("A")))); err != nil { return err } if _, err := w.Write([]byte("A")); err != nil { return err } if len(t.A) > cbg.MaxLength { return xerrors.Errorf("Value in field t.A was too long") } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.A)))); err != nil { return err } if _, err := w.Write([]byte(t.A)); err != nil { return err } // t.Val (uint64) (uint64) if len("Val") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Val\" was too long") } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Val")))); err != nil { return err } if _, err := w.Write([]byte("Val")); err != nil { return err } if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Val))); err != nil { return err } return nil } func (t *TestEvent) UnmarshalCBOR(r io.Reader) error { br := cbg.GetPeeker(r) maj, extra, err := cbg.CborReadHeader(br) if err != nil { return err } if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } if extra != 2 { return fmt.Errorf("cbor input had wrong number of fields") } var name string // t.A (string) (string) { sval, err := cbg.ReadString(br) if err != nil { return err } name = string(sval) } if name != "A" { return fmt.Errorf("expected struct map entry %s to be A", name) } { sval, err := cbg.ReadString(br) if err != nil { return err } t.A = string(sval) } // t.Val (uint64) (uint64) { sval, err := cbg.ReadString(br) if err != nil { return err } name = string(sval) } if name != "Val" { return fmt.Errorf("expected struct map entry %s to be Val", name) } maj, extra, err = cbg.CborReadHeader(br) if err != nil { return err } if maj != cbg.MajUnsignedInt { return fmt.Errorf("wrong type for uint64 field") } t.Val = uint64(extra) return nil }