(f reflect.Type, t reflect.Type, data any)
| 233 | } |
| 234 | |
| 235 | func stringToByteArrayHook(f reflect.Type, t reflect.Type, data any) (any, error) { |
| 236 | if f.Kind() != reflect.String || t.Kind() != reflect.Array || t.Elem().Kind() != reflect.Uint8 { |
| 237 | return data, nil |
| 238 | } |
| 239 | |
| 240 | str := strings.TrimPrefix(data.(string), "0x") |
| 241 | slice, err := hex.DecodeString(str) |
| 242 | if err != nil { |
| 243 | return nil, fmt.Errorf("could not decode hex: %w", err) |
| 244 | } |
| 245 | if len(slice) != t.Len() { |
| 246 | return nil, fmt.Errorf("invalid length: expected %d, got %d", t.Len(), len(slice)) |
| 247 | } |
| 248 | |
| 249 | rv := reflect.New(t).Elem() |
| 250 | for i, v := range slice { |
| 251 | rv.Index(i).SetUint(uint64(v)) |
| 252 | } |
| 253 | return rv.Interface(), nil |
| 254 | } |
| 255 | |
| 256 | func stringToTimeDurationPointerHook(f reflect.Type, t reflect.Type, data any) (any, error) { |
| 257 | d := time.Duration(0) |
nothing calls this directly
no test coverage detected