コード例 #1
0
ファイル: chitin.gen.go プロジェクト: andyleap/chitin
func (m *PersonV2Maker) Bytes() []byte {
	// TODO what do we guarantee about immutability of return value?

	// TODO do this in just one allocation
	data := m.slots[:]

	{
		var lb [varuint.MaxUint64Len]byte
		var ll int

		ll = varuint.PutUint64(lb[:], uint64(len(m.fieldName))+1)
		data = append(data, lb[:ll]...)
		data = append(data, m.fieldName...)
	}

	{
		var lb [varuint.MaxUint64Len]byte
		var ll int

		ll = varuint.PutUint64(lb[:], uint64(len(m.fieldPhone))+1)
		data = append(data, lb[:ll]...)
		data = append(data, m.fieldPhone...)
	}

	return data
}
コード例 #2
0
func BenchmarkDchestPutUint64MaxLen(b *testing.B) {
	buf := make([]byte, 9)
	var n int
	b.SetBytes(8)
	for i := 0; i < b.N; i++ {
		n = varuint.PutUint64(buf, tests[17].decoded)
	}
	_ = n
}
コード例 #3
0
func BenchmarkDchestPutUint64All(b *testing.B) {
	buf := make([]byte, 9)
	var n int
	b.SetBytes(8)
	for i := 0; i < b.N; i++ {
		for _, test := range tests {
			n = varuint.PutUint64(buf, test.decoded)
		}
	}
	_ = n
}
コード例 #4
0
func TestVaruint(t *testing.T) {
	for i, test := range tests {
		b := make([]byte, len(test.encoded))
		n := varuint.PutUint64(b, test.decoded)
		if n != test.n {
			t.Errorf("encode %d: got %d want %d", i, n, test.n)
		}
		if !bytes.Equal(b, test.encoded) {
			t.Errorf("encode %d: got %v want %v", i, b[0:n], test.encoded)
		}
		v, n := varuint.Uint64(test.encoded)
		if n != test.n {
			t.Errorf("decode %d: got %d want %d", i, n, test.n)
		}
		if v != test.decoded {
			t.Errorf("decode %d: got %d want %d", i, v, test.decoded)
		}
	}
}