Skip to content

Commit 78854c8

Browse files
committed
[C++] IR was losing type information with the use of constant enums. Full enums are serialised and fields retain the constant property and encoded length rather than the type. Issue #560.
1 parent b5c1a7f commit 78854c8

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ private CharSequence generateEnumProperty(
17121712

17131713
final StringBuilder sb = new StringBuilder();
17141714

1715-
if (token.isConstantEncoding())
1715+
if (signalToken.isConstantEncoding())
17161716
{
17171717
final String constValue = signalToken.encoding().constValue().toString();
17181718

sbe-tool/src/test/cpp/Rc3OtfFullIrTest.cpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -640,28 +640,9 @@ class Rc3OtfFullIrTest : public testing::Test
640640
{
641641
EXPECT_EQ(fieldToken.fieldId(), fieldIdDiscountedModel);
642642
EXPECT_EQ(encoding.primitiveType(), PrimitiveType::CHAR);
643-
EXPECT_EQ(encoding.presence(), Presence::SBE_CONSTANT);
644-
EXPECT_TRUE(typeToken.isConstantEncoding());
645-
EXPECT_EQ(typeToken.encodedLength(), 0);
646-
647-
const PrimitiveValue value = encoding.constValue();
648-
649-
EXPECT_EQ(value.getAsInt(), static_cast<std::int64_t>('C'));
650-
bool found = false;
651-
for (size_t i = fromIndex + 1; i < toIndex; i++)
652-
{
653-
const Token& token = tokens.at(i);
654-
const std::int64_t constValue = token.encoding().constValue().getAsInt();
655-
656-
std::cout << " " << token.name() << " = " << constValue << "\n";
657-
658-
if (constValue == value.getAsInt())
659-
{
660-
EXPECT_EQ(token.name(), std::string("C"));
661-
found = true;
662-
}
663-
}
664-
EXPECT_TRUE(found);
643+
EXPECT_TRUE(fieldToken.isConstantEncoding());
644+
EXPECT_EQ(fieldToken.encodedLength(), 0);
645+
EXPECT_EQ(std::string(fieldToken.encoding().constValue().getArray()), std::string("Model.C"));
665646
break;
666647
}
667648

0 commit comments

Comments
 (0)