From 73987be7d4c850f8b95babb8f68e6ccb6cafcee4 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 27 Nov 2025 02:15:44 +0900 Subject: internal/pipewire: size without serialisation This is required to achieve zero allocation (other than reflect). Signed-off-by: Ophestra --- internal/pipewire/core.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'internal/pipewire/core.go') diff --git a/internal/pipewire/core.go b/internal/pipewire/core.go index 407ea954..1ef2f790 100644 --- a/internal/pipewire/core.go +++ b/internal/pipewire/core.go @@ -102,6 +102,19 @@ type CoreInfo struct { Props *SPADict } +// Size satisfies [KnownSize] with a value computed at runtime. +func (c *CoreInfo) Size() Word { + return SizePrefix + + Size(SizeInt) + + Size(SizeInt) + + SizeString[Word](c.UserName) + + SizeString[Word](c.HostName) + + SizeString[Word](c.Version) + + SizeString[Word](c.Name) + + Size(SizeLong) + + c.Props.Size() +} + // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. func (c *CoreInfo) MarshalBinary() ([]byte, error) { return Marshal(c) } @@ -116,6 +129,9 @@ type CoreDone struct { Sequence Int } +// Size satisfies [KnownSize] with a constant value. +func (c *CoreDone) Size() Word { return SizePrefix + Size(SizeInt) + Size(SizeInt) } + // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. func (c *CoreDone) MarshalBinary() ([]byte, error) { return Marshal(c) } @@ -133,6 +149,14 @@ type CoreBoundProps struct { Props *SPADict } +// Size satisfies [KnownSize] with a value computed at runtime. +func (c *CoreBoundProps) Size() Word { + return SizePrefix + + Size(SizeInt) + + Size(SizeInt) + + c.Props.Size() +} + // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. func (c *CoreBoundProps) MarshalBinary() ([]byte, error) { return Marshal(c) } @@ -145,6 +169,9 @@ type CoreHello struct { Version Int } +// Size satisfies [KnownSize] with a constant value. +func (c *CoreHello) Size() Word { return SizePrefix + Size(SizeInt) } + // MarshalBinary satisfies [encoding.BinaryMarshaler] via [MarshalAppend]. func (c *CoreHello) MarshalBinary() ([]byte, error) { return MarshalAppend(make([]byte, 0, 24), c) @@ -168,6 +195,9 @@ type CoreSync struct { Sequence Int } +// Size satisfies [KnownSize] with a constant value. +func (c *CoreSync) Size() Word { return SizePrefix + Size(SizeInt) + Size(SizeInt) } + // MarshalBinary satisfies [encoding.BinaryMarshaler] via [MarshalAppend]. func (c *CoreSync) MarshalBinary() ([]byte, error) { return MarshalAppend(make([]byte, 0, 40), c) @@ -191,6 +221,9 @@ type CoreGetRegistry struct { NewID Int } +// Size satisfies [KnownSize] with a constant value. +func (c *CoreGetRegistry) Size() Word { return SizePrefix + Size(SizeInt) + Size(SizeInt) } + // MarshalBinary satisfies [encoding.BinaryMarshaler] via [MarshalAppend]. func (c *CoreGetRegistry) MarshalBinary() ([]byte, error) { return MarshalAppend(make([]byte, 0, 40), c) -- cgit v1.3.1