Skip to content

Commit

Permalink
Add iterator support to Parser bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jan 7, 2025
1 parent 707b93d commit a95fc32
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions python/bindings/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@ void init_novatel_parser(nb::module_& m)
})
.def(
"read",
[](oem::Parser& self, nb::handle_t<oem::MetaDataStruct> py_metadata) {
[](oem::Parser& self, nb::handle_t<oem::MetaDataStruct> py_metadata, bool decode_incomplete) {
MessageDataStruct message_data;
STATUS status = self.Read(message_data, nb::cast<oem::MetaDataStruct&>(py_metadata));
STATUS status = self.Read(message_data, nb::cast<oem::MetaDataStruct&>(py_metadata), decode_incomplete);
return std::make_tuple(status, oem::PyMessageData(message_data));
},
"metadata"_a)
"metadata"_a, "decode_incomplete_abbreviated"_a = false)
.def("__iter__", [](oem::Parser& self) { return &self; })
.def("__next__",
[](oem::Parser& self) {
MessageDataStruct message_data;
oem::MetaDataStruct meta_data;
STATUS status = self.Read(message_data, meta_data);
switch (status)
{
case STATUS::BUFFER_EMPTY: [[fallthrough]];
case STATUS::INCOMPLETE: [[fallthrough]];
case STATUS::INCOMPLETE_MORE_DATA: throw nb::stop_iteration();
default: break;
}
return std::make_tuple(status, oem::PyMessageData(message_data), meta_data);
})
.def(
"flush",
[](oem::Parser& self, bool return_flushed_bytes) -> nb::object {
Expand Down

0 comments on commit a95fc32

Please sign in to comment.