@@ -5,17 +5,18 @@ import (
55
66 "google.golang.org/protobuf/encoding/protojson"
77
8- gojsondecoder "github.com/ralvarezdev/go-json/decoder"
98 goreflect "github.com/ralvarezdev/go-reflect"
9+
10+ gojsondecoder "github.com/ralvarezdev/go-json/decoder"
1011)
1112
1213type (
1314 Decoder struct {
1415 unmarshalOptions protojson.UnmarshalOptions
15- cache bool
16- cachedMappers map [string ]* Mapper
16+ cache bool
17+ cachedMappers map [string ]* Mapper
1718 }
18-
19+
1920 // Options are the additional settings for the decoder implementation
2021 Options struct {
2122 // cache indicates whether to cache the precompute unmarshal by reflection functions
@@ -24,13 +25,13 @@ type (
2425)
2526
2627// NewOptions creates a new Options instance
27- //
28+ //
2829// Parameters:
29- //
30- // - cache: indicates whether to cache the precompute unmarshal by reflection functions
31- //
30+ //
31+ // - cache: indicates whether to cache the precompute unmarshal by reflection functions
32+ //
3233// Returns:
33- //
34+ //
3435// - *Options: the new Options instance
3536func NewOptions (
3637 cache bool ,
@@ -41,10 +42,10 @@ func NewOptions(
4142}
4243
4344// NewDecoder creates a new Decoder instance
44- //
45+ //
4546// Parameters:
46- //
47- // - options: the additional settings for the decoder implementation
47+ //
48+ // - options: the additional settings for the decoder implementation
4849//
4950// Returns:
5051//
@@ -55,7 +56,7 @@ func NewDecoder(options *Options) *Decoder {
5556 if options != nil {
5657 cache = options .cache
5758 }
58-
59+
5960 // Initialize unmarshal options
6061 unmarshalOptions := protojson.UnmarshalOptions {
6162 DiscardUnknown : true ,
@@ -92,7 +93,7 @@ func (d Decoder) Decode(
9293 if err != nil {
9394 return err
9495 }
95-
96+
9697 return d .DecodeReader (parsedReader , dest )
9798}
9899
@@ -119,18 +120,18 @@ func (d Decoder) DecodeReader(
119120 if dest == nil {
120121 return gojsondecoder .ErrNilDestination
121122 }
122-
123+
123124 // Read all body from the reader
124125 body , err := io .ReadAll (reader )
125126 if err != nil {
126127 return err
127128 }
128-
129+
129130 // Check if the cache is enabled and use cached mapper if available
130- if d .cache && d .cachedMappers != nil {
131+ if d .cache && d .cachedMappers != nil {
131132 // Get the unique type identifier for the destination
132133 uniqueTypeReference := goreflect .UniqueTypeReference (dest )
133-
134+
134135 // Check if there is a cached mapper for the destination type
135136 if mapper , found := d .cachedMappers [uniqueTypeReference ]; found {
136137 return mapper .UnmarshalByReflection (
@@ -140,24 +141,24 @@ func (d Decoder) DecodeReader(
140141 )
141142 }
142143 }
143-
144+
144145 // Initialize the cache map if caching is enabled
145146 if d .cache && d .cachedMappers == nil {
146147 d .cachedMappers = make (map [string ]* Mapper )
147148 }
148-
149+
149150 // Create a new mapper for the destination type
150151 mapper , err := NewMapper (dest )
151152 if err != nil {
152153 return err
153- }
154+ }
154155
155156 // Store the mapper in the cache if caching is enabled
156157 if d .cache {
157158 uniqueTypeReference := goreflect .UniqueTypeReference (dest )
158159 d .cachedMappers [uniqueTypeReference ] = mapper
159160 }
160-
161+
161162 // Unmarshal the body into the destination using the mapper
162163 return mapper .UnmarshalByReflection (
163164 body ,
0 commit comments