MCPcopy Index your code
hub / github.com/tinylib/msgp / TestExtensionRawStackBuffer

Function TestExtensionRawStackBuffer

msgp/extension_test.go:84–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestExtensionRawStackBuffer(t *testing.T) {
85 var buf bytes.Buffer
86 en := NewWriter(&buf)
87 dc := NewReader(&buf)
88
89 const bufSize = 128
90 e := &RawExtension{Type: int8(rand.Int()), Data: RandBytes(bufSize)}
91
92 allocs := testing.AllocsPerRun(100, func() {
93 buf.Reset()
94
95 var staticBuf [bufSize]byte
96 slc := e.Data[:rand.Intn(bufSize)]
97 copy(staticBuf[:], slc)
98
99 err := en.WriteExtensionRaw(e.Type, staticBuf[:len(slc)])
100 if err != nil {
101 t.Errorf("error writing extension: %s", err)
102 }
103 en.Flush()
104
105 typ, payload, err := dc.ReadExtensionRaw()
106 if err != nil {
107 t.Errorf("error reading extension: %s", err)
108 }
109 if typ != e.Type || !bytes.Equal(payload, slc) {
110 t.Errorf("extension mismatch: %d %x != %d %x", typ, payload, e.Type, slc)
111 }
112 })
113
114 if allocs != 0 {
115 t.Errorf("using stack allocated buffer with WriteExtensionRaw caused %f allocations", allocs)
116 }
117}
118
119func TestReadWriteExtensionBytes(t *testing.T) {
120 var bts []byte

Callers

nothing calls this directly

Calls 9

WriteExtensionRawMethod · 0.95
FlushMethod · 0.95
ReadExtensionRawMethod · 0.95
NewWriterFunction · 0.85
NewReaderFunction · 0.85
RandBytesFunction · 0.85
IntMethod · 0.80
ResetMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…