aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pipewire/header.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-27 00:54:56 +0900
committerOphestra <cat@gensokyo.uk>2025-11-27 00:54:56 +0900
commit2edcfe1e68078c467d12a04aff2fc1e45cb6dff2 (patch)
tree69b0faea654b5531b058d9d49db30e081ac85e34 /internal/pipewire/header.go
parent2698ca00e8fad5f7243c1e1b4c078d322854917c (diff)
internal/pipewire: define size constants
This gets rid of magic numbers in marshal/unmarshal. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire/header.go')
-rw-r--r--internal/pipewire/header.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/internal/pipewire/header.go b/internal/pipewire/header.go
index 3ab22d49..89d50efa 100644
--- a/internal/pipewire/header.go
+++ b/internal/pipewire/header.go
@@ -6,8 +6,8 @@ import (
)
const (
- // HeaderSize is the fixed size of [Header].
- HeaderSize = 16
+ // SizeHeader is the fixed size of [Header].
+ SizeHeader = 16
// SizeMax is the largest value of [Header.Size] that can be represented in its 3-byte segment.
SizeMax = 0x00ffffff
)
@@ -50,11 +50,11 @@ func (h *Header) MarshalBinary() (data []byte, err error) {
if h.Size&^SizeMax != 0 {
return nil, ErrSizeRange
}
- return h.append(make([]byte, 0, HeaderSize)), nil
+ return h.append(make([]byte, 0, SizeHeader)), nil
}
// unmarshalBinary decodes the protocol native message header.
-func (h *Header) unmarshalBinary(data [HeaderSize]byte) {
+func (h *Header) unmarshalBinary(data [SizeHeader]byte) {
h.ID = binary.NativeEndian.Uint32(data[0:4])
h.Size = binary.NativeEndian.Uint32(data[4:8])
h.Opcode = byte(h.Size >> 24)
@@ -65,9 +65,9 @@ func (h *Header) unmarshalBinary(data [HeaderSize]byte) {
// UnmarshalBinary decodes the protocol native message header.
func (h *Header) UnmarshalBinary(data []byte) error {
- if len(data) != HeaderSize {
+ if len(data) != SizeHeader {
return ErrBadHeader
}
- h.unmarshalBinary(([HeaderSize]byte)(data))
+ h.unmarshalBinary(([SizeHeader]byte)(data))
return nil
}