Skip to content

feat: Adding PbjReader - #900

Open
ldintr wants to merge 1 commit into
fromUTF8from
PbjReader
Open

feat: Adding PbjReader#900
ldintr wants to merge 1 commit into
fromUTF8from
PbjReader

Conversation

@ldintr

@ldintr ldintr commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Stack created with GitHub Stacks CLIGive Feedback 💬

@ldintr
ldintr requested review from a team as code owners August 25, 2026 19:57
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

JUnit Test Report

   521 files  ±0     521 suites  ±0   27s ⏱️ -4s
 1 537 tests ±0   1 533 ✅ ±0   4 💤 ±0  0 ❌ ±0 
10 755 runs  ±0  10 727 ✅ ±0  28 💤 ±0  0 ❌ ±0 

Results for commit 98ce0d8. ± Comparison against base commit 18b9660.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

Integration Test Report

    428 files  ±0      428 suites  ±0   14m 4s ⏱️ - 1m 38s
115 048 tests ±0  115 048 ✅ ±0  0 💤 ±0  0 ❌ ±0 
115 292 runs  ±0  115 292 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 98ce0d8. ± Comparison against base commit 18b9660.

♻️ This comment has been updated with latest results.

Signed-off-by: ldintr <levo.d@swirldslabs.com>
@ldintr
ldintr requested review from a team as code owners August 25, 2026 20:12
@ldintr
ldintr requested a review from rbarker-dev August 25, 2026 20:12
@ldintr ldintr changed the title Adding PbjReader feat: Adding PbjReader Aug 25, 2026
@ldintr ldintr self-assigned this Aug 25, 2026
Comment on lines +489 to +490
public void setPbjReader(@NonNull PbjReader reader) {
reader.resetWith(buffer, start, start + length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set may not be the perfect verb for this method because it's not a setter, i.e. it doesn't update the internal state of the Bytes object. resetPbjReader might sound better.

Also, you want to add a javadoc for this new public method.

Comment on lines +43 to +66
private static final boolean useStacktrace =
!"false".equalsIgnoreCase(System.getProperty("pbj.ReaderWriter.useStackTrace"));

public static final int EOF = -1,
Closed = -2,
DataEncoding = 1,
BufferUnderflow = 2,
Parse = 3,
IllegalArgument = 4,
IOError = 5,
Unsupported = 6, // used with WIRE_TYPE_GROUP_START, WIRE_TYPE_GROUP_END
UsageError = 9,
UnknownField = 10,
BufferOverflow = 11,
MaxDepthReached = 12,
MalformString = 13;

private static final UnknownFieldException premadeUnknown;
private static final BufferUnderflowException premadeUnderflow;
private static final BufferOverflowException premadeOverflow;
private static final RuntimeException premadeRuntime, premadeUnsupported;
private static final DataEncodingException premadeDataEncoding;
private static final IllegalArgumentException premadeIllegal;
private static final ParseException premadeParseEmpty, premadeParseUnknown, premadeMaxDepth;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static members in Java should all be UPPER_SNAKE_CASE. Otherwise, it's too easy to confuse them with instance members or local variables.

public long readVarLongNoZZ() {
if (pos + 10 <= relLimit) {
long value = 0;
for (int i = 0; i < 10; i++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reading varints, we want to use the algorithm that we've determined is the fastest and which is implemented elsewhere in PBJ.

Comment on lines +496 to +498
} else if (errorKind == Parse) {
cause = new RuntimeException(message);
includeCause = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still concerned about setting includeCause to false in this branch. To me it seems as though we're going to lose some context-related information.

}

@Override
public void close() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already seen this code a couple of times in previous iterations, so I mostly just skimmed it through this time. However, I'd like @artemananiev to review it thoroughly this time.

Comment on lines +4 to +11
/**
* Implemented by {@link ReadableSequentialData} types that are backed directly by a heap byte array.
* Callers (e.g. {@link com.hedera.pbj.runtime.io.buffer.PbjReader}) can detect this and use the array directly
* instead of copying data through an intermediate buffer.
*/
public interface ByteArraySequentialData {
/** The raw backing byte array. */
byte[] byteArrayUnsafe();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed previously, these operations look unsafe and we'd prefer not to introduce such APIs. Can we not use an approach similar to what's done with Bytes in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants