Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Generate DTOs for non-perf-sensitive usecases. #960

Closed
wants to merge 6 commits into from

Conversation

ZachBray
Copy link
Contributor

@ZachBray ZachBray commented Nov 2, 2023

No description provided.

@ZachBray ZachBray force-pushed the feature/cpp-dtos branch 2 times, most recently from 0ba6b3c to 8f3b436 Compare November 2, 2023 16:00
In some applications performance is not cricital. Some users would like
to use SBE across their whole "estate", but don't want the "sharp edges"
associated with using flyweight codecs, e.g., accidental escape.

In this commit, I've added a first cut of DTO generation for C++ and a
simple test based on the Car Example.

The DTOs support encoding and decoding via the generated codecs using
`DtoT::encode(CodecT& codec, const DtoT& dto)` and
`DtoT::decode(CodecT& codec, Dto& dto)` methods.

Generation can be enabled specifying the target code generator class,
`uk.co.real_logic.sbe.generation.cpp.CppDtos`, or by passing a
system property `-Dsbe.cpp.generate.dtos=true`.
@ZachBray ZachBray force-pushed the feature/cpp-dtos branch 5 times, most recently from 488e490 to 695d0da Compare November 3, 2023 09:43
Changes:

- `encode` -> `encodeWith`
- `decode` -> `decodeWith`
As we use the generated codecs to create a string representation of our
DTOs, we don't use Agrona buffers in C++, and there is no concept of
resizing, it is necessary to size a temporary buffer during the
construction of the string data.

Previously, we were letting the user supply this value, which wasn't a
very friendly API.

Now, we use the `computeLength` methods on the codec to determine how
big of a temporary buffer we need.

Perhaps the methods will also be useful for avoiding a buffer copy when
used in conjunction with Aeron. For example, a developer could use
`dto.computeEncodedLength()` to initialise a buffer claim rather than
copying via the `offer(...)` API.
I had incorrectly assumed that the `Flyweight::computeLength` method
took _encoded lengths_ of groups etc., but actually it takes a
complicated structure of group counts and variable lengths. As it was
hard to build this list, I've opted for a simpler approach: do the
length calculation within the generated DTO message and its groups.

In this commit, I've also added some convenience methods for converting
between DTOs and "byte arrays".
It is more-idiomatic to represent variable-length data using
`std::string` even when there is no character encoding specified, the
the `std::string` API provides useful utilities regardless.
@ZachBray
Copy link
Contributor Author

Combining with C# changes, as both rely on PBT infrastructure.

@ZachBray ZachBray closed this Nov 11, 2023
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.

1 participant