diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-12-14 07:12:00 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-12-14 07:12:00 +0900 |
| commit | 6d0d9cecd11bee0b79bbd95cb989a356134e4b6c (patch) | |
| tree | fc86ce89235bb82c8c1081a985e8c228a1a0f6a5 /internal/pipewire | |
| parent | 17248d7d6116a4a0b85ed0d90cb382a25eed16b5 (diff) | |
internal/pipewire: handle nil spa_dict correctly
This now marshals into a value of type None when the slice is nil, and correctly unmarshals from type None.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire')
| -rw-r--r-- | internal/pipewire/pod.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/pipewire/pod.go b/internal/pipewire/pod.go index 103154aa..caf83fd0 100644 --- a/internal/pipewire/pod.go +++ b/internal/pipewire/pod.go @@ -541,6 +541,11 @@ func (d *SPADict) Size() Word { // MarshalPOD satisfies [PODMarshaler] as [SPADict] violates the POD type system. func (d *SPADict) MarshalPOD(data []byte) ([]byte, error) { return appendInner(data, func(dataPrefix []byte) (data []byte, err error) { + if *d == nil { + data = SPA_TYPE_None.append(dataPrefix) + return + } + data = SPA_TYPE_Struct.append(dataPrefix) if data, err = MarshalAppend(data, Int(len(*d))); err != nil { return @@ -560,6 +565,14 @@ func (d *SPADict) MarshalPOD(data []byte) ([]byte, error) { // UnmarshalPOD satisfies [PODUnmarshaler] as [SPADict] violates the POD type system. func (d *SPADict) UnmarshalPOD(data []byte) (Word, error) { var wireSize Word + + if ok, err := unmarshalHandleNone(&data, &wireSize); err != nil { + return wireSize, err + } else if ok { + *d = nil + return wireSize, nil + } + if err := unmarshalCheckTypeBounds(&data, SPA_TYPE_Struct, &wireSize); err != nil { return wireSize, err } |
