github.com/batchcorp/thrift-iterator@v0.0.0-20220918180557-4c4a158fc6e9/general/decode.go (about)

     1  package general
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/batchcorp/thrift-iterator/protocol"
     7  	"github.com/batchcorp/thrift-iterator/spi"
     8  )
     9  
    10  func generalReaderOf(ttype protocol.TType) func(iter spi.Iterator) interface{} {
    11  	switch ttype {
    12  	case protocol.TypeBool:
    13  		return readBool
    14  	case protocol.TypeI08:
    15  		return readInt8
    16  	case protocol.TypeI16:
    17  		return readInt16
    18  	case protocol.TypeI32:
    19  		return readInt32
    20  	case protocol.TypeI64:
    21  		return readInt64
    22  	case protocol.TypeString:
    23  		return readString
    24  	case protocol.TypeDouble:
    25  		return readFloat64
    26  	case protocol.TypeList:
    27  		return readList
    28  	case protocol.TypeMap:
    29  		return readMap
    30  	case protocol.TypeStruct:
    31  		return readStruct
    32  	case protocol.TypeSet:
    33  		return readList
    34  	default:
    35  		panic(fmt.Sprintf("unsupported type: %d", ttype))
    36  	}
    37  }
    38  
    39  func readFloat64(iter spi.Iterator) interface{} {
    40  	return iter.ReadFloat64()
    41  }
    42  
    43  func readBool(iter spi.Iterator) interface{} {
    44  	return iter.ReadBool()
    45  }
    46  
    47  func readInt8(iter spi.Iterator) interface{} {
    48  	return iter.ReadInt8()
    49  }
    50  
    51  func readInt16(iter spi.Iterator) interface{} {
    52  	return iter.ReadInt16()
    53  }
    54  
    55  func readInt32(iter spi.Iterator) interface{} {
    56  	return iter.ReadInt32()
    57  }
    58  
    59  func readInt64(iter spi.Iterator) interface{} {
    60  	return iter.ReadInt64()
    61  }
    62  
    63  func readString(iter spi.Iterator) interface{} {
    64  	return iter.ReadString()
    65  }