Open davemarco opened 1 month ago
The changes introduce a new TypeScript file, datastream.ts
, which implements a DataInputStream
class designed to read primitive data types from a byte stream. This class mimics the functionality of Java's DataInputStream
and utilizes a DataView
for handling binary data in both little-endian and big-endian formats. Additionally, it includes methods for seeking, reading various data types, and managing the read position, along with a custom error class for handling end-of-file conditions.
File | Change Summary |
---|---|
src/utils/datastream.ts | Added DataInputStream class for reading primitive data types from a byte stream. Added DataInputStreamEOFError class for EOF error handling. Both classes are exported for use in other modules. |
sequenceDiagram
participant Client
participant DataInputStream
participant DataView
Client->>DataInputStream: Create instance
DataInputStream->>DataView: Initialize with byte stream
Client->>DataInputStream: Read unsigned byte
DataInputStream->>DataView: Fetch unsigned byte
DataView-->>DataInputStream: Return byte
DataInputStream-->>Client: Return unsigned byte
Client->>DataInputStream: Read signed byte
DataInputStream->>DataView: Fetch signed byte
DataView-->>DataInputStream: Return byte
DataInputStream-->>Client: Return signed byte
Client->>DataInputStream: Seek to index
DataInputStream-->>DataInputStream: Update current position
Client->>DataInputStream: Read beyond available data
DataInputStream-->>Client: Throw DataInputStreamEOFError
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Description
First PR in single file archive series. I am splitting up to make easier to review.
PR implements a class that can read primitive types from a serialized stream (int, long, etc…) This will be used in later PRs to decode data from serialized CLP segments.
This code existed in old log viewer (see here), and all this PR does is convert from js to typescript.
Ideally this can be merged as doesn't add any functionality, and required for other PRs.
Summary by CodeRabbit
DataInputStream
class for enhanced data reading from byte streams, supporting multiple data types and endianness.DataInputStreamEOFError
, to manage end-of-file scenarios effectively.