2022-08-03 15:20:03 +01:00
|
|
|
package ld
|
2022-08-05 20:53:44 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"sectorinf.com/emilis/flabk/pkg/ld/internal/parse"
|
|
|
|
"sectorinf.com/emilis/flabk/pkg/ld/internal/parse/chunk"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Unmarshal[T any](v []byte) (T, error) {
|
|
|
|
ptr := new(T)
|
|
|
|
if err := parse.SetValue(reflect.ValueOf(ptr), reflect.TypeOf(ptr), chunk.New(v)); err != nil {
|
|
|
|
return *ptr, fmt.Errorf("unmarshal: %w", err)
|
|
|
|
}
|
|
|
|
return *ptr, nil
|
|
|
|
}
|