diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-12-02 03:06:27 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-12-02 03:06:27 +0900 |
| commit | 647aa9d02fb275c47ae00c552977d42013888a6b (patch) | |
| tree | dbba67377be4ace06939a4f845852c6395829694 | |
| parent | 91aaabaa1b48b870d4e818e3651b7c6bc3b182fb (diff) | |
internal/pipewire: preallocate for footer
This is useful during serialisation.
Signed-off-by: Ophestra <cat@gensokyo.uk>
| -rw-r--r-- | internal/pipewire/core.go | 12 | ||||
| -rw-r--r-- | internal/pipewire/pod.go | 11 |
2 files changed, 21 insertions, 2 deletions
diff --git a/internal/pipewire/core.go b/internal/pipewire/core.go index a15d0803..4b61972b 100644 --- a/internal/pipewire/core.go +++ b/internal/pipewire/core.go @@ -81,6 +81,12 @@ type FooterCoreGeneration struct { RegistryGeneration Long `json:"registry_generation"` } +// Size satisfies [KnownSize] with a constant value. +func (fcg FooterCoreGeneration) Size() Word { + return SizePrefix + + Size(SizeLong) +} + // The FooterClientGeneration indicates to the server what is the last // registry generation number the client has processed. // @@ -91,6 +97,12 @@ type FooterClientGeneration struct { ClientGeneration Long `json:"client_generation"` } +// Size satisfies [KnownSize] with a constant value. +func (fcg FooterClientGeneration) Size() Word { + return SizePrefix + + Size(SizeLong) +} + // A CoreInfo event is emitted by the server upon connection // with the more information about the server. type CoreInfo struct { diff --git a/internal/pipewire/pod.go b/internal/pipewire/pod.go index fe6c43ad..88a49e82 100644 --- a/internal/pipewire/pod.go +++ b/internal/pipewire/pod.go @@ -468,11 +468,18 @@ func unmarshalCheckTypeBounds(data *[]byte, t Word, sizeP *Word) error { // The Footer contains additional messages, not directed to // the destination object defined by the Id field. -type Footer[T any] struct { +type Footer[P KnownSize] struct { // The footer opcode. Opcode Id `json:"opcode"` // The footer payload struct. - Payload T `json:"payload"` + Payload P `json:"payload"` +} + +// Size satisfies [KnownSize] with a usually compile-time known value. +func (f *Footer[P]) Size() Word { + return SizePrefix + + Size(SizeId) + + f.Payload.Size() } // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. |
