syncthing/vendor/github.com/gogo/protobuf/test/t.go
Jakob Borg 93a04158fd vendor: Update github.com/gogo/protobuf, keeping all files
gvt fetch -a, because we need the protobuf files etc for regeneration
2017-06-14 05:24:09 +02:00

74 lines
1.1 KiB
Go

package test
import (
"encoding/json"
"strings"
"github.com/gogo/protobuf/proto"
)
type T struct {
Data string
}
func (gt *T) protoType() *ProtoType {
return &ProtoType{
Field2: &gt.Data,
}
}
func (gt T) Equal(other T) bool {
return gt.protoType().Equal(other.protoType())
}
func (gt *T) Size() int {
proto := &ProtoType{
Field2: &gt.Data,
}
return proto.Size()
}
func NewPopulatedT(r randyThetest) *T {
data := NewPopulatedProtoType(r, false).Field2
gt := &T{}
if data != nil {
gt.Data = *data
}
return gt
}
func (r T) Marshal() ([]byte, error) {
return proto.Marshal(r.protoType())
}
func (r *T) Unmarshal(data []byte) error {
pr := &ProtoType{}
err := proto.Unmarshal(data, pr)
if err != nil {
return err
}
if pr.Field2 != nil {
r.Data = *pr.Field2
}
return nil
}
func (gt T) MarshalJSON() ([]byte, error) {
return json.Marshal(gt.Data)
}
func (gt *T) UnmarshalJSON(data []byte) error {
var s string
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
*gt = T{Data: s}
return nil
}
func (gt T) Compare(other T) int {
return strings.Compare(gt.Data, other.Data)
}