github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/internal/decoder/types.go (about)

     1  /*
     2   * Copyright 2021 ByteDance Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package decoder
    18  
    19  import (
    20  	"encoding"
    21  	"encoding/base64"
    22  	"encoding/json"
    23  	"reflect"
    24  	"unsafe"
    25  
    26  	"github.com/goshafaq/sonic/internal/rt"
    27  )
    28  
    29  var (
    30  	byteType                = reflect.TypeOf(byte(0))
    31  	intType                 = reflect.TypeOf(int(0))
    32  	int8Type                = reflect.TypeOf(int8(0))
    33  	int16Type               = reflect.TypeOf(int16(0))
    34  	int32Type               = reflect.TypeOf(int32(0))
    35  	int64Type               = reflect.TypeOf(int64(0))
    36  	uintType                = reflect.TypeOf(uint(0))
    37  	uint8Type               = reflect.TypeOf(uint8(0))
    38  	uint16Type              = reflect.TypeOf(uint16(0))
    39  	uint32Type              = reflect.TypeOf(uint32(0))
    40  	uint64Type              = reflect.TypeOf(uint64(0))
    41  	float32Type             = reflect.TypeOf(float32(0))
    42  	float64Type             = reflect.TypeOf(float64(0))
    43  	stringType              = reflect.TypeOf("")
    44  	bytesType               = reflect.TypeOf([]byte(nil))
    45  	jsonNumberType          = reflect.TypeOf(json.Number(""))
    46  	base64CorruptInputError = reflect.TypeOf(base64.CorruptInputError(0))
    47  )
    48  
    49  var (
    50  	errorType                   = reflect.TypeOf((*error)(nil)).Elem()
    51  	jsonUnmarshalerType         = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()
    52  	encodingTextUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
    53  )
    54  
    55  func rtype(t reflect.Type) (*rt.GoItab, *rt.GoType) {
    56  	p := (*rt.GoIface)(unsafe.Pointer(&t))
    57  	return p.Itab, (*rt.GoType)(p.Value)
    58  }