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

Variable length field in repeating group c++ compilation error #795

Closed
solarprime opened this issue Jun 4, 2020 · 3 comments
Closed

Variable length field in repeating group c++ compilation error #795

solarprime opened this issue Jun 4, 2020 · 3 comments

Comments

@solarprime
Copy link

solarprime commented Jun 4, 2020

No. The specification does not allow for variable length fields in a composite.

Variable length fields can be added at the end of a repeating group or the end of a message. You can compose something more complex with repeating groups or multiple messages.

Originally posted by @mjpt777 in #485 (comment)

There seems to be an issue with the generated c++ code when adding a variable length field inside a repeating group. The computeLength function is marked constexpr but calls std::vector<>::size(), which is a non-constexpr function.

    <sbe:message name="MyMessage" id="1" >
        <field name="sessionId" id="1" type="SessionId"/>
        <field name="method" id="2" type="Method"/>
        <group name="extraSendHeaders" id="5" dimensionType="groupSizeEncoding">
            <field name="headerKey" id="6" type="HeaderEnum"/>
            <data name="headerValue" id="7" type="varStringEncoding"/>
        </group>
    </sbe:message>
SBE_NODISCARD static SBE_CONSTEXPR_14 size_t computeLength(const std::vector<std::tuple<std::size_t>>& extraSendHeadersItemLengths = {})
{
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
    size_t length = sbeBlockLength();


    length += ExtraSendHeaders::sbeHeaderSize();
    if (extraSendHeadersItemLengths.size() > 65534)
    {
        throw std::runtime_error("extraSendHeadersItemLengths.size() outside of allowed range [E110]");
    }
    for (const auto& e: extraSendHeadersItemLengths)
    {
        #if __cpluplus >= 201703L
        length += std::apply(ExtraSendHeaders::computeLength, e);
        #else
        length += ExtraSendHeaders::computeLength(std::get<0>(e));
        #endif
    }
    return length;
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
}
@solarprime
Copy link
Author

solarprime commented Jun 4, 2020

Verified that compilation of the SBE tests fail with -std=c++14 and -std=c++17.

[ 41%] Built target codecs
In file included from ~/simple-binary-encoding/sbe-samples/src/main/cpp/GeneratedStubExample.cpp:24:
~/simple-binary-encoding/cppbuild/Release/generated/cpp/baseline/Car.h: In static member function ‘static constexpr size_t baseline::Car::computeLength(const std::vector<std::tuple<long unsigned int> >&, const std::vector<std::tuple<long unsigned int> >&, std::size_t, std::size_t, std::size_t)’:
~/simple-binary-encoding/cppbuild/Release/generated/cpp/baseline/Car.h:2991:36: error: call to non-‘constexpr’ function ‘std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = std::tuple<long unsigned int>; _Alloc = std::allocator<std::tuple<long unsigned int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int]’
 2991 |     if (fuelFiguresItemLengths.size() > 65534)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

@solarprime solarprime reopened this Jun 6, 2020
@tmontgomery
Copy link
Contributor

SBE_CONSTEXPR_14 has been removed in 494b00a

@solarprime
Copy link
Author

Thanks Todd.

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

No branches or pull requests

2 participants