You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The readers and all the other non-logging APIs currently available in this library are scheduled
196
-
> for deprecation in an upcoming release. To access our newest and improved CLP IR analytics
197
-
> interface (which offers advanced features like high-performance decoding and enhanced query search
198
-
> capabilities) check out [clp-ffi-py][9].
199
-
200
-
### CLPStreamReader
201
-
202
-
- Read/decode any arbitrary stream
203
-
- Can be used as an iterator that returns each log message as an object
204
-
- Can skip n logs: `clp_reader.skip_nlogs(N)`
205
-
- Can skip to first log after given time (since unix epoch):
206
-
-`clp_reader.skip_to_time(TIME)`
207
-
208
-
### CLPFileReader
209
-
210
-
- Simple wrapper around CLPStreamHandler that calls open
211
-
212
-
#### Example code: CLPFileReader
213
-
214
-
```python
215
-
from pathlib import Path
216
-
from typing import List
217
-
218
-
from clp_logging.readers import CLPFileReader, Log
219
-
220
-
# create a list of all Log objects
221
-
log_objects: List[Log] = []
222
-
with CLPFileReader(Path("example.clp.zst")) as clp_reader:
223
-
for log in clp_reader:
224
-
log_objects.append(log)
225
-
```
226
-
227
-
### CLPSegmentStreaming
228
-
229
-
* Classes that inherit from CLPBaseReader can only read a single CLP IR stream from start to finish. This is necessary because, to determine the timestamp of an individual log, the starting timestamp (from the IR stream preamble) and all timestamp deltas up to that log must be known. In scenarios where an IR stream is periodically uploaded in chunks, users would need to either continuously read the entire stream or re-read the entire stream from the start.
230
-
* The CLPSegmentStreaming class has the ability to take an input IR stream and segment it, outputting multiple independent IR streams. This makes it possible to read arbitrary segments of the original input IR stream without needing to decode it from the start.
231
-
* In technical terms, the segment streaming reader allows the read operation to start from a non-zero offset and streams the legally encoded logs from one stream to another.
232
-
* Each read call will return encoded metadata that can be used to resume from the current call.
233
-
234
-
#### Example code: CLPSegmentStreaming
235
-
236
-
```python
237
-
from clp_logging.readers import CLPSegmentStreaming
238
-
from clp_logging.protocol import Metadata
239
-
240
-
segment_idx: int=0
241
-
segment_max_size: int=8192
242
-
offset: int=0
243
-
metadata: Metadata =None
244
-
whileTrue:
245
-
bytes_read: int
246
-
withopen("example.clp", "rb") as fin, open(f"{segment_idx}.clp", "wb") as fout:
247
-
bytes_read, metadata = CLPSegmentStreaming.read(
248
-
fin,
249
-
fout,
250
-
offset=offset,
251
-
max_bytes_to_write=segment_max_size,
252
-
metadata=metadata
253
-
)
254
-
segment_idx +=1
255
-
offset += bytes_read
256
-
if metadata ==None:
257
-
break
258
-
```
259
-
260
-
In the example code provided, "example.clp" is streamed into segments named "0.clp", "1.clp", and so on. Each segment is smaller than 8192 bytes and can be decoded independently.
195
+
> All readers are removed from this library since v0.0.15. To read an IR stream, use [clp-ffi-py][9]
0 commit comments