func TestEncodeDecode5(t *testing.T) {
	pb := initGoTest(true)
	pb.RepeatedField = []*pb2.GoTestField{initGoTestField(), initGoTestField()}
	pb.F_BoolRepeated = []bool{false, true}
	pb.F_Int32Repeated = []int32{32, 33}
	pb.F_Int64Repeated = []int64{64, 65}
	pb.F_Fixed32Repeated = []uint32{3232, 3333}
	pb.F_Fixed64Repeated = []uint64{6464, 6565}
	pb.F_Uint32Repeated = []uint32{323232, 333333}
	pb.F_Uint64Repeated = []uint64{646464, 656565}
	pb.F_FloatRepeated = []float32{32., 33.}
	pb.F_DoubleRepeated = []float64{64., 65.}
	pb.F_StringRepeated = []string{"hello", "sailor"}
	pb.F_BytesRepeated = [][]byte{[]byte("big"), []byte("nose")}
	pb.F_Sint32Repeated = []int32{32, -32}
	pb.F_Sint64Repeated = []int64{64, -64}
	pb.F_Sfixed32Repeated = []int32{32, -32}
	pb.F_Sfixed64Repeated = []int64{64, -64}
	pb.Repeatedgroup = []*pb2.GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()}
	overify(t, pb,
		protopack.Message{
			protopack.Tag{1, protopack.VarintType}, protopack.Uvarint(7),
			protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{5, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{5, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{10, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{11, protopack.VarintType}, protopack.Varint(3),
			protopack.Tag{12, protopack.VarintType}, protopack.Varint(6),
			protopack.Tag{13, protopack.Fixed32Type}, protopack.Uint32(32),
			protopack.Tag{14, protopack.Fixed64Type}, protopack.Uint64(64),
			protopack.Tag{15, protopack.VarintType}, protopack.Uvarint(3232),
			protopack.Tag{16, protopack.VarintType}, protopack.Uvarint(6464),
			protopack.Tag{17, protopack.Fixed32Type}, protopack.Float32(3232),
			protopack.Tag{18, protopack.Fixed64Type}, protopack.Float64(6464),
			protopack.Tag{19, protopack.BytesType}, protopack.String("string"),
			protopack.Tag{20, protopack.VarintType}, protopack.Bool(false),
			protopack.Tag{20, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{21, protopack.VarintType}, protopack.Varint(32),
			protopack.Tag{21, protopack.VarintType}, protopack.Varint(33),
			protopack.Tag{22, protopack.VarintType}, protopack.Varint(64),
			protopack.Tag{22, protopack.VarintType}, protopack.Varint(65),
			protopack.Tag{23, protopack.Fixed32Type}, protopack.Uint32(3232),
			protopack.Tag{23, protopack.Fixed32Type}, protopack.Uint32(3333),
			protopack.Tag{24, protopack.Fixed64Type}, protopack.Uint64(6464),
			protopack.Tag{24, protopack.Fixed64Type}, protopack.Uint64(6565),
			protopack.Tag{25, protopack.VarintType}, protopack.Uvarint(323232),
			protopack.Tag{25, protopack.VarintType}, protopack.Uvarint(333333),
			protopack.Tag{26, protopack.VarintType}, protopack.Uvarint(646464),
			protopack.Tag{26, protopack.VarintType}, protopack.Uvarint(656565),
			protopack.Tag{27, protopack.Fixed32Type}, protopack.Float32(32),
			protopack.Tag{27, protopack.Fixed32Type}, protopack.Float32(33),
			protopack.Tag{28, protopack.Fixed64Type}, protopack.Float64(64),
			protopack.Tag{28, protopack.Fixed64Type}, protopack.Float64(65),
			protopack.Tag{29, protopack.BytesType}, protopack.String("hello"),
			protopack.Tag{29, protopack.BytesType}, protopack.String("sailor"),
			protopack.Tag{40, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{41, protopack.VarintType}, protopack.Varint(32),
			protopack.Tag{42, protopack.VarintType}, protopack.Varint(64),
			protopack.Tag{43, protopack.Fixed32Type}, protopack.Uint32(320),
			protopack.Tag{44, protopack.Fixed64Type}, protopack.Uint64(640),
			protopack.Tag{45, protopack.VarintType}, protopack.Uvarint(3200),
			protopack.Tag{46, protopack.VarintType}, protopack.Uvarint(6400),
			protopack.Tag{47, protopack.Fixed32Type}, protopack.Float32(314159),
			protopack.Tag{48, protopack.Fixed64Type}, protopack.Float64(271828),
			protopack.Tag{49, protopack.BytesType}, protopack.String("hello, \"world!\"\n"),
			protopack.Tag{70, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{71, protopack.BytesType}, protopack.String("required"),
			},
			protopack.Tag{70, protopack.EndGroupType},
			protopack.Tag{80, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{81, protopack.BytesType}, protopack.String("repeated"),
			},
			protopack.Tag{80, protopack.EndGroupType},
			protopack.Tag{80, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{81, protopack.BytesType}, protopack.String("repeated"),
			},
			protopack.Tag{80, protopack.EndGroupType},
			protopack.Tag{101, protopack.BytesType}, protopack.Bytes("bytes"),
			protopack.Tag{102, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{103, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{104, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{105, protopack.Fixed64Type}, protopack.Int64(-64),
			protopack.Tag{201, protopack.BytesType}, protopack.Bytes("big"),
			protopack.Tag{201, protopack.BytesType}, protopack.Bytes("nose"),
			protopack.Tag{202, protopack.VarintType}, protopack.Svarint(32),
			protopack.Tag{202, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{203, protopack.VarintType}, protopack.Svarint(64),
			protopack.Tag{203, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{204, protopack.Fixed32Type}, protopack.Int32(32),
			protopack.Tag{204, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{205, protopack.Fixed64Type}, protopack.Int64(64),
			protopack.Tag{205, protopack.Fixed64Type}, protopack.Int64(-64),
			protopack.Tag{401, protopack.BytesType}, protopack.Bytes("Bignose"),
			protopack.Tag{402, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{403, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{404, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{405, protopack.Fixed64Type}, protopack.Int64(-64),
		}.Marshal())
}
All required fields set, defaults provided, all repeated fields given two values.
package proto_test
import (
	"bytes"
	"encoding/json"
	"errors"
	"fmt"
	"log"
	"math"
	"math/rand"
	"reflect"
	"runtime/debug"
	"strings"
	"sync"
	"testing"
	"time"
	"github.com/golang/protobuf/proto"
	"google.golang.org/protobuf/testing/protopack"
	pb2 "github.com/golang/protobuf/internal/testprotos/proto2_proto"
	pb3 "github.com/golang/protobuf/internal/testprotos/proto3_proto"
	tspb "github.com/golang/protobuf/ptypes/timestamp"
)
func initGoTestField() *pb2.GoTestField {
	f := new(pb2.GoTestField)
	f.Label = proto.String("label")
	f.Type = proto.String("type")
	return f
}
func initGoTest_RequiredGroup() *pb2.GoTest_RequiredGroup {
	return &pb2.GoTest_RequiredGroup{
		RequiredField: proto.String("required"),
	}
}
func initGoTest_OptionalGroup() *pb2.GoTest_OptionalGroup {
	return &pb2.GoTest_OptionalGroup{
		RequiredField: proto.String("optional"),
	}
}
func initGoTest_RepeatedGroup() *pb2.GoTest_RepeatedGroup {
	return &pb2.GoTest_RepeatedGroup{
		RequiredField: proto.String("repeated"),
	}
}
func initGoTest(setdefaults bool) *pb2.GoTest {
	pb := new(pb2.GoTest)
	if setdefaults {
		pb.F_BoolDefaulted = proto.Bool(pb2.Default_GoTest_F_BoolDefaulted)
		pb.F_Int32Defaulted = proto.Int32(pb2.Default_GoTest_F_Int32Defaulted)
		pb.F_Int64Defaulted = proto.Int64(pb2.Default_GoTest_F_Int64Defaulted)
		pb.F_Fixed32Defaulted = proto.Uint32(pb2.Default_GoTest_F_Fixed32Defaulted)
		pb.F_Fixed64Defaulted = proto.Uint64(pb2.Default_GoTest_F_Fixed64Defaulted)
		pb.F_Uint32Defaulted = proto.Uint32(pb2.Default_GoTest_F_Uint32Defaulted)
		pb.F_Uint64Defaulted = proto.Uint64(pb2.Default_GoTest_F_Uint64Defaulted)
		pb.F_FloatDefaulted = proto.Float32(pb2.Default_GoTest_F_FloatDefaulted)
		pb.F_DoubleDefaulted = proto.Float64(pb2.Default_GoTest_F_DoubleDefaulted)
		pb.F_StringDefaulted = proto.String(pb2.Default_GoTest_F_StringDefaulted)
		pb.F_BytesDefaulted = pb2.Default_GoTest_F_BytesDefaulted
		pb.F_Sint32Defaulted = proto.Int32(pb2.Default_GoTest_F_Sint32Defaulted)
		pb.F_Sint64Defaulted = proto.Int64(pb2.Default_GoTest_F_Sint64Defaulted)
		pb.F_Sfixed32Defaulted = proto.Int32(pb2.Default_GoTest_F_Sfixed32Defaulted)
		pb.F_Sfixed64Defaulted = proto.Int64(pb2.Default_GoTest_F_Sfixed64Defaulted)
	}
	pb.Kind = pb2.GoTest_TIME.Enum()
	pb.RequiredField = initGoTestField()
	pb.F_BoolRequired = proto.Bool(true)
	pb.F_Int32Required = proto.Int32(3)
	pb.F_Int64Required = proto.Int64(6)
	pb.F_Fixed32Required = proto.Uint32(32)
	pb.F_Fixed64Required = proto.Uint64(64)
	pb.F_Uint32Required = proto.Uint32(3232)
	pb.F_Uint64Required = proto.Uint64(6464)
	pb.F_FloatRequired = proto.Float32(3232)
	pb.F_DoubleRequired = proto.Float64(6464)
	pb.F_StringRequired = proto.String("string")
	pb.F_BytesRequired = []byte("bytes")
	pb.F_Sint32Required = proto.Int32(-32)
	pb.F_Sint64Required = proto.Int64(-64)
	pb.F_Sfixed32Required = proto.Int32(-32)
	pb.F_Sfixed64Required = proto.Int64(-64)
	pb.Requiredgroup = initGoTest_RequiredGroup()
	return pb
}
func overify(t *testing.T, pb *pb2.GoTest, want []byte) {
	bb := new(proto.Buffer)
	err := bb.Marshal(pb)
	got := bb.Bytes()
	if err != nil {
		t.Logf("overify marshal-1 err = %v", err)
	}
	if !bytes.Equal(got, want) {
		t.Fatalf("got %q\nwant  %q", got, want)
	}
	pbd := new(pb2.GoTest)
	err = bb.Unmarshal(pbd)
	if err != nil {
		t.Fatalf("overify unmarshal err = %v", err)
	}
	bb.Reset()
	err = bb.Marshal(pbd)
	got = bb.Bytes()
	if err != nil {
		t.Fatalf("overify marshal-2 err = %v", err)
	}
	if !bytes.Equal(got, want) {
		t.Fatalf("got %q\nwant  %q", got, want)
	}
}
func isRequiredNotSetError(err error) bool {
	e, ok := err.(interface{ RequiredNotSet() bool })
	return ok && e.RequiredNotSet()
}
func TestNumericPrimitives(t *testing.T) {
	for i := uint64(0); i < 1e6; i += 111 {
		o := new(proto.Buffer)
		if o.EncodeVarint(i) != nil {
			t.Error("EncodeVarint")
			break
		}
		x, e := o.DecodeVarint()
		if e != nil {
			t.Fatal("DecodeVarint")
		}
		if x != i {
			t.Fatal("varint decode fail:", i, x)
		}
		o.Reset()
		if o.EncodeFixed32(i) != nil {
			t.Fatal("encFixed32")
		}
		x, e = o.DecodeFixed32()
		if e != nil {
			t.Fatal("decFixed32")
		}
		if x != i {
			t.Fatal("fixed32 decode fail:", i, x)
		}
		o.Reset()
		if o.EncodeFixed64(i*1234567) != nil {
			t.Error("encFixed64")
			break
		}
		x, e = o.DecodeFixed64()
		if e != nil {
			t.Error("decFixed64")
			break
		}
		if x != i*1234567 {
			t.Error("fixed64 decode fail:", i*1234567, x)
			break
		}
		o.Reset()
		i32 := int32(i - 12345)
		if o.EncodeZigzag32(uint64(i32)) != nil {
			t.Fatal("EncodeZigzag32")
		}
		x, e = o.DecodeZigzag32()
		if e != nil {
			t.Fatal("DecodeZigzag32")
		}
		if x != uint64(uint32(i32)) {
			t.Fatal("zigzag32 decode fail:", i32, x)
		}
		o.Reset()
		i64 := int64(i - 12345)
		if o.EncodeZigzag64(uint64(i64)) != nil {
			t.Fatal("EncodeZigzag64")
		}
		x, e = o.DecodeZigzag64()
		if e != nil {
			t.Fatal("DecodeZigzag64")
		}
		if x != uint64(i64) {
			t.Fatal("zigzag64 decode fail:", i64, x)
		}
	}
}
type fakeMarshaler struct {
	b   []byte
	err error
}
func (f *fakeMarshaler) Marshal() ([]byte, error) { return f.b, f.err }
func (f *fakeMarshaler) String() string           { return fmt.Sprintf("Bytes: %v Error: %v", f.b, f.err) }
func (f *fakeMarshaler) ProtoMessage()            {}
func (f *fakeMarshaler) Reset()                   {}
type msgWithFakeMarshaler struct {
	M *fakeMarshaler `protobuf:"bytes,1,opt,name=fake"`
}
func (m *msgWithFakeMarshaler) String() string { return proto.CompactTextString(m) }
func (m *msgWithFakeMarshaler) ProtoMessage()  {}
func (m *msgWithFakeMarshaler) Reset()         {}
func TestMarshalerEncoding(t *testing.T) {
	tests := []struct {
		name    string
		m       proto.Message
		want    []byte
		errType reflect.Type
	}{
		{
			name: "Marshaler that fails",
			m: &fakeMarshaler{
				err: errors.New("some marshal err"),
				b:   []byte{5, 6, 7},
			},
			errType: reflect.TypeOf(errors.New("some marshal err")),
		},
		{
			name: "Marshaler that fails with RequiredNotSetError",
			m: &msgWithFakeMarshaler{
				M: &fakeMarshaler{
					err: &proto.RequiredNotSetError{},
					b:   []byte{5, 6, 7},
				},
			},
			errType: reflect.TypeOf(&proto.RequiredNotSetError{}),
		},
		{
			name: "Marshaler that succeeds",
			m: &fakeMarshaler{
				b: []byte{0, 1, 2, 3, 4, 127, 255},
			},
			want: []byte{0, 1, 2, 3, 4, 127, 255},
		},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			b := proto.NewBuffer(nil)
			err := b.Marshal(test.m)
			if reflect.TypeOf(err) != test.errType {
				t.Errorf("got err %T(%v) wanted %T", err, err, test.errType)
			}
			if err != nil {
				return  
			}
			if !reflect.DeepEqual(test.want, b.Bytes()) {
				t.Errorf("got bytes %v wanted %v", b.Bytes(), test.want)
			}
			if size := proto.Size(test.m); size != len(b.Bytes()) {
				t.Errorf("Size(_) = %v, but marshaled to %v bytes", size, len(b.Bytes()))
			}
			m, mErr := proto.Marshal(test.m)
			if !bytes.Equal(b.Bytes(), m) {
				t.Errorf("Marshal returned %v, but (*Buffer).Marshal wrote %v", m, b.Bytes())
			}
			if !reflect.DeepEqual(err, mErr) {
				t.Errorf("Marshal err = %v, but (*Buffer).Marshal returned %v", mErr, err)
			}
		})
	}
}
func TestBufferMarshalAllocs(t *testing.T) {
	value := &pb2.OtherMessage{Key: proto.Int64(1)}
	msg := &pb2.MyMessage{Count: proto.Int32(1), Others: []*pb2.OtherMessage{value}}
	for _, prealloc := range []int{0, 100, 10000} {
		const count = 1000
		var b proto.Buffer
		s := make([]byte, 0, proto.Size(msg))
		marshalAllocs := testing.AllocsPerRun(count, func() {
			b.SetBuf(s)
			err := b.Marshal(msg)
			if err != nil {
				t.Errorf("Marshal err = %q", err)
			}
		})
		b.SetBuf(make([]byte, 0, prealloc))
		bufferAllocs := testing.AllocsPerRun(count, func() {
			err := b.Marshal(msg)
			if err != nil {
				t.Errorf("Marshal err = %q", err)
			}
		})
		if marshalAllocs != bufferAllocs {
			t.Errorf("%v allocs/op when writing to a preallocated buffer", marshalAllocs)
			t.Errorf("%v allocs/op when repeatedly appending to a buffer", bufferAllocs)
			t.Errorf("expect amortized allocs/op to be identical")
		}
	}
}
func TestBytesPrimitives(t *testing.T) {
	bb := new(proto.Buffer)
	want := []byte("now is the time")
	if err := bb.EncodeRawBytes(want); err != nil {
		t.Errorf("EncodeRawBytes error: %v", err)
	}
	got, err := bb.DecodeRawBytes(false)
	if err != nil {
		t.Errorf("DecodeRawBytes error: %v", err)
	}
	if !bytes.Equal(got, want) {
		t.Errorf("got %q\nwant  %q", got, want)
	}
}
func TestStringPrimitives(t *testing.T) {
	bb := new(proto.Buffer)
	want := "now is the time"
	if err := bb.EncodeStringBytes(want); err != nil {
		t.Errorf("EncodeStringBytes error: %v", err)
	}
	got, err := bb.DecodeStringBytes()
	if err != nil {
		t.Errorf("DecodeStringBytes error: %v", err)
	}
	if got != want {
		t.Errorf("got %q\nwant  %q", got, want)
	}
}
func TestRequiredBit(t *testing.T) {
	o := new(proto.Buffer)
	pb := new(pb2.GoTest)
	err := o.Marshal(pb)
	if err == nil {
		t.Error("did not catch missing required fields")
	} else if !strings.Contains(err.Error(), "Kind") {
		t.Error("wrong error type:", err)
	}
}
func checkInitialized(pb *pb2.GoTest, t *testing.T) {
	switch {
	case pb.F_BoolDefaulted != nil:
		t.Error("New or Reset did not set boolean:", *pb.F_BoolDefaulted)
	case pb.F_Int32Defaulted != nil:
		t.Error("New or Reset did not set int32:", *pb.F_Int32Defaulted)
	case pb.F_Int64Defaulted != nil:
		t.Error("New or Reset did not set int64:", *pb.F_Int64Defaulted)
	case pb.F_Fixed32Defaulted != nil:
		t.Error("New or Reset did not set fixed32:", *pb.F_Fixed32Defaulted)
	case pb.F_Fixed64Defaulted != nil:
		t.Error("New or Reset did not set fixed64:", *pb.F_Fixed64Defaulted)
	case pb.F_Uint32Defaulted != nil:
		t.Error("New or Reset did not set uint32:", *pb.F_Uint32Defaulted)
	case pb.F_Uint64Defaulted != nil:
		t.Error("New or Reset did not set uint64:", *pb.F_Uint64Defaulted)
	case pb.F_FloatDefaulted != nil:
		t.Error("New or Reset did not set float:", *pb.F_FloatDefaulted)
	case pb.F_DoubleDefaulted != nil:
		t.Error("New or Reset did not set double:", *pb.F_DoubleDefaulted)
	case pb.F_StringDefaulted != nil:
		t.Error("New or Reset did not set string:", *pb.F_StringDefaulted)
	case pb.F_BytesDefaulted != nil:
		t.Error("New or Reset did not set bytes:", string(pb.F_BytesDefaulted))
	case pb.F_Sint32Defaulted != nil:
		t.Error("New or Reset did not set int32:", *pb.F_Sint32Defaulted)
	case pb.F_Sint64Defaulted != nil:
		t.Error("New or Reset did not set int64:", *pb.F_Sint64Defaulted)
	}
}
func TestReset(t *testing.T) {
	pb := initGoTest(true)
	pb.F_BoolDefaulted = proto.Bool(false)
	pb.F_Int32Defaulted = proto.Int32(237)
	pb.F_Int64Defaulted = proto.Int64(12346)
	pb.F_Fixed32Defaulted = proto.Uint32(32000)
	pb.F_Fixed64Defaulted = proto.Uint64(666)
	pb.F_Uint32Defaulted = proto.Uint32(323232)
	pb.F_Uint64Defaulted = nil
	pb.F_FloatDefaulted = nil
	pb.F_DoubleDefaulted = proto.Float64(0)
	pb.F_StringDefaulted = proto.String("gotcha")
	pb.F_BytesDefaulted = []byte("asdfasdf")
	pb.F_Sint32Defaulted = proto.Int32(123)
	pb.F_Sint64Defaulted = proto.Int64(789)
	pb.Reset()
	checkInitialized(pb, t)
}
func TestEncodeDecode1(t *testing.T) {
	pb := initGoTest(false)
	overify(t, pb,
		protopack.Message{
			protopack.Tag{1, protopack.VarintType}, protopack.Uvarint(7),
			protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{10, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{11, protopack.VarintType}, protopack.Varint(3),
			protopack.Tag{12, protopack.VarintType}, protopack.Varint(6),
			protopack.Tag{13, protopack.Fixed32Type}, protopack.Uint32(32),
			protopack.Tag{14, protopack.Fixed64Type}, protopack.Uint64(64),
			protopack.Tag{15, protopack.VarintType}, protopack.Uvarint(3232),
			protopack.Tag{16, protopack.VarintType}, protopack.Uvarint(6464),
			protopack.Tag{17, protopack.Fixed32Type}, protopack.Float32(3232),
			protopack.Tag{18, protopack.Fixed64Type}, protopack.Float64(6464),
			protopack.Tag{19, protopack.BytesType}, protopack.String("string"),
			protopack.Tag{70, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{71, protopack.BytesType}, protopack.String("required"),
			},
			protopack.Tag{70, protopack.EndGroupType},
			protopack.Tag{101, protopack.BytesType}, protopack.Bytes("bytes"),
			protopack.Tag{102, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{103, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{104, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{105, protopack.Fixed64Type}, protopack.Int64(-64),
		}.Marshal())
}
func TestEncodeDecode2(t *testing.T) {
	pb := initGoTest(true)
	overify(t, pb,
		protopack.Message{
			protopack.Tag{1, protopack.VarintType}, protopack.Uvarint(7),
			protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{10, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{11, protopack.VarintType}, protopack.Varint(3),
			protopack.Tag{12, protopack.VarintType}, protopack.Varint(6),
			protopack.Tag{13, protopack.Fixed32Type}, protopack.Uint32(32),
			protopack.Tag{14, protopack.Fixed64Type}, protopack.Uint64(64),
			protopack.Tag{15, protopack.VarintType}, protopack.Uvarint(3232),
			protopack.Tag{16, protopack.VarintType}, protopack.Uvarint(6464),
			protopack.Tag{17, protopack.Fixed32Type}, protopack.Float32(3232),
			protopack.Tag{18, protopack.Fixed64Type}, protopack.Float64(6464),
			protopack.Tag{19, protopack.BytesType}, protopack.String("string"),
			protopack.Tag{40, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{41, protopack.VarintType}, protopack.Varint(32),
			protopack.Tag{42, protopack.VarintType}, protopack.Varint(64),
			protopack.Tag{43, protopack.Fixed32Type}, protopack.Uint32(320),
			protopack.Tag{44, protopack.Fixed64Type}, protopack.Uint64(640),
			protopack.Tag{45, protopack.VarintType}, protopack.Uvarint(3200),
			protopack.Tag{46, protopack.VarintType}, protopack.Uvarint(6400),
			protopack.Tag{47, protopack.Fixed32Type}, protopack.Float32(314159),
			protopack.Tag{48, protopack.Fixed64Type}, protopack.Float64(271828),
			protopack.Tag{49, protopack.BytesType}, protopack.String("hello, \"world!\"\n"),
			protopack.Tag{70, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{71, protopack.BytesType}, protopack.String("required"),
			},
			protopack.Tag{70, protopack.EndGroupType},
			protopack.Tag{101, protopack.BytesType}, protopack.Bytes("bytes"),
			protopack.Tag{102, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{103, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{104, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{105, protopack.Fixed64Type}, protopack.Int64(-64),
			protopack.Tag{401, protopack.BytesType}, protopack.Bytes("Bignose"),
			protopack.Tag{402, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{403, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{404, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{405, protopack.Fixed64Type}, protopack.Int64(-64),
		}.Marshal())
}
func TestEncodeDecode3(t *testing.T) {
	pb := initGoTest(false)
	pb.F_BoolDefaulted = proto.Bool(true)
	pb.F_Int32Defaulted = proto.Int32(32)
	pb.F_Int64Defaulted = proto.Int64(64)
	pb.F_Fixed32Defaulted = proto.Uint32(320)
	pb.F_Fixed64Defaulted = proto.Uint64(640)
	pb.F_Uint32Defaulted = proto.Uint32(3200)
	pb.F_Uint64Defaulted = proto.Uint64(6400)
	pb.F_FloatDefaulted = proto.Float32(314159)
	pb.F_DoubleDefaulted = proto.Float64(271828)
	pb.F_StringDefaulted = proto.String("hello, \"world!\"\n")
	pb.F_BytesDefaulted = []byte("Bignose")
	pb.F_Sint32Defaulted = proto.Int32(-32)
	pb.F_Sint64Defaulted = proto.Int64(-64)
	pb.F_Sfixed32Defaulted = proto.Int32(-32)
	pb.F_Sfixed64Defaulted = proto.Int64(-64)
	overify(t, pb,
		protopack.Message{
			protopack.Tag{1, protopack.VarintType}, protopack.Uvarint(7),
			protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{10, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{11, protopack.VarintType}, protopack.Varint(3),
			protopack.Tag{12, protopack.VarintType}, protopack.Varint(6),
			protopack.Tag{13, protopack.Fixed32Type}, protopack.Uint32(32),
			protopack.Tag{14, protopack.Fixed64Type}, protopack.Uint64(64),
			protopack.Tag{15, protopack.VarintType}, protopack.Uvarint(3232),
			protopack.Tag{16, protopack.VarintType}, protopack.Uvarint(6464),
			protopack.Tag{17, protopack.Fixed32Type}, protopack.Float32(3232),
			protopack.Tag{18, protopack.Fixed64Type}, protopack.Float64(6464),
			protopack.Tag{19, protopack.BytesType}, protopack.String("string"),
			protopack.Tag{40, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{41, protopack.VarintType}, protopack.Varint(32),
			protopack.Tag{42, protopack.VarintType}, protopack.Varint(64),
			protopack.Tag{43, protopack.Fixed32Type}, protopack.Uint32(320),
			protopack.Tag{44, protopack.Fixed64Type}, protopack.Uint64(640),
			protopack.Tag{45, protopack.VarintType}, protopack.Uvarint(3200),
			protopack.Tag{46, protopack.VarintType}, protopack.Uvarint(6400),
			protopack.Tag{47, protopack.Fixed32Type}, protopack.Float32(314159),
			protopack.Tag{48, protopack.Fixed64Type}, protopack.Float64(271828),
			protopack.Tag{49, protopack.BytesType}, protopack.String("hello, \"world!\"\n"),
			protopack.Tag{70, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{71, protopack.BytesType}, protopack.String("required"),
			},
			protopack.Tag{70, protopack.EndGroupType},
			protopack.Tag{101, protopack.BytesType}, protopack.Bytes("bytes"),
			protopack.Tag{102, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{103, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{104, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{105, protopack.Fixed64Type}, protopack.Int64(-64),
			protopack.Tag{401, protopack.BytesType}, protopack.Bytes("Bignose"),
			protopack.Tag{402, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{403, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{404, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{405, protopack.Fixed64Type}, protopack.Int64(-64),
		}.Marshal())
}
func TestEncodeDecode4(t *testing.T) {
	pb := initGoTest(true)
	pb.Table = proto.String("hello")
	pb.Param = proto.Int32(7)
	pb.OptionalField = initGoTestField()
	pb.F_BoolOptional = proto.Bool(true)
	pb.F_Int32Optional = proto.Int32(32)
	pb.F_Int64Optional = proto.Int64(64)
	pb.F_Fixed32Optional = proto.Uint32(3232)
	pb.F_Fixed64Optional = proto.Uint64(6464)
	pb.F_Uint32Optional = proto.Uint32(323232)
	pb.F_Uint64Optional = proto.Uint64(646464)
	pb.F_FloatOptional = proto.Float32(32.)
	pb.F_DoubleOptional = proto.Float64(64.)
	pb.F_StringOptional = proto.String("hello")
	pb.F_BytesOptional = []byte("Bignose")
	pb.F_Sint32Optional = proto.Int32(-32)
	pb.F_Sint64Optional = proto.Int64(-64)
	pb.F_Sfixed32Optional = proto.Int32(-32)
	pb.F_Sfixed64Optional = proto.Int64(-64)
	pb.Optionalgroup = initGoTest_OptionalGroup()
	overify(t, pb,
		protopack.Message{
			protopack.Tag{1, protopack.VarintType}, protopack.Uvarint(7),
			protopack.Tag{2, protopack.BytesType}, protopack.String("hello"),
			protopack.Tag{3, protopack.VarintType}, protopack.Varint(7),
			protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{6, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
				protopack.Tag{1, protopack.BytesType}, protopack.String("label"),
				protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
			}),
			protopack.Tag{10, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{11, protopack.VarintType}, protopack.Varint(3),
			protopack.Tag{12, protopack.VarintType}, protopack.Varint(6),
			protopack.Tag{13, protopack.Fixed32Type}, protopack.Uint32(32),
			protopack.Tag{14, protopack.Fixed64Type}, protopack.Uint64(64),
			protopack.Tag{15, protopack.VarintType}, protopack.Uvarint(3232),
			protopack.Tag{16, protopack.VarintType}, protopack.Uvarint(6464),
			protopack.Tag{17, protopack.Fixed32Type}, protopack.Float32(3232),
			protopack.Tag{18, protopack.Fixed64Type}, protopack.Float64(6464),
			protopack.Tag{19, protopack.BytesType}, protopack.String("string"),
			protopack.Tag{30, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{31, protopack.VarintType}, protopack.Varint(32),
			protopack.Tag{32, protopack.VarintType}, protopack.Varint(64),
			protopack.Tag{33, protopack.Fixed32Type}, protopack.Uint32(3232),
			protopack.Tag{34, protopack.Fixed64Type}, protopack.Uint64(6464),
			protopack.Tag{35, protopack.VarintType}, protopack.Uvarint(323232),
			protopack.Tag{36, protopack.VarintType}, protopack.Uvarint(646464),
			protopack.Tag{37, protopack.Fixed32Type}, protopack.Float32(32),
			protopack.Tag{38, protopack.Fixed64Type}, protopack.Float64(64),
			protopack.Tag{39, protopack.BytesType}, protopack.String("hello"),
			protopack.Tag{40, protopack.VarintType}, protopack.Bool(true),
			protopack.Tag{41, protopack.VarintType}, protopack.Varint(32),
			protopack.Tag{42, protopack.VarintType}, protopack.Varint(64),
			protopack.Tag{43, protopack.Fixed32Type}, protopack.Uint32(320),
			protopack.Tag{44, protopack.Fixed64Type}, protopack.Uint64(640),
			protopack.Tag{45, protopack.VarintType}, protopack.Uvarint(3200),
			protopack.Tag{46, protopack.VarintType}, protopack.Uvarint(6400),
			protopack.Tag{47, protopack.Fixed32Type}, protopack.Float32(314159),
			protopack.Tag{48, protopack.Fixed64Type}, protopack.Float64(271828),
			protopack.Tag{49, protopack.BytesType}, protopack.String("hello, \"world!\"\n"),
			protopack.Tag{70, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{71, protopack.BytesType}, protopack.String("required"),
			},
			protopack.Tag{70, protopack.EndGroupType},
			protopack.Tag{90, protopack.StartGroupType},
			protopack.Message{
				protopack.Tag{91, protopack.BytesType}, protopack.String("optional"),
			},
			protopack.Tag{90, protopack.EndGroupType},
			protopack.Tag{101, protopack.BytesType}, protopack.Bytes("bytes"),
			protopack.Tag{102, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{103, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{104, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{105, protopack.Fixed64Type}, protopack.Int64(-64),
			protopack.Tag{301, protopack.BytesType}, protopack.Bytes("Bignose"),
			protopack.Tag{302, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{303, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{304, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{305, protopack.Fixed64Type}, protopack.Int64(-64),
			protopack.Tag{401, protopack.BytesType}, protopack.Bytes("Bignose"),
			protopack.Tag{402, protopack.VarintType}, protopack.Svarint(-32),
			protopack.Tag{403, protopack.VarintType}, protopack.Svarint(-64),
			protopack.Tag{404, protopack.Fixed32Type}, protopack.Int32(-32),
			protopack.Tag{405, protopack.Fixed64Type}, protopack.Int64(-64),
		}.Marshal())
}