Skip to content

feat: readBytes to return Bytes.EMPTY for zero length#687

Merged
anthony-swirldslabs merged 1 commit intomainfrom
291-bytesEMPTY
Nov 17, 2025
Merged

feat: readBytes to return Bytes.EMPTY for zero length#687
anthony-swirldslabs merged 1 commit intomainfrom
291-bytesEMPTY

Conversation

@anthony-swirldslabs
Copy link
Copy Markdown
Contributor

Description:
DirectBufferedData.readBytes() should return Bytes.EMPTY instead of creating new zero-length Bytes objects when the length is zero.

Related issue(s):

Fixes #291

Notes for reviewer:
A new unit test is added to verify the behavior.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
@anthony-swirldslabs anthony-swirldslabs self-assigned this Nov 17, 2025
@anthony-swirldslabs anthony-swirldslabs requested review from a team as code owners November 17, 2025 23:04
@github-actions
Copy link
Copy Markdown

JUnit Test Report

   78 files  ±0     78 suites  ±0   4m 4s ⏱️ +5s
1 350 tests +3  1 346 ✅ +3   4 💤 ±0  0 ❌ ±0 
7 227 runs  +3  7 207 ✅ +3  20 💤 ±0  0 ❌ ±0 

Results for commit d040965. ± Comparison against base commit c2f6bdf.

This pull request removes 8 and adds 10 tests. Note that renamed tests count towards both.
, 1
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] FLOAT, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c042f5a8@32068aef, [0.1, 0.5, 100.0], 12, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c042f7b8@8ab231
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] STRING, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c043e630@394e504d, [string 1, testing here, testing there], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c043e840@62ff14cd
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] BYTES, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c043ea50@426a4301, [010203, ff7f0f, 42da07370bff], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c043ec60@193f3306
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] DOUBLE, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c042f9c8@16024b49, [0.1, 0.5, 100.0, 1.7653472635472653E240], 32, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c042fbd8@53f94afe
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [3] BOOL, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c042fde8@7d4e424e, [true, false, false, true, true, true], 6, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0434000@799206ad
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [4] ENUM, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0434210@2059c3ff, [Mock for EnumWithProtoMetadata, hashCode: 1811787479, Mock for EnumWithProtoMetadata, hashCode: 1794960787, Mock for EnumWithProtoMetadata, hashCode: 1058287239], 3, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0434420@2b30b627
com.hedera.pbj.runtime.Utf8ToolsTest ‑ [4] 
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] FLOAT, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0449b38@6ba0dcba, [0.1, 0.5, 100.0], 12, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0449d48@6d7772d3
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [1] STRING, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0456a58@32e9c3af, [string 1, testing here, testing there], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0456c68@796e2187
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] BYTES, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0456e78@31aa9b01, [010203, ff7f0f, 42da07370bff], com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0457088@2148b47e
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [2] DOUBLE, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c0449f58@7d4e424e, [0.1, 0.5, 100.0, 1.7653472635472653E240], 32, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c044a168@799206ad
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [3] BOOL, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c044a378@2059c3ff, [true, false, false, true, true, true], 6, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c044a588@2f8ab988
com.hedera.pbj.runtime.ProtoWriterToolsTest ‑ [4] ENUM, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c044a798@e47637c, [Mock for EnumWithProtoMetadata, hashCode: 1890388052, Mock for EnumWithProtoMetadata, hashCode: 1673971173, Mock for EnumWithProtoMetadata, hashCode: 1859857531], 3, com.hedera.pbj.runtime.ProtoWriterToolsTest$$Lambda/0x00000007c044a9a8@684430c1
com.hedera.pbj.runtime.Utf8ToolsTest ‑ [4] 
, 1
com.hedera.pbj.runtime.io.buffer.BufferedDataTest ‑ readBytesReturnsConstantEmptyForZeroLength()
com.hedera.pbj.runtime.io.buffer.ByteArrayBufferedDataTest ‑ readBytesReturnsConstantEmptyForZeroLength()
com.hedera.pbj.runtime.io.buffer.DirectBufferedDataTest ‑ readBytesReturnsConstantEmptyForZeroLength()

@github-actions
Copy link
Copy Markdown

Integration Test Report

    409 files  ±0      409 suites  ±0   16m 25s ⏱️ +15s
114 853 tests ±0  114 853 ✅ ±0  0 💤 ±0  0 ❌ ±0 
115 094 runs  ±0  115 094 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit d040965. ± Comparison against base commit c2f6bdf.

This pull request removes 3 and adds 3 tests. Note that renamed tests count towards both.
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [1] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f92b0bc4000@59621804
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [2] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f92b0bc4230@589f936c
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [3] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007f92b0bc4460@3d657ebd
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [1] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007fcf17bbd518@15dbf6f4
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [2] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007fcf17bbd748@493b2893
com.hedera.pbj.integration.test.ParserNeverWrapsTest ‑ [3] com.hedera.pbj.integration.test.ParserNeverWrapsTest$$Lambda/0x00007fcf17bbd978@60e56cf9

@anthony-swirldslabs anthony-swirldslabs merged commit 6b108a7 into main Nov 17, 2025
12 checks passed
@anthony-swirldslabs anthony-swirldslabs deleted the 291-bytesEMPTY branch November 17, 2025 23:55
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.

Return Bytes.EMPTY from DirectBufferedData.readBytes() if length is zero

2 participants