diff --git a/clp_ffi_py/ir/native.pyi b/clp_ffi_py/ir/native.pyi index dfe9a279..4d557970 100644 --- a/clp_ffi_py/ir/native.pyi +++ b/clp_ffi_py/ir/native.pyi @@ -80,7 +80,7 @@ class Decoder: allow_incomplete_stream: bool = False, ) -> Optional[LogEvent]: ... @staticmethod - def skip_next_n_log_events( + def skip_forward( decoder_buffer: DecoderBuffer, num_events_to_skip: int, allow_incomplete_stream: bool = False, diff --git a/clp_ffi_py/ir/readers.py b/clp_ffi_py/ir/readers.py index dbc32e9b..dbe3dfe8 100644 --- a/clp_ffi_py/ir/readers.py +++ b/clp_ffi_py/ir/readers.py @@ -100,6 +100,15 @@ def search(self, query: Query) -> Generator[LogEvent, None, None]: break yield log_event + def skip_forward(self, num_events_to_skip: int) -> None: + """ + Decodes and discards the next `num_events_to_skip` log events from the + underlying IR stream. + + :param: num_events_to_skip + """ + Decoder.skip_forward(self._decoder_buffer, num_events_to_skip) + def close(self) -> None: self.__istream.close() diff --git a/src/clp_ffi_py/ir/native/PyDecoder.cpp b/src/clp_ffi_py/ir/native/PyDecoder.cpp index 57f21809..b421f93b 100644 --- a/src/clp_ffi_py/ir/native/PyDecoder.cpp +++ b/src/clp_ffi_py/ir/native/PyDecoder.cpp @@ -45,13 +45,13 @@ PyDoc_STRVAR( // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) PyDoc_STRVAR( - cSkipNextNLogEventsDoc, - "skip_next_n_log_events( " + cSkipForwardDoc, + "skip_forward( " "decoder_buffer, num_events_to_skip, allow_incomplete_stream=False)\n" "--\n\n" - "Decodes and discard the next n log events from the IR stream buffered in the given " - "decoder buffer. `decoder_buffer` must have been returned by a successfully invocation of " - "`decode_preamble`. It will stop whenever EOF.\n\n" + "Decodes and discards the given amount of log events from the IR stream buffered in the " + "given decoder buffer. `decoder_buffer` must have been returned by a successfully " + "invocation of `decode_preamble`. It will stop whenever EOF.\n\n" ":param decoder_buffer: The decoder buffer of the encoded CLP IR stream.\n" ":param num_events_to_skip: Number of events to skip forward.\n" ":param allow_incomplete_stream: If set to `True`, an incomplete CLP IR stream is not " @@ -73,10 +73,10 @@ PyMethodDef PyDecoder_method_table[]{ METH_VARARGS | METH_KEYWORDS | METH_STATIC, static_cast(cDecodeNextLogEventDoc)}, - {"skip_next_n_log_events", - py_c_function_cast(skip_next_n_log_events), + {"skip_forward", + py_c_function_cast(skip_forward), METH_VARARGS | METH_KEYWORDS | METH_STATIC, - static_cast(cSkipNextNLogEventsDoc)}, + static_cast(cSkipForwardDoc)}, {nullptr, nullptr, 0, nullptr} }; diff --git a/src/clp_ffi_py/ir/native/decoding_methods.cpp b/src/clp_ffi_py/ir/native/decoding_methods.cpp index 8b1ada3f..b25fceb0 100644 --- a/src/clp_ffi_py/ir/native/decoding_methods.cpp +++ b/src/clp_ffi_py/ir/native/decoding_methods.cpp @@ -328,8 +328,7 @@ auto decode_next_log_event(PyObject* Py_UNUSED(self), PyObject* args, PyObject* ); } -auto skip_next_n_log_events(PyObject* Py_UNUSED(self), PyObject* args, PyObject* keywords) - -> PyObject* { +auto skip_forward(PyObject* Py_UNUSED(self), PyObject* args, PyObject* keywords) -> PyObject* { static char keyword_decoder_buffer[]{"decoder_buffer"}; static char keyword_num_events_to_skip[]{"num_events_to_skip"}; static char keyword_allow_incomplete_stream[]{"allow_incomplete_stream"}; diff --git a/src/clp_ffi_py/ir/native/decoding_methods.hpp b/src/clp_ffi_py/ir/native/decoding_methods.hpp index c7f0ca92..61da44f8 100644 --- a/src/clp_ffi_py/ir/native/decoding_methods.hpp +++ b/src/clp_ffi_py/ir/native/decoding_methods.hpp @@ -9,7 +9,7 @@ namespace clp_ffi_py::ir::native { extern "C" { auto decode_preamble(PyObject* self, PyObject* py_decoder_buffer) -> PyObject*; auto decode_next_log_event(PyObject* self, PyObject* args, PyObject* keywords) -> PyObject*; -auto skip_next_n_log_events(PyObject* self, PyObject* args, PyObject* keywords) -> PyObject*; +auto skip_forward(PyObject* self, PyObject* args, PyObject* keywords) -> PyObject*; } } // namespace clp_ffi_py::ir::native diff --git a/tests/test_ir/test_decoder.py b/tests/test_ir/test_decoder.py index ebc9254b..5e4806e1 100644 --- a/tests/test_ir/test_decoder.py +++ b/tests/test_ir/test_decoder.py @@ -51,7 +51,7 @@ def test_skip_negative_num_events(self) -> None: _ = Decoder.decode_preamble(decoder_buffer) error_captured: bool = False try: - Decoder.skip_next_n_log_events(decoder_buffer, -1) + Decoder.skip_forward(decoder_buffer, -1) except NotImplementedError: error_captured = True except Exception as e: @@ -67,7 +67,7 @@ def test_skip_zero_event(self) -> None: decoder_buffer: DecoderBuffer = DecoderBuffer(ir_stream) _ = Decoder.decode_preamble(decoder_buffer) for i in range(num_events): - Decoder.skip_next_n_log_events(decoder_buffer, 0) + Decoder.skip_forward(decoder_buffer, 0) log_event: Optional[LogEvent] = Decoder.decode_next_log_event(decoder_buffer) if None is log_event: self.assertTrue(False, "EOF shouldn't be reached before all log events are decoded") @@ -85,7 +85,7 @@ def test_skip_to_eof(self) -> None: ir_stream: IO[bytes] = self._create_simple_encoded_IR_stream(1) decoder_buffer: DecoderBuffer = DecoderBuffer(ir_stream) _ = Decoder.decode_preamble(decoder_buffer) - Decoder.skip_next_n_log_events(decoder_buffer, 1000) + Decoder.skip_forward(decoder_buffer, 1000) eof: Optional[LogEvent] = Decoder.decode_next_log_event(decoder_buffer) self.assertEqual(None, eof, "EOF should be reached since all the log events are decoded") @@ -106,7 +106,7 @@ def test_skip_general(self) -> None: num_events_decoded: int = 0 for i in range(num_arithmetic_sequence_term): term_idx = i + 1 - Decoder.skip_next_n_log_events(decoder_buffer, term_idx) + Decoder.skip_forward(decoder_buffer, term_idx) num_events_skipped += term_idx for _ in range(term_idx): log_event: Optional[LogEvent] = Decoder.decode_next_log_event(decoder_buffer)