From cbe86dc4f02bc43d00fd362692a123549ad48efc Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 28 Nov 2025 01:33:32 +0900 Subject: [PATCH] internal/pipewire: add json struct tags These match the names found in documentation. Signed-off-by: Ophestra --- internal/pipewire/client.go | 14 +++++------ internal/pipewire/client_test.go | 8 +++--- internal/pipewire/core.go | 42 ++++++++++++++++---------------- internal/pipewire/core_test.go | 4 +-- internal/pipewire/pod.go | 4 +-- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/internal/pipewire/client.go b/internal/pipewire/client.go index 0847ac0..cf66647 100644 --- a/internal/pipewire/client.go +++ b/internal/pipewire/client.go @@ -39,11 +39,11 @@ const ( // This is emitted when binding to a client or when the client info is updated later. type ClientInfo struct { // The global id of the client. - ID Int + ID Int `json:"id"` // The changes emitted by this event. - ChangeMask Long + ChangeMask Long `json:"change_mask"` // Properties of this object, valid when change_mask has PW_CLIENT_CHANGE_MASK_PROPS. - Props *SPADict + Properties *SPADict `json:"props"` } // Size satisfies [KnownSize] with a value computed at runtime. @@ -51,7 +51,7 @@ func (c *ClientInfo) Size() Word { return SizePrefix + Size(SizeInt) + Size(SizeLong) + - c.Props.Size() + c.Properties.Size() } // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. @@ -62,12 +62,12 @@ func (c *ClientInfo) UnmarshalBinary(data []byte) error { return Unmarshal(data, // ClientUpdateProperties is used to update the properties of a client. type ClientUpdateProperties struct { - // Props are properties to update on the client. - Props *SPADict + // Properties to update on the client. + Properties *SPADict `json:"props"` } // Size satisfies [KnownSize] with a value computed at runtime. -func (c *ClientUpdateProperties) Size() Word { return SizePrefix + c.Props.Size() } +func (c *ClientUpdateProperties) Size() Word { return SizePrefix + c.Properties.Size() } // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. func (c *ClientUpdateProperties) MarshalBinary() ([]byte, error) { return Marshal(c) } diff --git a/internal/pipewire/client_test.go b/internal/pipewire/client_test.go index ffdffb2..d3f8089 100644 --- a/internal/pipewire/client_test.go +++ b/internal/pipewire/client_test.go @@ -13,7 +13,7 @@ func TestClientInfo(t *testing.T) { {"sample", samplePWContainer[1][2][1], pipewire.ClientInfo{ ID: 34, ChangeMask: pipewire.PW_CLIENT_CHANGE_MASK_PROPS, - Props: &pipewire.SPADict{ + Properties: &pipewire.SPADict{ {Key: "pipewire.protocol", Value: "protocol-native"}, {Key: "core.name", Value: "pipewire-0"}, {Key: "pipewire.sec.socket", Value: "pipewire-0-manager"}, @@ -28,7 +28,7 @@ func TestClientInfo(t *testing.T) { {"sample*", samplePWContainer[1][3][1], pipewire.ClientInfo{ ID: 34, ChangeMask: pipewire.PW_CLIENT_CHANGE_MASK_PROPS, - Props: &pipewire.SPADict{ + Properties: &pipewire.SPADict{ {Key: "pipewire.protocol", Value: "protocol-native"}, {Key: "core.name", Value: "pipewire-alice-1443"}, {Key: "pipewire.sec.socket", Value: "pipewire-0-manager"}, @@ -72,7 +72,7 @@ func TestClientInfo(t *testing.T) { {"sample**", samplePWContainer[1][4][1], pipewire.ClientInfo{ ID: 34, ChangeMask: pipewire.PW_CLIENT_CHANGE_MASK_PROPS, - Props: &pipewire.SPADict{ + Properties: &pipewire.SPADict{ {Key: "pipewire.protocol", Value: "protocol-native"}, {Key: "core.name", Value: "pipewire-alice-1443"}, {Key: "pipewire.sec.socket", Value: "pipewire-0-manager"}, @@ -120,7 +120,7 @@ func TestClientUpdateProperties(t *testing.T) { t.Parallel() encodingTestCases[pipewire.ClientUpdateProperties, *pipewire.ClientUpdateProperties]{ - {"sample", samplePWContainer[0][1][1], pipewire.ClientUpdateProperties{Props: &pipewire.SPADict{ + {"sample", samplePWContainer[0][1][1], pipewire.ClientUpdateProperties{Properties: &pipewire.SPADict{ {Key: "remote.intention", Value: "manager"}, {Key: "application.name", Value: "pw-container"}, {Key: "application.process.binary", Value: "pw-container"}, diff --git a/internal/pipewire/core.go b/internal/pipewire/core.go index 57e1f5b..c172d0c 100644 --- a/internal/pipewire/core.go +++ b/internal/pipewire/core.go @@ -78,28 +78,28 @@ const ( // The server shall include this footer in the next message it sends that // follows the increment of the registry generation number. type FooterCoreGeneration struct { - RegistryGeneration Long + RegistryGeneration Long `json:"registry_generation"` } // A CoreInfo event is emitted by the server upon connection // with the more information about the server. type CoreInfo struct { // The id of the server (PW_ID_CORE). - ID Int + ID Int `json:"id"` // A unique cookie for this server. - Cookie Int + Cookie Int `json:"cookie"` // The name of the user running the server. - UserName String + UserName String `json:"user_name"` // The name of the host running the server. - HostName String + HostName String `json:"host_name"` // A version string of the server. - Version String + Version String `json:"version"` // The name of the server. - Name String + Name String `json:"name"` // A set of bits with changes to the info. - ChangeMask Long + ChangeMask Long `json:"change_mask"` // Optional key/value properties, valid when change_mask has PW_CORE_CHANGE_MASK_PROPS. - Props *SPADict + Properties *SPADict `json:"props"` } // Size satisfies [KnownSize] with a value computed at runtime. @@ -112,7 +112,7 @@ func (c *CoreInfo) Size() Word { SizeString[Word](c.Version) + SizeString[Word](c.Name) + Size(SizeLong) + - c.Props.Size() + c.Properties.Size() } // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. @@ -124,9 +124,9 @@ func (c *CoreInfo) UnmarshalBinary(data []byte) error { return Unmarshal(data, c // The CoreDone event is emitted as a result of a client Sync method. type CoreDone struct { // Passed from [CoreSync.ID]. - ID Int + ID Int `json:"id"` // Passed from [CoreSync.Sequence]. - Sequence Int + Sequence Int `json:"sequence"` } // Size satisfies [KnownSize] with a constant value. @@ -142,11 +142,11 @@ func (c *CoreDone) UnmarshalBinary(data []byte) error { return Unmarshal(data, c // It is emitted before the global becomes visible in the registry. type CoreBoundProps struct { // A proxy id. - ID Int + ID Int `json:"id"` // The global_id as it will appear in the registry. - GlobalID Int + GlobalID Int `json:"global_id"` // The properties of the global. - Props *SPADict + Properties *SPADict `json:"props"` } // Size satisfies [KnownSize] with a value computed at runtime. @@ -154,7 +154,7 @@ func (c *CoreBoundProps) Size() Word { return SizePrefix + Size(SizeInt) + Size(SizeInt) + - c.Props.Size() + c.Properties.Size() } // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal]. @@ -166,7 +166,7 @@ func (c *CoreBoundProps) UnmarshalBinary(data []byte) error { return Unmarshal(d // CoreHello is the first message sent by a client. type CoreHello struct { // The version number of the client, usually PW_VERSION_CORE. - Version Int + Version Int `json:"version"` } // Size satisfies [KnownSize] with a constant value. @@ -188,9 +188,9 @@ const ( // operations before the Sync method have been completed. type CoreSync struct { // The id will be returned in the Done event. - ID Int + ID Int `json:"id"` // Usually generated automatically and will be returned in the Done event. - Sequence Int + Sequence Int `json:"sequence"` } // Size satisfies [KnownSize] with a constant value. @@ -211,10 +211,10 @@ func (c *CoreSync) UnmarshalBinary(data []byte) error { return Unmarshal(data, c type CoreGetRegistry struct { // The version of the registry interface used on the client, // usually PW_VERSION_REGISTRY. - Version Int + Version Int `json:"version"` // The id of the new proxy with the registry interface, // ends up as [Header.ID] in future messages. - NewID Int + NewID Int `json:"new_id"` } // Size satisfies [KnownSize] with a constant value. diff --git a/internal/pipewire/core_test.go b/internal/pipewire/core_test.go index 05f19eb..9cfc571 100644 --- a/internal/pipewire/core_test.go +++ b/internal/pipewire/core_test.go @@ -34,7 +34,7 @@ func TestCoreInfo(t *testing.T) { Version: "1.4.7", Name: "pipewire-0", ChangeMask: pipewire.PW_CORE_CHANGE_MASK_PROPS, - Props: &pipewire.SPADict{ + Properties: &pipewire.SPADict{ {Key: "config.name", Value: "pipewire.conf"}, {Key: "application.name", Value: "pipewire"}, {Key: "application.process.binary", Value: "pipewire"}, @@ -88,7 +88,7 @@ func TestCoreBoundProps(t *testing.T) { {"sample", samplePWContainer[1][1][1], pipewire.CoreBoundProps{ ID: pipewire.PW_ID_CLIENT, GlobalID: 34, - Props: &pipewire.SPADict{ + Properties: &pipewire.SPADict{ {Key: "object.serial", Value: "34"}, {Key: "module.id", Value: "2"}, {Key: "pipewire.protocol", Value: "protocol-native"}, diff --git a/internal/pipewire/pod.go b/internal/pipewire/pod.go index 42055e1..6e13177 100644 --- a/internal/pipewire/pod.go +++ b/internal/pipewire/pod.go @@ -445,9 +445,9 @@ func unmarshalCheckTypeBounds(data *[]byte, t Word, sizeP *Word) error { // the destination object defined by the Id field. type Footer[T any] struct { // The footer opcode. - Opcode Id + Opcode Id `json:"opcode"` // The footer payload struct. - Payload T + Payload T `json:"payload"` } // MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal].