{"record":{"id":"a9344e76b480bac3","repo":"AlexxIT/go2rtc","slug":"tlv8-unsupported-array","errorCode":null,"errorMessage":"tlv8: unsupported array: ","messagePattern":"tlv8: unsupported array: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hap/tlv8/tlv8.go","lineNumber":332,"sourceCode":"\t\t}\n\t\tvalue.SetUint(uint64(v[0]) | uint64(v[1])<<8 | uint64(v[2])<<16 | uint64(v[3])<<24)\n\n\tcase reflect.Uint64:\n\t\tif len(v) != 8 {\n\t\t\treturn errors.New(\"tlv8: wrong size: \" + value.Type().Name())\n\t\t}\n\t\tvalue.SetUint(binary.LittleEndian.Uint64(v))\n\n\tcase reflect.Float32:\n\t\tf := math.Float32frombits(binary.LittleEndian.Uint32(v))\n\t\tvalue.SetFloat(float64(f))\n\n\tcase reflect.String:\n\t\tvalue.SetString(string(v))\n\n\tcase reflect.Array:\n\t\tif kind := value.Type().Elem().Kind(); kind != reflect.Uint8 {\n\t\t\treturn errors.New(\"tlv8: unsupported array: \" + kind.String())\n\t\t}\n\n\t\tfor i, b := range v {\n\t\t\tvalue.Index(i).SetUint(uint64(b))\n\t\t}\n\t\treturn nil\n\n\tcase reflect.Slice:\n\t\ti := growSlice(value)\n\t\treturn unmarshalValue(v, value.Index(i))\n\n\tcase reflect.Struct:\n\t\treturn unmarshalStruct(v, value)\n\n\tdefault:\n\t\treturn errors.New(\"tlv8: not implemented: \" + value.Kind().String())\n\t}\n","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/hap/tlv8/tlv8.go#L314-L350","documentation":"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.","triggerScenarios":"Decoding a TLV8 record into a struct field declared as e.g. [4]uint16, [2]int, or [N]string.","commonSituations":"Modeling HomeKit TLV fields as typed arrays; refactoring a []byte field to a wider numeric array; copying struct definitions from another protocol.","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."],"exampleFix":"// before\ntype T struct {\n  Addrs [4]uint16 `tlv8:\"2\"`\n}\n// after\ntype T struct {\n  Addrs [8]byte `tlv8:\"2\"`\n}","handlingStrategy":"type-guard","validationCode":"func tlv8Supported(v reflect.Value) error {\n    t := v.Type()\n    if t.Kind() == reflect.Array || t.Kind() == reflect.Slice {\n        if t.Elem().Kind() != reflect.Uint8 {\n            return fmt.Errorf(\"field %s: only byte arrays supported, got %s\", t, t.Elem().Kind())\n        }\n    }\n    return nil\n}","typeGuard":"func isByteArray(t reflect.Type) bool {\n    return (t.Kind() == reflect.Array || t.Kind() == reflect.Slice) && t.Elem().Kind() == reflect.Uint8\n}","tryCatchPattern":"if err := tlv8.Unmarshal(payload, &msg); err != nil {\n    if strings.Contains(err.Error(), \"unsupported array\") {\n        return fmt.Errorf(\"schema uses non-byte array: %w\", err)\n    }\n    return err\n}","preventionTips":["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."],"tags":["tlv8","decoding","reflection","unsupported-type"],"backgroundTag":"unsupported-operation","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}