1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package thrift
21
22import (
23	"bytes"
24	"context"
25	"io"
26	"math"
27	"net"
28	"net/http"
29	"testing"
30)
31
32const PROTOCOL_BINARY_DATA_SIZE = 155
33
34var (
35	protocol_bdata []byte // test data for writing; same as data
36	BOOL_VALUES    []bool
37	BYTE_VALUES    []int8
38	INT16_VALUES   []int16
39	INT32_VALUES   []int32
40	INT64_VALUES   []int64
41	DOUBLE_VALUES  []float64
42	STRING_VALUES  []string
43	UUID_VALUES    []Tuuid
44)
45
46func init() {
47	protocol_bdata = make([]byte, PROTOCOL_BINARY_DATA_SIZE)
48	for i := 0; i < PROTOCOL_BINARY_DATA_SIZE; i++ {
49		protocol_bdata[i] = byte((i + 'a') % 255)
50	}
51	BOOL_VALUES = []bool{false, true, false, false, true}
52	BYTE_VALUES = []int8{117, 0, 1, 32, 127, -128, -1}
53	INT16_VALUES = []int16{459, 0, 1, -1, -128, 127, 32767, -32768}
54	INT32_VALUES = []int32{459, 0, 1, -1, -128, 127, 32767, 2147483647, -2147483535}
55	INT64_VALUES = []int64{459, 0, 1, -1, -128, 127, 32767, 2147483647, -2147483535, 34359738481, -35184372088719, -9223372036854775808, 9223372036854775807}
56	DOUBLE_VALUES = []float64{459.3, 0.0, -1.0, 1.0, 0.5, 0.3333, 3.14159, 1.537e-38, 1.673e25, 6.02214179e23, -6.02214179e23, INFINITY.Float64(), NEGATIVE_INFINITY.Float64(), NAN.Float64()}
57	STRING_VALUES = []string{"", "a", "st[uf]f", "st,u:ff with spaces", "stuff\twith\nescape\\characters'...\"lots{of}fun</xml>"}
58	UUID_VALUES = []Tuuid{
59		{},
60		Must(ParseTuuid("6ba7b810-9dad-11d1-80b4-00c04fd430c8")),
61		Must(ParseTuuid("6ba7b811-9dad-11d1-80b4-00c04fd430c8")),
62		Must(ParseTuuid("6ba7b812-9dad-11d1-80b4-00c04fd430c8")),
63		Must(ParseTuuid("6ba7b814-9dad-11d1-80b4-00c04fd430c8")),
64	}
65}
66
67type HTTPEchoServer struct{}
68type HTTPHeaderEchoServer struct{}
69
70func (p *HTTPEchoServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
71	buf, err := io.ReadAll(req.Body)
72	if err != nil {
73		w.WriteHeader(http.StatusBadRequest)
74		w.Write(buf)
75	} else {
76		w.WriteHeader(http.StatusOK)
77		w.Write(buf)
78	}
79}
80
81func (p *HTTPHeaderEchoServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
82	buf, err := io.ReadAll(req.Body)
83	if err != nil {
84		w.WriteHeader(http.StatusBadRequest)
85		w.Write(buf)
86	} else {
87		w.WriteHeader(http.StatusOK)
88		w.Write(buf)
89	}
90}
91
92func HttpClientSetupForTest(t *testing.T) (net.Listener, net.Addr) {
93	addr, err := FindAvailableTCPServerPort(40000)
94	if err != nil {
95		t.Fatalf("Unable to find available tcp port addr: %s", err)
96		return nil, addr
97	}
98	l, err := net.Listen(addr.Network(), addr.String())
99	if err != nil {
100		t.Fatalf("Unable to setup tcp listener on %s: %s", addr.String(), err)
101		return l, addr
102	}
103	go http.Serve(l, &HTTPEchoServer{})
104	return l, addr
105}
106
107func HttpClientSetupForHeaderTest(t *testing.T) (net.Listener, net.Addr) {
108	addr, err := FindAvailableTCPServerPort(40000)
109	if err != nil {
110		t.Fatalf("Unable to find available tcp port addr: %s", err)
111		return nil, addr
112	}
113	l, err := net.Listen(addr.Network(), addr.String())
114	if err != nil {
115		t.Fatalf("Unable to setup tcp listener on %s: %s", addr.String(), err)
116		return l, addr
117	}
118	go http.Serve(l, &HTTPHeaderEchoServer{})
119	return l, addr
120}
121
122func ReadWriteProtocolTest(t *testing.T, protocolFactory TProtocolFactory) {
123	buf := bytes.NewBuffer(make([]byte, 0, 1024))
124	l, addr := HttpClientSetupForTest(t)
125	defer l.Close()
126	transports := []TTransportFactory{
127		NewTMemoryBufferTransportFactory(1024),
128		NewStreamTransportFactory(buf, buf, true),
129		NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024)),
130		NewTZlibTransportFactoryWithFactory(0, NewTMemoryBufferTransportFactory(1024)),
131		NewTZlibTransportFactoryWithFactory(6, NewTMemoryBufferTransportFactory(1024)),
132		NewTZlibTransportFactoryWithFactory(9, NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024))),
133		NewTHttpPostClientTransportFactory("http://" + addr.String()),
134	}
135	for _, tf := range transports {
136		trans, err := tf.GetTransport(nil)
137		if err != nil {
138			t.Error(err)
139			continue
140		}
141		p := protocolFactory.GetProtocol(trans)
142		ReadWriteBool(t, p, trans)
143		trans.Close()
144	}
145	for _, tf := range transports {
146		trans, err := tf.GetTransport(nil)
147		if err != nil {
148			t.Error(err)
149			continue
150		}
151		p := protocolFactory.GetProtocol(trans)
152		ReadWriteByte(t, p, trans)
153		trans.Close()
154	}
155	for _, tf := range transports {
156		trans, err := tf.GetTransport(nil)
157		if err != nil {
158			t.Error(err)
159			continue
160		}
161		p := protocolFactory.GetProtocol(trans)
162		ReadWriteI16(t, p, trans)
163		trans.Close()
164	}
165	for _, tf := range transports {
166		trans, err := tf.GetTransport(nil)
167		if err != nil {
168			t.Error(err)
169			continue
170		}
171		p := protocolFactory.GetProtocol(trans)
172		ReadWriteI32(t, p, trans)
173		trans.Close()
174	}
175	for _, tf := range transports {
176		trans, err := tf.GetTransport(nil)
177		if err != nil {
178			t.Error(err)
179			continue
180		}
181		p := protocolFactory.GetProtocol(trans)
182		ReadWriteI64(t, p, trans)
183		trans.Close()
184	}
185	for _, tf := range transports {
186		trans, err := tf.GetTransport(nil)
187		if err != nil {
188			t.Error(err)
189			continue
190		}
191		p := protocolFactory.GetProtocol(trans)
192		ReadWriteDouble(t, p, trans)
193		trans.Close()
194	}
195	for _, tf := range transports {
196		trans, err := tf.GetTransport(nil)
197		if err != nil {
198			t.Error(err)
199			continue
200		}
201		p := protocolFactory.GetProtocol(trans)
202		ReadWriteString(t, p, trans)
203		trans.Close()
204	}
205	for _, tf := range transports {
206		trans, err := tf.GetTransport(nil)
207		if err != nil {
208			t.Error(err)
209			continue
210		}
211		p := protocolFactory.GetProtocol(trans)
212		ReadWriteBinary(t, p, trans)
213		trans.Close()
214	}
215	for _, tf := range transports {
216		trans, err := tf.GetTransport(nil)
217		if err != nil {
218			t.Error(err)
219			continue
220		}
221		p := protocolFactory.GetProtocol(trans)
222		ReadWriteUUID(t, p, trans)
223		trans.Close()
224	}
225	for _, tf := range transports {
226		trans, err := tf.GetTransport(nil)
227		if err != nil {
228			t.Error(err)
229			continue
230		}
231		p := protocolFactory.GetProtocol(trans)
232		ReadWriteI64(t, p, trans)
233		ReadWriteDouble(t, p, trans)
234		ReadWriteBinary(t, p, trans)
235		ReadWriteByte(t, p, trans)
236		ReadWriteUUID(t, p, trans)
237		trans.Close()
238	}
239
240	t.Run("UnmatchedBeginEnd", func(t *testing.T) {
241		UnmatchedBeginEndProtocolTest(t, protocolFactory)
242	})
243}
244
245func ReadWriteBool(t testing.TB, p TProtocol, trans TTransport) {
246	thetype := TType(BOOL)
247	thelen := len(BOOL_VALUES)
248	err := p.WriteListBegin(context.Background(), thetype, thelen)
249	if err != nil {
250		t.Errorf("%s: %T %T %q Error writing list begin: %q", "ReadWriteBool", p, trans, err, thetype)
251	}
252	for k, v := range BOOL_VALUES {
253		err = p.WriteBool(context.Background(), v)
254		if err != nil {
255			t.Errorf("%s: %T %T %v Error writing bool in list at index %v: %v", "ReadWriteBool", p, trans, err, k, v)
256		}
257	}
258	p.WriteListEnd(context.Background())
259	if err != nil {
260		t.Errorf("%s: %T %T %v Error writing list end: %v", "ReadWriteBool", p, trans, err, BOOL_VALUES)
261	}
262	p.Flush(context.Background())
263	thetype2, thelen2, err := p.ReadListBegin(context.Background())
264	if err != nil {
265		t.Errorf("%s: %T %T %v Error reading list: %v", "ReadWriteBool", p, trans, err, BOOL_VALUES)
266	}
267	_, ok := p.(*TSimpleJSONProtocol)
268	if !ok {
269		if thetype != thetype2 {
270			t.Errorf("%s: %T %T type %s != type %s", "ReadWriteBool", p, trans, thetype, thetype2)
271		}
272		if thelen != thelen2 {
273			t.Errorf("%s: %T %T len %v != len %v", "ReadWriteBool", p, trans, thelen, thelen2)
274		}
275	}
276	for k, v := range BOOL_VALUES {
277		value, err := p.ReadBool(context.Background())
278		if err != nil {
279			t.Errorf("%s: %T %T %v Error reading bool at index %v: %v", "ReadWriteBool", p, trans, err, k, v)
280		}
281		if v != value {
282			t.Errorf("%s: index %v %v %v %v != %v", "ReadWriteBool", k, p, trans, v, value)
283		}
284	}
285	err = p.ReadListEnd(context.Background())
286	if err != nil {
287		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteBool", p, trans, err)
288	}
289}
290
291func ReadWriteByte(t testing.TB, p TProtocol, trans TTransport) {
292	thetype := TType(BYTE)
293	thelen := len(BYTE_VALUES)
294	err := p.WriteListBegin(context.Background(), thetype, thelen)
295	if err != nil {
296		t.Errorf("%s: %T %T %q Error writing list begin: %q", "ReadWriteByte", p, trans, err, thetype)
297	}
298	for k, v := range BYTE_VALUES {
299		err = p.WriteByte(context.Background(), v)
300		if err != nil {
301			t.Errorf("%s: %T %T %q Error writing byte in list at index %d: %q", "ReadWriteByte", p, trans, err, k, v)
302		}
303	}
304	err = p.WriteListEnd(context.Background())
305	if err != nil {
306		t.Errorf("%s: %T %T %q Error writing list end: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
307	}
308	err = p.Flush(context.Background())
309	if err != nil {
310		t.Errorf("%s: %T %T %q Error flushing list of bytes: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
311	}
312	thetype2, thelen2, err := p.ReadListBegin(context.Background())
313	if err != nil {
314		t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
315	}
316	_, ok := p.(*TSimpleJSONProtocol)
317	if !ok {
318		if thetype != thetype2 {
319			t.Errorf("%s: %T %T type %s != type %s", "ReadWriteByte", p, trans, thetype, thetype2)
320		}
321		if thelen != thelen2 {
322			t.Errorf("%s: %T %T len %v != len %v", "ReadWriteByte", p, trans, thelen, thelen2)
323		}
324	}
325	for k, v := range BYTE_VALUES {
326		value, err := p.ReadByte(context.Background())
327		if err != nil {
328			t.Errorf("%s: %T %T %q Error reading byte at index %d: %q", "ReadWriteByte", p, trans, err, k, v)
329		}
330		if v != value {
331			t.Errorf("%s: %T %T %d != %d", "ReadWriteByte", p, trans, v, value)
332		}
333	}
334	err = p.ReadListEnd(context.Background())
335	if err != nil {
336		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteByte", p, trans, err)
337	}
338}
339
340func ReadWriteI16(t testing.TB, p TProtocol, trans TTransport) {
341	thetype := TType(I16)
342	thelen := len(INT16_VALUES)
343	p.WriteListBegin(context.Background(), thetype, thelen)
344	for _, v := range INT16_VALUES {
345		p.WriteI16(context.Background(), v)
346	}
347	p.WriteListEnd(context.Background())
348	p.Flush(context.Background())
349	thetype2, thelen2, err := p.ReadListBegin(context.Background())
350	if err != nil {
351		t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI16", p, trans, err, INT16_VALUES)
352	}
353	_, ok := p.(*TSimpleJSONProtocol)
354	if !ok {
355		if thetype != thetype2 {
356			t.Errorf("%s: %T %T type %s != type %s", "ReadWriteI16", p, trans, thetype, thetype2)
357		}
358		if thelen != thelen2 {
359			t.Errorf("%s: %T %T len %v != len %v", "ReadWriteI16", p, trans, thelen, thelen2)
360		}
361	}
362	for k, v := range INT16_VALUES {
363		value, err := p.ReadI16(context.Background())
364		if err != nil {
365			t.Errorf("%s: %T %T %q Error reading int16 at index %d: %q", "ReadWriteI16", p, trans, err, k, v)
366		}
367		if v != value {
368			t.Errorf("%s: %T %T %d != %d", "ReadWriteI16", p, trans, v, value)
369		}
370	}
371	err = p.ReadListEnd(context.Background())
372	if err != nil {
373		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteI16", p, trans, err)
374	}
375}
376
377func ReadWriteI32(t testing.TB, p TProtocol, trans TTransport) {
378	thetype := TType(I32)
379	thelen := len(INT32_VALUES)
380	p.WriteListBegin(context.Background(), thetype, thelen)
381	for _, v := range INT32_VALUES {
382		p.WriteI32(context.Background(), v)
383	}
384	p.WriteListEnd(context.Background())
385	p.Flush(context.Background())
386	thetype2, thelen2, err := p.ReadListBegin(context.Background())
387	if err != nil {
388		t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI32", p, trans, err, INT32_VALUES)
389	}
390	_, ok := p.(*TSimpleJSONProtocol)
391	if !ok {
392		if thetype != thetype2 {
393			t.Errorf("%s: %T %T type %s != type %s", "ReadWriteI32", p, trans, thetype, thetype2)
394		}
395		if thelen != thelen2 {
396			t.Errorf("%s: %T %T len %v != len %v", "ReadWriteI32", p, trans, thelen, thelen2)
397		}
398	}
399	for k, v := range INT32_VALUES {
400		value, err := p.ReadI32(context.Background())
401		if err != nil {
402			t.Errorf("%s: %T %T %q Error reading int32 at index %d: %q", "ReadWriteI32", p, trans, err, k, v)
403		}
404		if v != value {
405			t.Errorf("%s: %T %T %d != %d", "ReadWriteI32", p, trans, v, value)
406		}
407	}
408	if err != nil {
409		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteI32", p, trans, err)
410	}
411}
412
413func ReadWriteI64(t testing.TB, p TProtocol, trans TTransport) {
414	thetype := TType(I64)
415	thelen := len(INT64_VALUES)
416	p.WriteListBegin(context.Background(), thetype, thelen)
417	for _, v := range INT64_VALUES {
418		p.WriteI64(context.Background(), v)
419	}
420	p.WriteListEnd(context.Background())
421	p.Flush(context.Background())
422	thetype2, thelen2, err := p.ReadListBegin(context.Background())
423	if err != nil {
424		t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI64", p, trans, err, INT64_VALUES)
425	}
426	_, ok := p.(*TSimpleJSONProtocol)
427	if !ok {
428		if thetype != thetype2 {
429			t.Errorf("%s: %T %T type %s != type %s", "ReadWriteI64", p, trans, thetype, thetype2)
430		}
431		if thelen != thelen2 {
432			t.Errorf("%s: %T %T len %v != len %v", "ReadWriteI64", p, trans, thelen, thelen2)
433		}
434	}
435	for k, v := range INT64_VALUES {
436		value, err := p.ReadI64(context.Background())
437		if err != nil {
438			t.Errorf("%s: %T %T %q Error reading int64 at index %d: %q", "ReadWriteI64", p, trans, err, k, v)
439		}
440		if v != value {
441			t.Errorf("%s: %T %T %q != %q", "ReadWriteI64", p, trans, v, value)
442		}
443	}
444	if err != nil {
445		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteI64", p, trans, err)
446	}
447}
448
449func ReadWriteDouble(t testing.TB, p TProtocol, trans TTransport) {
450	thetype := TType(DOUBLE)
451	thelen := len(DOUBLE_VALUES)
452	p.WriteListBegin(context.Background(), thetype, thelen)
453	for _, v := range DOUBLE_VALUES {
454		p.WriteDouble(context.Background(), v)
455	}
456	p.WriteListEnd(context.Background())
457	p.Flush(context.Background())
458	thetype2, thelen2, err := p.ReadListBegin(context.Background())
459	if err != nil {
460		t.Errorf("%s: %T %T %v Error reading list: %v", "ReadWriteDouble", p, trans, err, DOUBLE_VALUES)
461	}
462	if thetype != thetype2 {
463		t.Errorf("%s: %T %T type %s != type %s", "ReadWriteDouble", p, trans, thetype, thetype2)
464	}
465	if thelen != thelen2 {
466		t.Errorf("%s: %T %T len %v != len %v", "ReadWriteDouble", p, trans, thelen, thelen2)
467	}
468	for k, v := range DOUBLE_VALUES {
469		value, err := p.ReadDouble(context.Background())
470		if err != nil {
471			t.Errorf("%s: %T %T %q Error reading double at index %d: %v", "ReadWriteDouble", p, trans, err, k, v)
472		}
473		if math.IsNaN(v) {
474			if !math.IsNaN(value) {
475				t.Errorf("%s: %T %T math.IsNaN(%v) != math.IsNaN(%v)", "ReadWriteDouble", p, trans, v, value)
476			}
477		} else if v != value {
478			t.Errorf("%s: %T %T %v != %v", "ReadWriteDouble", p, trans, v, value)
479		}
480	}
481	err = p.ReadListEnd(context.Background())
482	if err != nil {
483		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteDouble", p, trans, err)
484	}
485}
486
487func ReadWriteString(t testing.TB, p TProtocol, trans TTransport) {
488	thetype := TType(STRING)
489	thelen := len(STRING_VALUES)
490	p.WriteListBegin(context.Background(), thetype, thelen)
491	for _, v := range STRING_VALUES {
492		p.WriteString(context.Background(), v)
493	}
494	p.WriteListEnd(context.Background())
495	p.Flush(context.Background())
496	thetype2, thelen2, err := p.ReadListBegin(context.Background())
497	if err != nil {
498		t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteString", p, trans, err, STRING_VALUES)
499	}
500	_, ok := p.(*TSimpleJSONProtocol)
501	if !ok {
502		if thetype != thetype2 {
503			t.Errorf("%s: %T %T type %s != type %s", "ReadWriteString", p, trans, thetype, thetype2)
504		}
505		if thelen != thelen2 {
506			t.Errorf("%s: %T %T len %v != len %v", "ReadWriteString", p, trans, thelen, thelen2)
507		}
508	}
509	for k, v := range STRING_VALUES {
510		value, err := p.ReadString(context.Background())
511		if err != nil {
512			t.Errorf("%s: %T %T %q Error reading string at index %d: %q", "ReadWriteString", p, trans, err, k, v)
513		}
514		if v != value {
515			t.Errorf("%s: %T %T %v != %v", "ReadWriteString", p, trans, v, value)
516		}
517	}
518	if err != nil {
519		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteString", p, trans, err)
520	}
521}
522
523func ReadWriteBinary(t testing.TB, p TProtocol, trans TTransport) {
524	v := protocol_bdata
525	p.WriteBinary(context.Background(), v)
526	p.Flush(context.Background())
527	value, err := p.ReadBinary(context.Background())
528	if err != nil {
529		t.Errorf("%s: %T %T Unable to read binary: %s", "ReadWriteBinary", p, trans, err.Error())
530	}
531	if len(v) != len(value) {
532		t.Errorf("%s: %T %T len(v) != len(value)... %d != %d", "ReadWriteBinary", p, trans, len(v), len(value))
533	} else {
534		for i := 0; i < len(v); i++ {
535			if v[i] != value[i] {
536				t.Errorf("%s: %T %T %s != %s", "ReadWriteBinary", p, trans, v, value)
537			}
538		}
539	}
540}
541
542func ReadWriteUUID(t testing.TB, p TProtocol, trans TTransport) {
543	ctx := context.Background()
544	thetype := TType(UUID)
545	thelen := len(UUID_VALUES)
546	p.WriteListBegin(ctx, thetype, thelen)
547	for _, v := range UUID_VALUES {
548		p.WriteUUID(ctx, v)
549	}
550	p.WriteListEnd(ctx)
551	p.Flush(ctx)
552	thetype2, thelen2, err := p.ReadListBegin(ctx)
553	if err != nil {
554		t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteUUID", p, trans, err, STRING_VALUES)
555	}
556	_, ok := p.(*TSimpleJSONProtocol)
557	if !ok {
558		if thetype != thetype2 {
559			t.Errorf("%s: %T %T type %s != type %s", "ReadWriteUUID", p, trans, thetype, thetype2)
560		}
561		if thelen != thelen2 {
562			t.Errorf("%s: %T %T len %v != len %v", "ReadWriteUUID", p, trans, thelen, thelen2)
563		}
564	}
565	for k, v := range UUID_VALUES {
566		value, err := p.ReadUUID(ctx)
567		if err != nil {
568			t.Errorf("%s: %T %T %q Error reading UUID at index %d: %q", "ReadWriteUUID", p, trans, err, k, v)
569		}
570		if v != value {
571			t.Errorf("%s: %T %T %v != %v", "ReadWriteUUID", p, trans, v, value)
572		}
573	}
574	if err != nil {
575		t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteUUID", p, trans, err)
576	}
577}
578
579func UnmatchedBeginEndProtocolTest(t *testing.T, protocolFactory TProtocolFactory) {
580	// NOTE: not all protocol implementations do strict state check to
581	// return an error on unmatched Begin/End calls.
582	// This test is only meant to make sure that those unmatched Begin/End
583	// calls won't cause panic. There's no real "test" here.
584	trans := NewTMemoryBuffer()
585	t.Run("Read", func(t *testing.T) {
586		t.Run("Message", func(t *testing.T) {
587			trans.Reset()
588			p := protocolFactory.GetProtocol(trans)
589			p.ReadMessageEnd(context.Background())
590			p.ReadMessageEnd(context.Background())
591		})
592		t.Run("Struct", func(t *testing.T) {
593			trans.Reset()
594			p := protocolFactory.GetProtocol(trans)
595			p.ReadStructEnd(context.Background())
596			p.ReadStructEnd(context.Background())
597		})
598		t.Run("Field", func(t *testing.T) {
599			trans.Reset()
600			p := protocolFactory.GetProtocol(trans)
601			p.ReadFieldEnd(context.Background())
602			p.ReadFieldEnd(context.Background())
603		})
604		t.Run("Map", func(t *testing.T) {
605			trans.Reset()
606			p := protocolFactory.GetProtocol(trans)
607			p.ReadMapEnd(context.Background())
608			p.ReadMapEnd(context.Background())
609		})
610		t.Run("List", func(t *testing.T) {
611			trans.Reset()
612			p := protocolFactory.GetProtocol(trans)
613			p.ReadListEnd(context.Background())
614			p.ReadListEnd(context.Background())
615		})
616		t.Run("Set", func(t *testing.T) {
617			trans.Reset()
618			p := protocolFactory.GetProtocol(trans)
619			p.ReadSetEnd(context.Background())
620			p.ReadSetEnd(context.Background())
621		})
622	})
623	t.Run("Write", func(t *testing.T) {
624		t.Run("Message", func(t *testing.T) {
625			trans.Reset()
626			p := protocolFactory.GetProtocol(trans)
627			p.WriteMessageEnd(context.Background())
628			p.WriteMessageEnd(context.Background())
629		})
630		t.Run("Struct", func(t *testing.T) {
631			trans.Reset()
632			p := protocolFactory.GetProtocol(trans)
633			p.WriteStructEnd(context.Background())
634			p.WriteStructEnd(context.Background())
635		})
636		t.Run("Field", func(t *testing.T) {
637			trans.Reset()
638			p := protocolFactory.GetProtocol(trans)
639			p.WriteFieldEnd(context.Background())
640			p.WriteFieldEnd(context.Background())
641		})
642		t.Run("Map", func(t *testing.T) {
643			trans.Reset()
644			p := protocolFactory.GetProtocol(trans)
645			p.WriteMapEnd(context.Background())
646			p.WriteMapEnd(context.Background())
647		})
648		t.Run("List", func(t *testing.T) {
649			trans.Reset()
650			p := protocolFactory.GetProtocol(trans)
651			p.WriteListEnd(context.Background())
652			p.WriteListEnd(context.Background())
653		})
654		t.Run("Set", func(t *testing.T) {
655			trans.Reset()
656			p := protocolFactory.GetProtocol(trans)
657			p.WriteSetEnd(context.Background())
658			p.WriteSetEnd(context.Background())
659		})
660	})
661	trans.Close()
662}
663