hashgraph / hashgraph/pbj

Extract sub-message processing to `com.hedera.pbj.runtime.ProtoParserTools`

Open
#132 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
44
Forks
15
Avg merge
1d 15h
Merged PRs (30d)
12

Description

### Problem

Currently `com.hedera.pbj.compiler.impl.generators.protobuf.CodecParseMethodGenerator` has the following code to process nested messages:
```
final var messageLength = input.readVarInt(false);
final var limitBefore = input.limit();
// Make sure that we have enough bytes in the message
// to read the subObject.
// If the buffer is truncated on the boundary of a subObject,
// we will not throw.
final var startPos = input.position();
if ((startPos + messageLength) > limitBefore)
throw new BufferOverflowException();
input.limit(startPos + messageLength);
final var value = $readMethod;
// Make sure we read the full number of bytes. for the types
if ((startPos + messageLength) != input.position()) {
throw new BufferOverflowException();
}
input.limit(limitBefore);

```
The only way to test it is indirect, that is to test the generated code

### Solution

This block can be moved to `com.hedera.pbj.runtime.ProtoParserTools` and unit-tested directly. However, it will require certain refactoring. In particular `$readMethod;` has to be passed to the method as lambda expression. Though it looks better and gives a benefit of direct unit testing, it can cause potential performance issue due to additional pressure on garbage collector.

That is, if we want to do this refactoring, we have to run performance tests to make sure that it doesn't incur a significant performance penalty

### Alternatives

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.