Skip to content

spa pod parser: Add new `parser_get` convenience macro to parse complex pods in single statement

Tom Wagner requested to merge ryuukyu/pipewire-rs:spa-pod-parser-macro into main

Adds a new convenience macro for parsing SPA pods, esp. complex structs:

The general syntax is

parser_get(<&mut libspa::pod::parser::Parser>, Bool(<&mut bool>));
parser_get(<&mut libspa::pod::parser::Parser>, Id(<&mut libspa::utils::Id>));
parser_get(<&mut libspa::pod::parser::Parser>, Int(<&mut i32>));
parser_get(<&mut libspa::pod::parser::Parser>, Long(<&mut i64>));
parser_get(<&mut libspa::pod::parser::Parser>, Float(<&mut f32>));
parser_get(<&mut libspa::pod::parser::Parser>, Double(<&mut f64>));
parser_get(<&mut libspa::pod::parser::Parser>, Bytes(<&mut &[u8]>));
parser_get(<&mut libspa::pod::parser::Parser>, Pointer(<&mut *const c_void>));
parser_get(<&mut libspa::pod::parser::Parser>, Fd(<&mut i64>));
parser_get(<&mut libspa::pod::parser::Parser>, Rectangle(<&mut libspa::utils::Rectangle>));
parser_get(<&mut libspa::pod::parser::Parser>, Fraction(<&mut libspa::utils::Fraction>));
parser_get(<&mut libspa::pod::parser::Parser>,
    Struct {
        // 0 to n fields, e.g.:
        Struct {
            Int(<&mut i32>),
            Float(<&mut f32>),
        },
        Bytes(<&mut &[u8]),
    }
);

In future MRs, support for objects, optional fields etc. will be added.

Merge request reports

Loading