internal/pipewire: size without serialisation

This is required to achieve zero allocation (other than reflect).

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-11-27 02:15:44 +09:00
parent 563b5e66fc
commit 73987be7d4
4 changed files with 90 additions and 8 deletions

View File

@@ -46,6 +46,14 @@ type ClientInfo struct {
Props *SPADict
}
// Size satisfies [KnownSize] with a value computed at runtime.
func (c *ClientInfo) Size() Word {
return SizePrefix +
Size(SizeInt) +
Size(SizeLong) +
c.Props.Size()
}
// MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal].
func (c *ClientInfo) MarshalBinary() ([]byte, error) { return Marshal(c) }
@@ -58,6 +66,9 @@ type ClientUpdateProperties struct {
Props *SPADict
}
// Size satisfies [KnownSize] with a value computed at runtime.
func (c *ClientUpdateProperties) Size() Word { return SizePrefix + c.Props.Size() }
// MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal].
func (c *ClientUpdateProperties) MarshalBinary() ([]byte, error) { return Marshal(c) }