diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-11-27 02:15:44 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-11-27 02:17:38 +0900 |
| commit | 73987be7d4c850f8b95babb8f68e6ccb6cafcee4 (patch) | |
| tree | c46e77b552fe508b7970be199699b07ae86cb288 /internal/pipewire/core.go | |
| parent | 563b5e66fc0dfe0abc4a4b8c96f0f89ef71c3422 (diff) | |
internal/pipewire: size without serialisation
This is required to achieve zero allocation (other than reflect).
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire/core.go')
| -rw-r--r-- | internal/pipewire/core.go | 33 |
1 files changed, 33 insertions, 0 deletions
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) |
