internal/pipewire: preallocate for footer
All checks were successful
Test / Create distribution (push) Successful in 38s
Test / Sandbox (push) Successful in 2m36s
Test / Sandbox (race detector) (push) Successful in 4m43s
Test / Hakurei (push) Successful in 5m11s
Test / Hpkg (push) Successful in 5m5s
Test / Hakurei (race detector) (push) Successful in 6m30s
Test / Flake checks (push) Successful in 1m31s

This is useful during serialisation.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-12-02 03:06:27 +09:00
parent 91aaabaa1b
commit 647aa9d02f
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 21 additions and 2 deletions

View File

@ -81,6 +81,12 @@ type FooterCoreGeneration struct {
RegistryGeneration Long `json:"registry_generation"` 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 // The FooterClientGeneration indicates to the server what is the last
// registry generation number the client has processed. // registry generation number the client has processed.
// //
@ -91,6 +97,12 @@ type FooterClientGeneration struct {
ClientGeneration Long `json:"client_generation"` 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 // A CoreInfo event is emitted by the server upon connection
// with the more information about the server. // with the more information about the server.
type CoreInfo struct { type CoreInfo struct {

View File

@ -468,11 +468,18 @@ func unmarshalCheckTypeBounds(data *[]byte, t Word, sizeP *Word) error {
// The Footer contains additional messages, not directed to // The Footer contains additional messages, not directed to
// the destination object defined by the Id field. // the destination object defined by the Id field.
type Footer[T any] struct { type Footer[P KnownSize] struct {
// The footer opcode. // The footer opcode.
Opcode Id `json:"opcode"` Opcode Id `json:"opcode"`
// The footer payload struct. // 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]. // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal].