AlexxIT/go2rtc · error
tlv8: unsupported array:
Error message
tlv8: unsupported array:
What it means
tlv8 supports decoding arrays only when the element kind is uint8 (byte arrays). If a struct field is an array of any other element type, unmarshalValue returns this error naming the unsupported element kind.
Solutions
- Change the array element type to uint8 (e.g. [6]byte instead of [6]uint16).
- Use a []byte slice if the length is variable.
- Decode into a custom type implementing manual unmarshaling for non-byte elements.
- Split the multi-byte array into multiple scalar uint8/uint16 fields.
Example fix
// before
type T struct {
Addrs [4]uint16 `tlv8:"2"`
}
// after
type T struct {
Addrs [8]byte `tlv8:"2"`
} Defensive patterns
Strategy: type-guard
Validate before calling
func tlv8Supported(v reflect.Value) error {
t := v.Type()
if t.Kind() == reflect.Array || t.Kind() == reflect.Slice {
if t.Elem().Kind() != reflect.Uint8 {
return fmt.Errorf("field %s: only byte arrays supported, got %s", t, t.Elem().Kind())
}
}
return nil
} Type guard
func isByteArray(t reflect.Type) bool {
return (t.Kind() == reflect.Array || t.Kind() == reflect.Slice) && t.Elem().Kind() == reflect.Uint8
} Try / catch
if err := tlv8.Unmarshal(payload, &msg); err != nil {
if strings.Contains(err.Error(), "unsupported array") {
return fmt.Errorf("schema uses non-byte array: %w", err)
}
return err
} Prevention
- Restrict TLV8 struct arrays to [N]byte / []byte.
- Run a compile-time or test-time schema check that walks struct tags and rejects unsupported kinds.
- Prefer slices of scalars decoded manually over exotic array types.
When it happens
Trigger: Decoding a TLV8 record into a struct field declared as e.g. [4]uint16, [2]int, or [N]string.
Common situations: Modeling HomeKit TLV fields as typed arrays; refactoring a []byte field to a wider numeric array; copying struct definitions from another protocol.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- tlv8: not implemented:
- tlv8: value should be pointer:
- tlv8: unmarshal zero data
- tlv8: wrong size:
- tlv8: zero item
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/a9344e76b480bac3.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/hap/tlv8/tlv8.go:332
}
value.SetUint(uint64(v[0]) | uint64(v[1])<<8 | uint64(v[2])<<16 | uint64(v[3])<<24)
case reflect.Uint64:
if len(v) != 8 {
return errors.New("tlv8: wrong size: " + value.Type().Name())
}
value.SetUint(binary.LittleEndian.Uint64(v))
case reflect.Float32:
f := math.Float32frombits(binary.LittleEndian.Uint32(v))
value.SetFloat(float64(f))
case reflect.String:
value.SetString(string(v))
case reflect.Array:
if kind := value.Type().Elem().Kind(); kind != reflect.Uint8 {
return errors.New("tlv8: unsupported array: " + kind.String())
}
for i, b := range v {
value.Index(i).SetUint(uint64(b))
}
return nil
case reflect.Slice:
i := growSlice(value)
return unmarshalValue(v, value.Index(i))
case reflect.Struct:
return unmarshalStruct(v, value)
default:
return errors.New("tlv8: not implemented: " + value.Kind().String())
}
View on GitHub (pinned to c245815e75)