forked from moov-io/iso8583
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.go
More file actions
814 lines (657 loc) · 20 KB
/
message.go
File metadata and controls
814 lines (657 loc) · 20 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
package iso8583
import (
"encoding/json"
"errors"
"fmt"
"maps"
"reflect"
"slices"
"strconv"
"strings"
"sync"
iso8583errors "github.com/moov-io/iso8583/errors"
"github.com/moov-io/iso8583/field"
"github.com/moov-io/iso8583/utils"
)
var _ json.Marshaler = (*Message)(nil)
var _ json.Unmarshaler = (*Message)(nil)
const (
mtiIdx = 0
bitmapIdx = 1
)
type Message struct {
spec *MessageSpec
cachedBitmap *field.Bitmap
// to guard fields
mu sync.Mutex
// stores all fields according to the spec
fields map[int]field.Field
}
func NewMessage(spec *MessageSpec) *Message {
// Validate the spec
if err := spec.Validate(); err != nil {
panic(err) //nolint:forbidigo,nolintlint // as specs moslty static, we panic on spec validation errors
}
return &Message{
fields: make(map[int]field.Field),
spec: spec,
}
}
// Deprecated. Use Marshal instead.
func (m *Message) SetData(data any) error {
return m.Marshal(data)
}
func (m *Message) Bitmap() *field.Bitmap {
m.mu.Lock()
defer m.mu.Unlock()
return m.bitmap()
}
// bitmap creates and returns the bitmap field, it's not thread safe
// and should be called from a thread safe function
func (m *Message) bitmap() *field.Bitmap {
if m.cachedBitmap != nil {
return m.cachedBitmap
}
// presence and type of m.spec.Fields[bitmapIdx] was validated in NewMessage
//nolint:forcetypeassert
bitmap := field.NewInstanceOf(m.spec.Fields[bitmapIdx]).(*field.Bitmap)
m.fields[bitmapIdx] = bitmap
bitmap.Reset()
m.cachedBitmap = bitmap
return m.cachedBitmap
}
func (m *Message) resetBitmap() {
m.fields[bitmapIdx] = m.bitmap()
m.bitmap().Reset()
}
func (m *Message) MTI(val string) {
m.mu.Lock()
defer m.mu.Unlock()
mti, err := m.getOrCreateField(mtiIdx)
if err != nil {
panic(fmt.Sprintf("required MTI field is missing: %v", err)) //nolint:forbidigo,nolintlint // as specs mostly static, we panic on spec validation errors
}
mti.SetBytes([]byte(val))
}
func (m *Message) GetSpec() *MessageSpec {
return m.spec
}
func (m *Message) Field(id int, val string) error {
m.mu.Lock()
defer m.mu.Unlock()
field, err := m.getOrCreateField(id)
if err != nil {
return fmt.Errorf("getting or creating field %d: %w", id, err)
}
err = field.SetBytes([]byte(val))
if err != nil {
return fmt.Errorf("setting bytes for field %d: %w", id, err)
}
return nil
}
func (m *Message) BinaryField(id int, val []byte) error {
m.mu.Lock()
defer m.mu.Unlock()
field, err := m.getOrCreateField(id)
if err != nil {
return fmt.Errorf("getting or creating field %d: %w", id, err)
}
err = field.SetBytes(val)
if err != nil {
return fmt.Errorf("setting bytes for field %d: %w", id, err)
}
return nil
}
// GetMTI returns the Message Type Indicator (MTI) of the message. It returns
// an empty string if the MTI field is not set.
func (m *Message) GetMTI() (string, error) {
return m.GetString(mtiIdx)
}
// GetString returns the string representation of the field with the given ID.
// If the field does not exist in the message, an empty value will be returned. If
// the field ID is not defined in the specification, an error will be returned.
func (m *Message) GetString(id int) (string, error) {
m.mu.Lock()
defer m.mu.Unlock()
field, err := m.getField(id)
if err != nil {
return "", err
}
if field == nil {
return "", nil
}
str, err := field.String()
if err != nil {
return "", fmt.Errorf("getting string for field %d: %w", id, err)
}
return str, nil
}
// GetBytes returns the byte slice representation of the field with the given ID.
// If the field does not exist in the message, nil will be returned. If the field ID
// is not defined in the specification, an error will be returned.
func (m *Message) GetBytes(id int) ([]byte, error) {
m.mu.Lock()
defer m.mu.Unlock()
field, err := m.getField(id)
if err != nil {
return nil, err
}
if field == nil {
return nil, nil
}
bytes, err := field.Bytes()
if err != nil {
return nil, fmt.Errorf("getting bytes for field %d: %w", id, err)
}
return bytes, nil
}
// GetField returns the field with the given ID, or nil if the field is not set
// or not defined in the specification.
func (m *Message) GetField(id int) field.Field {
m.mu.Lock()
defer m.mu.Unlock()
field, _ := m.getField(id)
return field
}
func (m *Message) getField(id int) (field.Field, error) {
f := m.fields[id]
if f == nil {
if _, ok := m.spec.Fields[id]; !ok {
return nil, fmt.Errorf("field %d is not defined in the spec", id)
}
return nil, nil
}
return f, nil
}
// Fields returns the copy of the map of the set fields in the message. Be aware
// that fields are live references, so modifying them will affect the message.
func (m *Message) GetFields() map[int]field.Field {
m.mu.Lock()
defer m.mu.Unlock()
return m.getFields()
}
// getFields returns the map of the set fields. It assumes that the mutex
// is already locked by the caller.
func (m *Message) getFields() map[int]field.Field {
return maps.Clone(m.fields)
}
// Pack locks the message, packs its fields, and then unlocks it.
// If any errors are encountered during packing, they will be wrapped
// in a *PackError before being returned.
func (m *Message) Pack() ([]byte, error) {
m.mu.Lock()
defer m.mu.Unlock()
return m.wrapErrorPack()
}
// wrapErrorPack calls the core packing logic and wraps any errors in a
// *PackError. It assumes that the mutex is already locked by the caller.
func (m *Message) wrapErrorPack() ([]byte, error) {
data, err := m.pack()
if err != nil {
return nil, &iso8583errors.PackError{Err: err}
}
return data, nil
}
// pack contains the core logic for packing the message. This method does not
// handle locking or error wrapping and should typically be used internally
// after ensuring concurrency safety.
func (m *Message) pack() ([]byte, error) {
packed := []byte{}
m.resetBitmap()
ids, err := m.packableFieldIDs()
if err != nil {
return nil, fmt.Errorf("failed to pack message: %w", err)
}
for _, id := range ids {
// indexes 0 and 1 are for mti and bitmap
// regular field number startd from index 2
// do not pack presence bits as well
if id < 2 || m.bitmap().IsBitmapPresenceBit(id) {
continue
}
m.bitmap().Set(id)
}
// pack fields
for _, i := range ids {
// do not pack presence bits other than the first one as it's the bitmap itself
if i != 1 && m.bitmap().IsBitmapPresenceBit(i) {
continue
}
// m.fields[i] must have the field as we got i from packableFieldIDs()
field := m.fields[i]
packedField, err := field.Pack()
if err != nil {
return nil, fmt.Errorf("failed to pack field %d (%s): %w", i, field.Spec().Description, err)
}
packed = append(packed, packedField...)
}
return packed, nil
}
// Unpack unpacks the message from the given byte slice or returns an error
// which is of type *UnpackError and contains the raw message
func (m *Message) Unpack(src []byte) error {
m.mu.Lock()
defer m.mu.Unlock()
return m.wrapErrorUnpack(src)
}
// wrapErrorUnpack calls the core unpacking logic and wraps any
// errors in a *UnpackError. It assumes that the mutex is already
// locked by the caller.
func (m *Message) wrapErrorUnpack(src []byte) error {
if fieldID, err := m.unpack(src); err != nil {
return &iso8583errors.UnpackError{
Err: err,
FieldID: fieldID,
RawMessage: src,
}
}
return nil
}
// unpack contains the core logic for unpacking the message. This method does
// not handle locking or error wrapping and should typically be used internally
// after ensuring concurrency safety.
func (m *Message) unpack(src []byte) (string, error) {
// reset fields
m.fields = make(map[int]field.Field)
// it implicitly sets the bitmap field in m.fields
m.resetBitmap()
mti, err := m.createField(mtiIdx)
if err != nil {
return strconv.Itoa(mtiIdx), fmt.Errorf("getting or creating MTI field: %w", err)
}
read, err := mti.Unpack(src)
if err != nil {
return strconv.Itoa(mtiIdx), fmt.Errorf("failed to unpack MTI: %w", err)
}
offset := read
// unpack Bitmap
read, err = m.bitmap().Unpack(src[offset:])
if err != nil {
return strconv.Itoa(bitmapIdx), fmt.Errorf("failed to unpack bitmap: %w", err)
}
offset += read
for i := 2; i <= m.bitmap().Len(); i++ {
// skip bitmap presence bits (for default bitmap length of 64 these are bits 1, 65, 129, 193, etc.)
if m.bitmap().IsBitmapPresenceBit(i) {
continue
}
if m.bitmap().IsSet(i) {
fl, err := m.createField(i)
if err != nil {
return strconv.Itoa(i), fmt.Errorf("creating field %d: %w", i, err)
}
read, err = fl.Unpack(src[offset:])
if err != nil {
return strconv.Itoa(i), fmt.Errorf("failed to unpack field %d (%s): %w", i, fl.Spec().Description, err)
}
offset += read
}
}
return "", nil
}
func (m *Message) MarshalJSON() ([]byte, error) {
m.mu.Lock()
defer m.mu.Unlock()
// by packing the message we will generate bitmap
// create HEX representation
// and validate message against the spec
if _, err := m.wrapErrorPack(); err != nil {
return nil, err
}
fieldMap := m.getFields()
strFieldMap := map[string]field.Field{}
for id, field := range fieldMap {
strFieldMap[strconv.Itoa(id)] = field
}
// get only fields that were set
bytes, err := json.Marshal(field.OrderedMap(strFieldMap))
if err != nil {
return nil, utils.NewSafeError(err, "failed to JSON marshal map to bytes")
}
return bytes, nil
}
func (m *Message) UnmarshalJSON(b []byte) error {
m.mu.Lock()
defer m.mu.Unlock()
var data map[string]json.RawMessage
if err := json.Unmarshal(b, &data); err != nil {
return err
}
for id, rawMsg := range data {
i, err := strconv.Atoi(id)
if err != nil {
return fmt.Errorf("failed to unmarshal field %v: could not convert to int", i)
}
field, err := m.getOrCreateField(i)
if err != nil {
return fmt.Errorf("failed to unmarshal field %d: %w", i, err)
}
if err := json.Unmarshal(rawMsg, field); err != nil {
return utils.NewSafeErrorf(err, "failed to unmarshal field %v", id)
}
}
return nil
}
func (m *Message) packableFieldIDs() ([]int, error) {
return slices.Sorted(maps.Keys(m.fields)), nil
}
// Clone clones the message by creating a new message from the binary
// representation of the original message
func (m *Message) Clone() (*Message, error) {
newMessage := NewMessage(m.spec)
m.mu.Lock()
bytes, err := m.wrapErrorPack()
if err != nil {
m.mu.Unlock()
return nil, err
}
m.mu.Unlock()
mti, err := m.GetMTI()
if err != nil {
return nil, err
}
newMessage.MTI(mti)
newMessage.Unpack(bytes)
_, err = newMessage.Pack()
if err != nil {
return nil, err
}
return newMessage, nil
}
// Marshal populates message fields with v struct field values. It traverses
// through the message fields and calls Unmarshal(...) on them setting the v If
// v is not a struct or not a pointer to struct then it returns error.
func (m *Message) Marshal(v interface{}) error {
m.mu.Lock()
defer m.mu.Unlock()
if v == nil {
return nil
}
dataStruct := reflect.ValueOf(v)
if dataStruct.Kind() == reflect.Ptr || dataStruct.Kind() == reflect.Interface {
dataStruct = dataStruct.Elem()
}
if dataStruct.Kind() != reflect.Struct {
return errors.New("data is not a struct")
}
err := m.marshalStruct(dataStruct)
if err != nil {
return fmt.Errorf("marshaling struct: %w", err)
}
return nil
}
// marshalStruct is a helper method that handles the core logic of marshaling a struct.
// It supports anonymous embedded structs by recursively traversing into them when they
// don't have index tags themselves.
func (m *Message) marshalStruct(dataStruct reflect.Value) error {
// iterate over struct fields
for i := 0; i < dataStruct.NumField(); i++ {
structField := dataStruct.Type().Field(i)
indexTag := field.NewIndexTag(structField)
// If the field has an index tag, process it normally
if indexTag.ID >= 0 {
dataField := dataStruct.Field(i)
// for non pointer fields we need to check if they are zero
// and we want to skip them (as specified in the field tag)
if dataField.IsZero() && !indexTag.KeepZero {
continue
}
messageField, err := m.getOrCreateField(indexTag.ID)
if err != nil {
return fmt.Errorf("getting or creating field %d: %w", indexTag.ID, err)
}
if err := messageField.Marshal(dataField.Interface()); err != nil {
return fmt.Errorf("failed to set value to field %d: %w", indexTag.ID, err)
}
continue
}
// If it's an anonymous embedded struct without an index tag, traverse into it
if structField.Anonymous {
fieldValue := dataStruct.Field(i)
// Handle pointer and interface types
for fieldValue.Kind() == reflect.Ptr || fieldValue.Kind() == reflect.Interface {
if fieldValue.IsNil() {
break // skip nil embedded structs
}
fieldValue = fieldValue.Elem()
}
if fieldValue.Kind() == reflect.Struct && fieldValue.IsValid() {
// Recursively process the embedded struct
if err := m.marshalStruct(fieldValue); err != nil {
return err
}
}
}
// Otherwise, skip the field (existing behavior for non-anonymous fields without index tags)
}
return nil
}
// Unmarshal populates v struct fields with message field values. It traverses
// through the message fields and calls Unmarshal(...) on them setting the v If
// v is nil or not a pointer it returns error.
func (m *Message) Unmarshal(v interface{}) error {
m.mu.Lock()
defer m.mu.Unlock()
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
return errors.New("data is not a pointer or nil")
}
// get the struct from the pointer
dataStruct := rv.Elem()
if dataStruct.Kind() != reflect.Struct {
return errors.New("data is not a struct")
}
return m.unmarshalStruct(dataStruct)
}
// unmarshalStruct is a helper method that handles the core logic of unmarshaling into a struct.
// It supports anonymous embedded structs by recursively traversing into them when they
// don't have index tags themselves.
func (m *Message) unmarshalStruct(dataStruct reflect.Value) error {
// iterate over struct fields
for i := range dataStruct.NumField() {
structField := dataStruct.Type().Field(i)
indexTag := field.NewIndexTag(structField)
// If the field has an index tag, process it normally
if indexTag.ID >= 0 {
// skip if field is not set in the message
messageField := m.fields[indexTag.ID]
if messageField == nil {
continue
}
dataField := dataStruct.Field(i)
switch dataField.Kind() { //nolint:exhaustive
case reflect.Pointer, reflect.Interface:
if dataField.IsNil() {
dataField.Set(reflect.New(dataField.Type().Elem()))
}
err := messageField.Unmarshal(dataField.Interface())
if err != nil {
return fmt.Errorf("failed to get value from field %d: %w", indexTag.ID, err)
}
case reflect.Slice:
// Pass reflect.Value for slices so they can be modified
err := messageField.Unmarshal(dataField)
if err != nil {
return fmt.Errorf("failed to get value from field %d: %w", indexTag.ID, err)
}
default: // Native types
err := messageField.Unmarshal(dataField)
if err != nil {
return fmt.Errorf("failed to get value from field %d: %w", indexTag.ID, err)
}
}
continue
}
// If it's an anonymous embedded struct without an index tag, traverse into it
if structField.Anonymous {
fieldValue := dataStruct.Field(i)
// Handle pointer and interface types
for fieldValue.Kind() == reflect.Ptr || fieldValue.Kind() == reflect.Interface {
if fieldValue.IsNil() {
// Try to initialize if possible
if fieldValue.CanSet() && fieldValue.Kind() == reflect.Ptr {
fieldValue.Set(reflect.New(fieldValue.Type().Elem()))
fieldValue = fieldValue.Elem()
} else {
break // skip nil embedded structs that can't be initialized
}
} else {
fieldValue = fieldValue.Elem()
}
}
if fieldValue.Kind() == reflect.Struct && fieldValue.IsValid() {
// Recursively process the embedded struct
if err := m.unmarshalStruct(fieldValue); err != nil {
return err
}
}
}
// Otherwise, skip the field (existing behavior for non-anonymous fields without index tags)
}
return nil
}
// UnsetField marks the field with the given ID as not set and replaces it with
// a new zero-valued field. This effectively removes the field's value and excludes
// it from operations like Pack() or Marshal().
func (m *Message) UnsetField(id int) {
m.mu.Lock()
defer m.mu.Unlock()
m.unsetField(id)
}
func (m *Message) unsetField(id int) {
delete(m.fields, id)
}
func (m *Message) getOrCreateField(id int) (field.Field, error) {
f := m.fields[id]
if f != nil {
return f, nil
}
f, err := m.createField(id)
if err != nil {
return nil, fmt.Errorf("creating field %d: %w", id, err)
}
return f, nil
}
func (m *Message) createField(id int) (field.Field, error) {
specField, ok := m.GetSpec().Fields[id]
if !ok {
return nil, fmt.Errorf("field %d is not defined in the spec", id)
}
f := field.NewInstanceOf(specField)
m.fields[id] = f
return f, nil
}
// UnsetFields marks multiple fields identified by their paths as not set and
// replaces them with new zero-valued fields. Each path should be in the format
// "a.b.c". This effectively removes the fields' values and excludes them from
// operations like Pack() or Marshal().
// Deprecated: use UnsetPath instead.
func (m *Message) UnsetFields(idPaths ...string) error {
return m.UnsetPath(idPaths...)
}
// UnsetPath marks multiple fields identified by their paths as not set and
// replaces them with new zero-valued fields. Each path should be in the format
// "a.b.c". This effectively removes the fields' values and excludes them from
// operations like Pack() or Marshal().
func (m *Message) UnsetPath(idPaths ...string) error {
m.mu.Lock()
defer m.mu.Unlock()
for _, idPath := range idPaths {
if idPath == "" {
continue
}
id, path, hasSubpath := strings.Cut(idPath, ".")
idx, err := strconv.Atoi(id)
if err != nil {
return fmt.Errorf("conversion of %s to int failed: %w", id, err)
}
f := m.fields[idx]
// field is not set, continue
if f == nil {
continue
}
// If there's no subpath, unset the entire field
if !hasSubpath {
m.unsetField(idx)
continue
}
// Handle composite field with subpaths
pathUnsetter, ok := f.(field.PathUnsetter)
if !ok {
return fmt.Errorf("field %d is not a composite field and its subfields %s cannot be unset", idx, path)
}
if err := pathUnsetter.UnsetPath(path); err != nil {
return fmt.Errorf("failed to unset %s in composite field %d: %w", path, idx, err)
}
}
return nil
}
func (m *Message) MarshalPath(path string, value any) error {
if path == "" {
return errors.New("path cannot be empty")
}
m.mu.Lock()
defer m.mu.Unlock()
id, subPath, hasSubPath := strings.Cut(path, ".")
idx, err := strconv.Atoi(id)
if err != nil {
return fmt.Errorf("conversion of %s to int failed: %w", id, err)
}
f, err := m.getOrCreateField(idx)
if err != nil {
return fmt.Errorf("getting or creating field %s: %w", id, err)
}
if hasSubPath {
mField, ok := f.(field.PathMarshaler)
if !ok {
return fmt.Errorf("field %s is not a PathMarshaler", id)
}
err := mField.MarshalPath(subPath, value)
if err != nil {
return fmt.Errorf("marshaling filed %s: %w", id, err)
}
return nil
}
err = f.Marshal(value)
if err != nil {
return fmt.Errorf("marshaling field %s: %w", id, err)
}
return nil
}
func (m *Message) UnmarshalPath(path string, value any) error {
if path == "" {
return errors.New("path cannot be empty")
}
m.mu.Lock()
defer m.mu.Unlock()
id, subPath, hasSubPath := strings.Cut(path, ".")
idx, err := strconv.Atoi(id)
if err != nil {
return fmt.Errorf("conversion of %s to int failed: %w", id, err)
}
f := m.fields[idx]
if f == nil {
// check if field exists in spec
_, ok := m.spec.Fields[idx]
if !ok {
return fmt.Errorf("field %d is not defined in the spec", idx)
}
return nil
}
if hasSubPath {
uField, ok := f.(field.PathUnmarshaler)
if !ok {
return fmt.Errorf("field %s is not a PathUnmarshaler", id)
}
err := uField.UnmarshalPath(subPath, value)
if err != nil {
return fmt.Errorf("unmarshaling filed %s: %w", id, err)
}
return nil
}
err = f.Unmarshal(value)
if err != nil {
return fmt.Errorf("unmarshaling field %s: %w", id, err)
}
return nil
}