feat: Adding PbjWriter - #909
Open
ldintr wants to merge 1 commit into
Open
Conversation
This was referenced Sep 3, 2026
jasperpotts
reviewed
Sep 9, 2026
Comment on lines
+511
to
+530
| public void writeIntLE(int value) { | ||
| if (pos + 4 <= cap) { | ||
| buf[pos] = (byte) value; | ||
| buf[pos + 1] = (byte) (value >>> 8); | ||
| buf[pos + 2] = (byte) (value >>> 16); | ||
| buf[pos + 3] = (byte) (value >>> 24); | ||
| pos += 4; | ||
| return; | ||
| } | ||
| writeIntLEInternal(value); | ||
| } | ||
|
|
||
| private void writeIntLEInternal(int value) { | ||
| flushOrGrow(4); | ||
| buf[pos] = (byte) value; | ||
| buf[pos + 1] = (byte) (value >>> 8); | ||
| buf[pos + 2] = (byte) (value >>> 16); | ||
| buf[pos + 3] = (byte) (value >>> 24); | ||
| pos += 4; | ||
| } |
Member
There was a problem hiding this comment.
I don't see where writeIntLEInternal() is used other than in writeIntLE() so why not just have:
public void writeIntLE(int value) {
if (pos + 4 > cap) flushOrGrow(4);
buf[pos] = (byte) value;
buf[pos + 1] = (byte) (value >>> 8);
buf[pos + 2] = (byte) (value >>> 16);
buf[pos + 3] = (byte) (value >>> 24);
pos += 4;
}
?
Signed-off-by: ldintr <levo.d@swirldslabs.com>
ldintr
force-pushed
the
ldintr-addWriter
branch
from
September 10, 2026 19:08
219ade1 to
44a9230
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Write-side counterpart to PbjReader: fixed-width/varint(+zigzag) writes, a placeholder/patch mechanism (placehold/writeAtUnsafe/reinsertVarInt) for filling in length prefixes after writing content (avoiding a two-pass encode for short strings), constructible from OutputStream/ByteBuffer/growable buffers/WritableSequentialData, with toByteArray()/toPbjReader() round-tripping. Makes sizeOfStringNoTag public for the large-string fallback.
Overview: PbjReader/PbjWriter are a leaner, buffer-reusing alternative to the existing ReadableSequentialData/WritableSequentialData read/write path used by Codec, ProtoParserTools/ProtoWriterTools, and the pbj-compiler generators. They reuse an internal ~16KB (L1-cache-sized) buffer across many parse/write calls instead of allocating per call, avoid checked-exception-based control flow by recording a sticky internal error code instead, and split hot-path operations (e.g. zigzag vs. non-zigzag varints, direct UTF-8 decode into a reusable char[]) into dedicated fast methods.