@@ -117,6 +117,21 @@ func decodeStreamUnmarshaler(s *Stream, depth int64, unmarshaler json.Unmarshale
117
117
return nil
118
118
}
119
119
120
+ func decodeStreamUnmarshalerContext (s * Stream , depth int64 , unmarshaler unmarshalerContext ) error {
121
+ start := s .cursor
122
+ if err := s .skipValue (depth ); err != nil {
123
+ return err
124
+ }
125
+ src := s .buf [start :s .cursor ]
126
+ dst := make ([]byte , len (src ))
127
+ copy (dst , src )
128
+
129
+ if err := unmarshaler .UnmarshalJSON (s .Option .Context , dst ); err != nil {
130
+ return err
131
+ }
132
+ return nil
133
+ }
134
+
120
135
func decodeUnmarshaler (buf []byte , cursor , depth int64 , unmarshaler json.Unmarshaler ) (int64 , error ) {
121
136
cursor = skipWhiteSpace (buf , cursor )
122
137
start := cursor
@@ -134,6 +149,23 @@ func decodeUnmarshaler(buf []byte, cursor, depth int64, unmarshaler json.Unmarsh
134
149
return end , nil
135
150
}
136
151
152
+ func decodeUnmarshalerContext (ctx * RuntimeContext , buf []byte , cursor , depth int64 , unmarshaler unmarshalerContext ) (int64 , error ) {
153
+ cursor = skipWhiteSpace (buf , cursor )
154
+ start := cursor
155
+ end , err := skipValue (buf , cursor , depth )
156
+ if err != nil {
157
+ return 0 , err
158
+ }
159
+ src := buf [start :end ]
160
+ dst := make ([]byte , len (src ))
161
+ copy (dst , src )
162
+
163
+ if err := unmarshaler .UnmarshalJSON (ctx .Option .Context , dst ); err != nil {
164
+ return 0 , err
165
+ }
166
+ return end , nil
167
+ }
168
+
137
169
func decodeStreamTextUnmarshaler (s * Stream , depth int64 , unmarshaler encoding.TextUnmarshaler , p unsafe.Pointer ) error {
138
170
start := s .cursor
139
171
if err := s .skipValue (depth ); err != nil {
@@ -260,6 +292,9 @@ func (d *interfaceDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer
260
292
}))
261
293
rv := reflect .ValueOf (runtimeInterfaceValue )
262
294
if rv .NumMethod () > 0 && rv .CanInterface () {
295
+ if u , ok := rv .Interface ().(unmarshalerContext ); ok {
296
+ return decodeStreamUnmarshalerContext (s , depth , u )
297
+ }
263
298
if u , ok := rv .Interface ().(json.Unmarshaler ); ok {
264
299
return decodeStreamUnmarshaler (s , depth , u )
265
300
}
@@ -317,6 +352,9 @@ func (d *interfaceDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p un
317
352
}))
318
353
rv := reflect .ValueOf (runtimeInterfaceValue )
319
354
if rv .NumMethod () > 0 && rv .CanInterface () {
355
+ if u , ok := rv .Interface ().(unmarshalerContext ); ok {
356
+ return decodeUnmarshalerContext (ctx , buf , cursor , depth , u )
357
+ }
320
358
if u , ok := rv .Interface ().(json.Unmarshaler ); ok {
321
359
return decodeUnmarshaler (buf , cursor , depth , u )
322
360
}
0 commit comments