diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-12-04 02:27:45 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-12-04 02:29:27 +0900 |
| commit | 69b1131d6622108f37c85014035f71cf4f2986e5 (patch) | |
| tree | 368cc8d0659d9925c9df8153398ca5038313e160 /internal/pipewire/spa.go | |
| parent | 2c0b92771a95693af7f14a70ddeddc5371e73996 (diff) | |
internal/pipewire: use type name in error strings
This provides more useful messages for protocol errors.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire/spa.go')
| -rw-r--r-- | internal/pipewire/spa.go | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/internal/pipewire/spa.go b/internal/pipewire/spa.go index 32d6986f..a1014da9 100644 --- a/internal/pipewire/spa.go +++ b/internal/pipewire/spa.go @@ -1,10 +1,24 @@ package pipewire +import ( + "encoding/binary" + "fmt" +) + +// A SPAKind describes the kind of data being encoded right after it. +// +// These do not always follow the same rules, and encoding/decoding +// is very much context-dependent. Callers should therefore not +// attempt to use these values directly and rely on [Marshal] and +// [Unmarshal] and their variants instead. +type SPAKind Word + /* Basic types */ const ( /* POD's can contain a number of basic SPA types: */ - SPA_TYPE_START = 0x00000 + iota + SPA_TYPE_START SPAKind = 0x00000 + iota + SPA_TYPE_None // No value or a NULL pointer. SPA_TYPE_Bool // A boolean value. SPA_TYPE_Id // An enumerated value. @@ -35,6 +49,60 @@ const ( _SPA_TYPE_LAST // not part of ABI ) +// append appends the representation of [SPAKind] to data and returns the appended slice. +func (kind SPAKind) append(data []byte) []byte { + return binary.NativeEndian.AppendUint32(data, Word(kind)) +} + +// String returns the name of the [SPAKind] for basic types. +func (kind SPAKind) String() string { + switch kind { + case SPA_TYPE_None: + return "None" + case SPA_TYPE_Bool: + return "Bool" + case SPA_TYPE_Id: + return "Id" + case SPA_TYPE_Int: + return "Int" + case SPA_TYPE_Long: + return "Long" + case SPA_TYPE_Float: + return "Float" + case SPA_TYPE_Double: + return "Double" + case SPA_TYPE_String: + return "String" + case SPA_TYPE_Bytes: + return "Bytes" + case SPA_TYPE_Rectangle: + return "Rectangle" + case SPA_TYPE_Fraction: + return "Fraction" + case SPA_TYPE_Bitmap: + return "Bitmap" + case SPA_TYPE_Array: + return "Array" + case SPA_TYPE_Struct: + return "Struct" + case SPA_TYPE_Object: + return "Object" + case SPA_TYPE_Sequence: + return "Sequence" + case SPA_TYPE_Pointer: + return "Pointer" + case SPA_TYPE_Fd: + return "Fd" + case SPA_TYPE_Choice: + return "Choice" + case SPA_TYPE_Pod: + return "Pod" + + default: + return fmt.Sprintf("invalid type field %#x", Word(kind)) + } +} + /* Pointers */ const ( SPA_TYPE_POINTER_START = 0x10000 + iota |
