internal/pipewire: simplify spa_dict appends
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m33s
Test / Hakurei (push) Successful in 3m31s
Test / Hpkg (push) Successful in 4m16s
Test / Sandbox (race detector) (push) Successful in 4m29s
Test / Hakurei (race detector) (push) Successful in 5m20s
Test / Flake checks (push) Successful in 1m30s
All checks were successful
Test / Create distribution (push) Successful in 43s
Test / Sandbox (push) Successful in 2m33s
Test / Hakurei (push) Successful in 3m31s
Test / Hpkg (push) Successful in 4m16s
Test / Sandbox (race detector) (push) Successful in 4m29s
Test / Hakurei (race detector) (push) Successful in 5m20s
Test / Flake checks (push) Successful in 1m30s
This change uses the (somewhat) newly exposed MarshalAppend which improves readability. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
2edcfe1e68
commit
563b5e66fc
@ -441,30 +441,26 @@ type SPADict struct {
|
|||||||
Items []SPADictItem
|
Items []SPADictItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalPOD satisfies [PODMarshaler] as [SPADict] violates the POD type system.
|
||||||
func (d *SPADict) MarshalPOD() ([]byte, error) {
|
func (d *SPADict) MarshalPOD() ([]byte, error) {
|
||||||
return appendInner(nil, func(data []byte) ([]byte, error) {
|
return appendInner(nil, func(dataPrefix []byte) (data []byte, err error) {
|
||||||
data = binary.NativeEndian.AppendUint32(data, SPA_TYPE_Struct)
|
data = binary.NativeEndian.AppendUint32(dataPrefix, SPA_TYPE_Struct)
|
||||||
if extraData, err := Marshal(d.NItems); err != nil {
|
if data, err = MarshalAppend(data, d.NItems); err != nil {
|
||||||
return data, err
|
return
|
||||||
} else {
|
|
||||||
data = append(data, extraData...)
|
|
||||||
}
|
}
|
||||||
for i := range d.Items {
|
for i := range d.Items {
|
||||||
if extraData, err := Marshal(d.Items[i].Key); err != nil {
|
if data, err = MarshalAppend(data, d.Items[i].Key); err != nil {
|
||||||
return data, err
|
return
|
||||||
} else {
|
|
||||||
data = append(data, extraData...)
|
|
||||||
}
|
}
|
||||||
if extraData, err := Marshal(d.Items[i].Value); err != nil {
|
if data, err = MarshalAppend(data, d.Items[i].Value); err != nil {
|
||||||
return data, err
|
return
|
||||||
} else {
|
|
||||||
data = append(data, extraData...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data, nil
|
return
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalPOD satisfies [PODUnmarshaler] as [SPADict] violates the POD type system.
|
||||||
func (d *SPADict) UnmarshalPOD(data []byte) (Word, error) {
|
func (d *SPADict) UnmarshalPOD(data []byte) (Word, error) {
|
||||||
var wireSize Word
|
var wireSize Word
|
||||||
if err := unmarshalCheckTypeBounds(&data, SPA_TYPE_Struct, &wireSize); err != nil {
|
if err := unmarshalCheckTypeBounds(&data, SPA_TYPE_Struct, &wireSize); err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user