git.lukeshu.com/go/lowmemjson@v0.3.9-0.20230723050957-72f6d13f6fb2/external.go (about)

     1  // Copyright (C) 2022-2023  Luke Shumaker <lukeshu@lukeshu.com>
     2  //
     3  // SPDX-License-Identifier: GPL-2.0-or-later
     4  
     5  package lowmemjson
     6  
     7  import (
     8  	"encoding"
     9  	"encoding/json"
    10  	"reflect"
    11  )
    12  
    13  // A Number represents a JSON number value.  It is represented as a
    14  // string containing the raw JSON text; it is useful for preserving
    15  // number values with perfect fidelity, but isn't so useful for use as
    16  // a number value in a Go program.
    17  type Number = json.Number
    18  
    19  // A RawMessage is a raw encoded JSON value.  This saves time when
    20  // encoding or decoding, but does mean that the full text must be
    21  // buffered when decoding.
    22  type RawMessage = json.RawMessage
    23  
    24  type (
    25  	jsonMarshaler   = json.Marshaler
    26  	jsonUnmarshaler = json.Unmarshaler
    27  )
    28  
    29  var (
    30  	// common types.
    31  	numberType    = reflect.TypeOf(Number(""))
    32  	byteType      = reflect.TypeOf(byte(0))
    33  	byteSliceType = reflect.TypeOf(([]byte)(nil))
    34  
    35  	// encodable/marshaler types.
    36  	encodableType     = reflect.TypeOf((*Encodable)(nil)).Elem()
    37  	jsonMarshalerType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
    38  	textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
    39  
    40  	// decodable/unmarshaler types.
    41  	decodableType       = reflect.TypeOf((*Decodable)(nil)).Elem()
    42  	jsonUnmarshalerType = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()
    43  	textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
    44  
    45  	// other types used by Decoder.
    46  	rawMessagePtrType = reflect.TypeOf((*json.RawMessage)(nil))
    47  	float64Type       = reflect.TypeOf(float64(0))
    48  )