MCPcopy
hub / github.com/TarsCloud/TarsGo / TestSkipStruct2

Function TestSkipStruct2

tars/protocol/codec/codec_test.go:233–276  ·  view source on GitHub ↗

TestSkipStruct2 tests skip struct.

(t *testing.T)

Source from the content-addressed store, hash-verified

231
232// TestSkipStruct2 tests skip struct.
233func TestSkipStruct2(t *testing.T) {
234 b := NewBuffer()
235
236 err := b.WriteHead(StructBegin, 1)
237 if err != nil {
238 t.Error(err)
239 }
240 err = b.WriteHead(StructBegin, 1)
241 if err != nil {
242 t.Error(err)
243 }
244
245 err = b.WriteHead(StructEnd, 0)
246 if err != nil {
247 t.Error(err)
248 }
249 err = b.WriteHead(StructEnd, 0)
250 if err != nil {
251 t.Error(err)
252 }
253 err = b.WriteInt64(math.MinInt64, byte(10))
254 if err != nil {
255 t.Error(err)
256 }
257
258 rb := r(b)
259
260 have, err := rb.SkipTo(StructBegin, 1, true)
261 if err != nil || !have {
262 t.Error(err)
263 }
264 err = rb.SkipToStructEnd()
265 if err != nil {
266 t.Error(err)
267 }
268 var data int64
269 err = rb.ReadInt64(&data, byte(10), true)
270 if err != nil {
271 t.Error(err)
272 }
273 if data != math.MinInt64 {
274 t.Error("no eq.")
275 }
276}
277
278// BenchmarkUint32 benchmarks the write and read the uint32 type.
279func BenchmarkUint32(t *testing.B) {

Callers

nothing calls this directly

Calls 8

WriteHeadMethod · 0.95
WriteInt64Method · 0.95
NewBufferFunction · 0.85
rFunction · 0.85
SkipToMethod · 0.80
SkipToStructEndMethod · 0.80
ReadInt64Method · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected