diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-11-27 02:33:19 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-11-27 02:33:19 +0900 |
| commit | dcb22a61c00aa4a09ab31cb47380f55ae9ad1b0d (patch) | |
| tree | 7c789f472ec38c031f490e7dba1eeea24beea83d /internal | |
| parent | e028a61fc1567de71ba836a3a7caf64aef84b34c (diff) | |
internal/pipewire: require appending marshaler
This eliminates all non-reflect allocations.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/pipewire/pod.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/internal/pipewire/pod.go b/internal/pipewire/pod.go index 3a94db5d..27d3c601 100644 --- a/internal/pipewire/pod.go +++ b/internal/pipewire/pod.go @@ -107,8 +107,9 @@ func SizeString[W Word | int](s string) W { return Size(W(len(s)) + 1) } // PODMarshaler is the interface implemented by an object that can // marshal itself into PipeWire POD encoding. type PODMarshaler interface { - // MarshalPOD encodes the receiver into PipeWire POD encoding and returns the result. - MarshalPOD() ([]byte, error) + // MarshalPOD encodes the receiver into PipeWire POD encoding, + // appends it to data, and returns the result. + MarshalPOD(data []byte) ([]byte, error) } // An UnsupportedTypeError is returned by [Marshal] when attempting @@ -164,8 +165,9 @@ func appendInner(data []byte, f func(data []byte) ([]byte, error)) ([]byte, erro func marshalValueAppend(data []byte, v reflect.Value) ([]byte, error) { if v.CanInterface() && (v.Kind() != reflect.Pointer || !v.IsNil()) { if m, ok := v.Interface().(PODMarshaler); ok { - extraData, err := m.MarshalPOD() - return append(data, extraData...), err + var err error + data, err = m.MarshalPOD(data) + return data, err } } @@ -475,8 +477,8 @@ func (d *SPADict) Size() Word { } // MarshalPOD satisfies [PODMarshaler] as [SPADict] violates the POD type system. -func (d *SPADict) MarshalPOD() ([]byte, error) { - return appendInner(nil, func(dataPrefix []byte) (data []byte, err error) { +func (d *SPADict) MarshalPOD(data []byte) ([]byte, error) { + return appendInner(data, func(dataPrefix []byte) (data []byte, err error) { data = binary.NativeEndian.AppendUint32(dataPrefix, SPA_TYPE_Struct) if data, err = MarshalAppend(data, d.NItems); err != nil { return |
