internal/pipewire: handle nil spa_dict correctly
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m25s
Test / Hakurei (push) Successful in 3m27s
Test / Hpkg (push) Successful in 4m15s
Test / Sandbox (race detector) (push) Successful in 4m28s
Test / Hakurei (race detector) (push) Successful in 5m21s
Test / Flake checks (push) Successful in 1m37s
All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Sandbox (push) Successful in 2m25s
Test / Hakurei (push) Successful in 3m27s
Test / Hpkg (push) Successful in 4m15s
Test / Sandbox (race detector) (push) Successful in 4m28s
Test / Hakurei (race detector) (push) Successful in 5m21s
Test / Flake checks (push) Successful in 1m37s
This now marshals into a value of type None when the slice is nil, and correctly unmarshals from type None. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -541,6 +541,11 @@ func (d *SPADict) Size() Word {
|
||||
// MarshalPOD satisfies [PODMarshaler] as [SPADict] violates the POD type system.
|
||||
func (d *SPADict) MarshalPOD(data []byte) ([]byte, error) {
|
||||
return appendInner(data, func(dataPrefix []byte) (data []byte, err error) {
|
||||
if *d == nil {
|
||||
data = SPA_TYPE_None.append(dataPrefix)
|
||||
return
|
||||
}
|
||||
|
||||
data = SPA_TYPE_Struct.append(dataPrefix)
|
||||
if data, err = MarshalAppend(data, Int(len(*d))); err != nil {
|
||||
return
|
||||
@@ -560,6 +565,14 @@ func (d *SPADict) MarshalPOD(data []byte) ([]byte, error) {
|
||||
// UnmarshalPOD satisfies [PODUnmarshaler] as [SPADict] violates the POD type system.
|
||||
func (d *SPADict) UnmarshalPOD(data []byte) (Word, error) {
|
||||
var wireSize Word
|
||||
|
||||
if ok, err := unmarshalHandleNone(&data, &wireSize); err != nil {
|
||||
return wireSize, err
|
||||
} else if ok {
|
||||
*d = nil
|
||||
return wireSize, nil
|
||||
}
|
||||
|
||||
if err := unmarshalCheckTypeBounds(&data, SPA_TYPE_Struct, &wireSize); err != nil {
|
||||
return wireSize, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user