Skip to content

spa_pod_parser wrapper

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

This adds a new wrapper type libspa::pod::parser::Parser around spa_pod_parser, which offers low-level bindings that may require unsafe and/or working with C types, but is still more rusty than working with the raw parser.

For creating a parser from a byte slice, and for parsing most "easy" pod types that can be parsed with a simple "get_*" call, no unsafe is neccessary.

When parsing structs, objects, etc., and using other functions that access/modify the state of the parser, unsafe is neccessary because the caller has to work with stack-allocated spa_pod_frames that the parser uses to keep track of the state, and those frames must be kept alive and unmoved until poping them in the right order.

This new wrapper could be used in our serde-like PodDeserializer in the future to get rid of the custom and buggy nom implementation (and the nom dependency).

Also, I will add similar bindings for spa_pod_builder in later MR.

Unresolved:

  1. We might require Pin around provided frames to help callers make sure they don't move. This doesn't make the API fully safe because they could still be dropped early, but would help make it less dangerous. Would this create other problems somehow? Nevermind, this would only work with pointer types. You can still move a Pin<T> to another location and the T moves with it.

  2. Should we make wrapper types around spa_pod_parser_state and spa_pod_frame? Maybe in a future MR.

  3. I left out a couple functions that I wasn't 100% sure about what they were doing, we might add those too. Done

Edited by Tom Wagner

Merge request reports