diff options
| author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
| commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
| tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/json-iterator/go/reflect_json_raw_message.go | |
| parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
| download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip | |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/json-iterator/go/reflect_json_raw_message.go')
| -rw-r--r-- | vendor/github.com/json-iterator/go/reflect_json_raw_message.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/vendor/github.com/json-iterator/go/reflect_json_raw_message.go b/vendor/github.com/json-iterator/go/reflect_json_raw_message.go new file mode 100644 index 0000000..eba434f --- /dev/null +++ b/vendor/github.com/json-iterator/go/reflect_json_raw_message.go | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | package jsoniter | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "encoding/json" | ||
| 5 | "github.com/modern-go/reflect2" | ||
| 6 | "unsafe" | ||
| 7 | ) | ||
| 8 | |||
| 9 | var jsonRawMessageType = reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem() | ||
| 10 | var jsoniterRawMessageType = reflect2.TypeOfPtr((*RawMessage)(nil)).Elem() | ||
| 11 | |||
| 12 | func createEncoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
| 13 | if typ == jsonRawMessageType { | ||
| 14 | return &jsonRawMessageCodec{} | ||
| 15 | } | ||
| 16 | if typ == jsoniterRawMessageType { | ||
| 17 | return &jsoniterRawMessageCodec{} | ||
| 18 | } | ||
| 19 | return nil | ||
| 20 | } | ||
| 21 | |||
| 22 | func createDecoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
| 23 | if typ == jsonRawMessageType { | ||
| 24 | return &jsonRawMessageCodec{} | ||
| 25 | } | ||
| 26 | if typ == jsoniterRawMessageType { | ||
| 27 | return &jsoniterRawMessageCodec{} | ||
| 28 | } | ||
| 29 | return nil | ||
| 30 | } | ||
| 31 | |||
| 32 | type jsonRawMessageCodec struct { | ||
| 33 | } | ||
| 34 | |||
| 35 | func (codec *jsonRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
| 36 | if iter.ReadNil() { | ||
| 37 | *((*json.RawMessage)(ptr)) = nil | ||
| 38 | } else { | ||
| 39 | *((*json.RawMessage)(ptr)) = iter.SkipAndReturnBytes() | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | func (codec *jsonRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
| 44 | if *((*json.RawMessage)(ptr)) == nil { | ||
| 45 | stream.WriteNil() | ||
| 46 | } else { | ||
| 47 | stream.WriteRaw(string(*((*json.RawMessage)(ptr)))) | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | func (codec *jsonRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
| 52 | return len(*((*json.RawMessage)(ptr))) == 0 | ||
| 53 | } | ||
| 54 | |||
| 55 | type jsoniterRawMessageCodec struct { | ||
| 56 | } | ||
| 57 | |||
| 58 | func (codec *jsoniterRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
| 59 | if iter.ReadNil() { | ||
| 60 | *((*RawMessage)(ptr)) = nil | ||
| 61 | } else { | ||
| 62 | *((*RawMessage)(ptr)) = iter.SkipAndReturnBytes() | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | func (codec *jsoniterRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
| 67 | if *((*RawMessage)(ptr)) == nil { | ||
| 68 | stream.WriteNil() | ||
| 69 | } else { | ||
| 70 | stream.WriteRaw(string(*((*RawMessage)(ptr)))) | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | func (codec *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
| 75 | return len(*((*RawMessage)(ptr))) == 0 | ||
| 76 | } | ||