1 // Copyright 2012 Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
14 func TestExponentialSizeIncreasePrepend(t *testing.T) {
16 for i, test := range []struct {
29 b.PrependBytes(test.prepend)
30 if test.size != cap(b.data) {
31 t.Error(i, "size want", test.size, "got", cap(b.data))
40 func TestExponentialSizeIncreaseAppend(t *testing.T) {
42 for i, test := range []struct {
55 b.AppendBytes(test.appnd)
56 if test.size != cap(b.data) {
57 t.Error(i, "size want", test.size, "got", cap(b.data))
66 func ExampleSerializeBuffer() {
67 b := NewSerializeBuffer()
68 fmt.Println("1:", b.Bytes())
69 bytes, _ := b.PrependBytes(3)
70 copy(bytes, []byte{1, 2, 3})
71 fmt.Println("2:", b.Bytes())
72 bytes, _ = b.AppendBytes(2)
73 copy(bytes, []byte{4, 5})
74 fmt.Println("3:", b.Bytes())
75 bytes, _ = b.PrependBytes(1)
76 copy(bytes, []byte{0})
77 fmt.Println("4:", b.Bytes())
78 bytes, _ = b.AppendBytes(3)
79 copy(bytes, []byte{6, 7, 8})
80 fmt.Println("5:", b.Bytes())
82 fmt.Println("6:", b.Bytes())
83 bytes, _ = b.PrependBytes(2)
84 copy(bytes, []byte{9, 9})
85 fmt.Println("7:", b.Bytes())
91 // 5: [0 1 2 3 4 5 6 7 8]