Skip to content

BufferedData to provide random write access API #790

@artemananiev

Description

@artemananiev

ByteBuffer provide two sets of methods to write data. First, write to the current position, e.g. put(byte). Second, write to a specified position, e.g. put(offset, byte). This isn't limited to bytes, there are similar methods for byte arrays, byte buffers, etc.

BufferedData is a PBJ wrapper on top of ByteBuffer. It provides methods to read data at the current position (e.g. readByte()) and at a given offset (e.g. getByte(offset)), but only methods to write data to the current position (e.g. writeByte(byte)). There are no methods to write data to a specified offset. I'd expect them to be named putByte(offset, byte) to be consistent with getByte().

As a result, there are no methods in high level write APIs like ProtoWriterTools. This class has methods to write data to the current position of a given buffer (typically, WritableSequentialData), but no methods to write to a given offset. Such missing methods wouldn't work with WritableSequentialData, since, well, it's sequential, but they can be implemented for BufferedData or similar. It may be reasonable to introduce a new interface like WritableRandomAccessData for this purpose, and let BufferedData implement it, but I'm not 100% sure about this idea.

Metadata

Metadata

Labels

ImprovementCode changes driven by non business requirements.PerformanceIssues related to performance concerns.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions