github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/binding/reflection/encode_simple_value.go (about)

     1  package reflection
     2  
     3  import (
     4  	"unsafe"
     5  	"github.com/batchcorp/thrift-iterator/spi"
     6  	"github.com/batchcorp/thrift-iterator/protocol"
     7  )
     8  
     9  type binaryEncoder struct {
    10  }
    11  
    12  func (encoder *binaryEncoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    13  	iter.WriteBinary(*(*[]byte)(ptr))
    14  }
    15  
    16  func (encoder *binaryEncoder) thriftType() protocol.TType {
    17  	return protocol.TypeString
    18  }
    19  
    20  type stringEncoder struct {
    21  }
    22  
    23  func (encoder *stringEncoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    24  	iter.WriteString(*(*string)(ptr))
    25  }
    26  
    27  func (encoder *stringEncoder) thriftType() protocol.TType {
    28  	return protocol.TypeString
    29  }
    30  
    31  type boolEncoder struct {
    32  }
    33  
    34  func (encoder *boolEncoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    35  	iter.WriteBool(*(*bool)(ptr))
    36  }
    37  
    38  func (encoder *boolEncoder) thriftType() protocol.TType {
    39  	return protocol.TypeBool
    40  }
    41  
    42  type int8Encoder struct {
    43  }
    44  
    45  func (encoder *int8Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    46  	iter.WriteInt8(*(*int8)(ptr))
    47  }
    48  
    49  func (encoder *int8Encoder) thriftType() protocol.TType {
    50  	return protocol.TypeI08
    51  }
    52  
    53  type uint8Encoder struct {
    54  }
    55  
    56  func (encoder *uint8Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    57  	iter.WriteUint8(*(*uint8)(ptr))
    58  }
    59  
    60  func (encoder *uint8Encoder) thriftType() protocol.TType {
    61  	return protocol.TypeI08
    62  }
    63  
    64  type int16Encoder struct {
    65  }
    66  
    67  func (encoder *int16Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    68  	iter.WriteInt16(*(*int16)(ptr))
    69  }
    70  
    71  func (encoder *int16Encoder) thriftType() protocol.TType {
    72  	return protocol.TypeI16
    73  }
    74  
    75  type uint16Encoder struct {
    76  }
    77  
    78  func (encoder *uint16Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    79  	iter.WriteUint16(*(*uint16)(ptr))
    80  }
    81  
    82  func (encoder *uint16Encoder) thriftType() protocol.TType {
    83  	return protocol.TypeI16
    84  }
    85  
    86  type int32Encoder struct {
    87  }
    88  
    89  func (encoder *int32Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
    90  	iter.WriteInt32(*(*int32)(ptr))
    91  }
    92  
    93  func (encoder *int32Encoder) thriftType() protocol.TType {
    94  	return protocol.TypeI32
    95  }
    96  
    97  type uint32Encoder struct {
    98  }
    99  
   100  func (encoder *uint32Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
   101  	iter.WriteUint32(*(*uint32)(ptr))
   102  }
   103  
   104  func (encoder *uint32Encoder) thriftType() protocol.TType {
   105  	return protocol.TypeI32
   106  }
   107  
   108  type int64Encoder struct {
   109  }
   110  
   111  func (encoder *int64Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
   112  	iter.WriteInt64(*(*int64)(ptr))
   113  }
   114  
   115  func (encoder *int64Encoder) thriftType() protocol.TType {
   116  	return protocol.TypeI64
   117  }
   118  
   119  type uint64Encoder struct {
   120  }
   121  
   122  func (encoder *uint64Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
   123  	iter.WriteUint64(*(*uint64)(ptr))
   124  }
   125  
   126  func (encoder *uint64Encoder) thriftType() protocol.TType {
   127  	return protocol.TypeI64
   128  }
   129  
   130  type intEncoder struct {
   131  }
   132  
   133  func (encoder *intEncoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
   134  	iter.WriteInt(*(*int)(ptr))
   135  }
   136  
   137  func (encoder *intEncoder) thriftType() protocol.TType {
   138  	return protocol.TypeI64
   139  }
   140  
   141  type uintEncoder struct {
   142  }
   143  
   144  func (encoder *uintEncoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
   145  	iter.WriteUint(*(*uint)(ptr))
   146  }
   147  
   148  func (encoder *uintEncoder) thriftType() protocol.TType {
   149  	return protocol.TypeI64
   150  }
   151  
   152  type float64Encoder struct {
   153  }
   154  
   155  func (encoder *float64Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
   156  	iter.WriteFloat64(*(*float64)(ptr))
   157  }
   158  
   159  func (encoder *float64Encoder) thriftType() protocol.TType {
   160  	return protocol.TypeDouble
   161  }
   162  
   163  type float32Encoder struct {
   164  }
   165  
   166  func (encoder *float32Encoder) encode(ptr unsafe.Pointer, iter spi.Stream) {
   167  	iter.WriteFloat64(float64(*(*float32)(ptr)))
   168  }
   169  
   170  func (encoder *float32Encoder) thriftType() protocol.TType {
   171  	return protocol.TypeDouble
   172  }