Skip to content

Commit

Permalink
Done...
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZhihao-723 committed Dec 3, 2023
1 parent 5c9905b commit 5a1696a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clp_ffi_py/ir/native.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions clp_ffi_py/ir/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
16 changes: 8 additions & 8 deletions src/clp_ffi_py/ir/native/PyDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -73,10 +73,10 @@ PyMethodDef PyDecoder_method_table[]{
METH_VARARGS | METH_KEYWORDS | METH_STATIC,
static_cast<char const*>(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<char const*>(cSkipNextNLogEventsDoc)},
static_cast<char const*>(cSkipForwardDoc)},

{nullptr, nullptr, 0, nullptr}
};
Expand Down
3 changes: 1 addition & 2 deletions src/clp_ffi_py/ir/native/decoding_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down
2 changes: 1 addition & 1 deletion src/clp_ffi_py/ir/native/decoding_methods.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/test_ir/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand All @@ -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")

Expand All @@ -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)
Expand Down

0 comments on commit 5a1696a

Please sign in to comment.