summaryrefslogtreecommitdiff
path: root/external.go
blob: c8a1f68de690533b986cedf3a98a7f359187ae74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2022-2023  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package lowmemjson

import (
	"encoding"
	"encoding/json"
	"reflect"
)

// A Number represents a JSON number value.  It is represented as a
// string containing the raw JSON text; it is useful for preserving
// number values with perfect fidelity, but isn't so useful for use as
// a number value in a Go program.
type Number = json.Number

// A RawMessage is a raw encoded JSON value.  This saves time when
// encoding or decoding, but does mean that the full text must be
// buffered when decoding.
type RawMessage = json.RawMessage

type (
	jsonMarshaler   = json.Marshaler
	jsonUnmarshaler = json.Unmarshaler
)

var (
	// common types.
	numberType    = reflect.TypeOf(Number(""))
	byteType      = reflect.TypeOf(byte(0))
	byteSliceType = reflect.TypeOf(([]byte)(nil))

	// encodable/marshaler types.
	encodableType     = reflect.TypeOf((*Encodable)(nil)).Elem()
	jsonMarshalerType = reflect.TypeOf((*json.Marshaler)(nil)).Elem()
	textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()

	// decodable/unmarshaler types.
	decodableType       = reflect.TypeOf((*Decodable)(nil)).Elem()
	jsonUnmarshalerType = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()
	textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()

	// other types used by Decoder.
	rawMessagePtrType = reflect.TypeOf((*json.RawMessage)(nil))
	float64Type       = reflect.TypeOf(float64(0))
)