github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/test/api/binding_test.go (about)

     1  package test
     2  
     3  import (
     4  	"github.com/apache/thrift/lib/go/thrift"
     5  	"github.com/batchcorp/thrift-iterator/test/api/binding_test"
     6  	"github.com/stretchr/testify/require"
     7  	"testing"
     8  )
     9  
    10  func Test_binding(t *testing.T) {
    11  	should := require.New(t)
    12  	buf := thrift.NewTMemoryBuffer()
    13  	transport := thrift.NewTFramedTransport(buf)
    14  	proto := thrift.NewTBinaryProtocol(transport, true, true)
    15  	proto.WriteStructBegin("hello")
    16  	proto.WriteFieldBegin("field1", thrift.I64, 1)
    17  	proto.WriteI64(1024)
    18  	proto.WriteFieldEnd()
    19  	proto.WriteFieldStop()
    20  	proto.WriteStructEnd()
    21  	transport.Flush()
    22  	var val binding_test.TestObject
    23  	should.NoError(api.Unmarshal(buf.Bytes()[4:], &val))
    24  	should.Equal(int64(1024), val.Field1)
    25  }