Skip to content

Commit 7d0222e

Browse files
committed
[C++] Address feedback from Todd re var data representation.
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.
1 parent 919aea0 commit 7d0222e

File tree

1 file changed

+4
-35
lines changed

1 file changed

+4
-35
lines changed

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

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,6 @@ private void generateVarDataDecodeWith(
724724
if (token.signal() == Signal.BEGIN_VAR_DATA)
725725
{
726726
final String propertyName = token.name();
727-
final Token varDataToken = Generators.findFirst("varData", tokens, i);
728-
final String characterEncoding = varDataToken.encoding().characterEncoding();
729727
final String formattedPropertyName = formatPropertyName(propertyName);
730728

731729
final boolean isOptional = token.version() > 0;
@@ -739,19 +737,8 @@ private void generateVarDataDecodeWith(
739737
.append(blockIndent).append("const char* ").append(dataVar)
740738
.append(" = codec.").append(formattedPropertyName).append("();\n");
741739

742-
final String dtoValue;
743-
final String nullDtoValue;
744-
745-
if (characterEncoding == null)
746-
{
747-
dtoValue = "std::vector<std::uint8_t>(" + dataVar + ", " + dataVar + " + " + lengthVar + ")";
748-
nullDtoValue = "std::vector<std::uint8_t>()";
749-
}
750-
else
751-
{
752-
dtoValue = "std::string(" + dataVar + ", " + lengthVar + ")";
753-
nullDtoValue = "\"\"";
754-
}
740+
final String dtoValue = "std::string(" + dataVar + ", " + lengthVar + ")";
741+
final String nullDtoValue = "\"\"";
755742

756743
if (isOptional)
757744
{
@@ -1129,29 +1116,13 @@ private void generateVarDataEncodeWith(
11291116
if (token.signal() == Signal.BEGIN_VAR_DATA)
11301117
{
11311118
final String propertyName = token.name();
1132-
final Token lengthToken = Generators.findFirst("length", tokens, i);
1133-
final String lengthTypeName = cppTypeName(lengthToken.encoding().primitiveType());
1134-
final Token varDataToken = Generators.findFirst("varData", tokens, i);
1135-
final String characterEncoding = varDataToken.encoding().characterEncoding();
11361119
final String formattedPropertyName = formatPropertyName(propertyName);
11371120
final String varName = toLowerFirstChar(propertyName) + "Vector";
11381121

11391122
sb.append(indent).append("auto& ").append(varName).append(" = dto.")
11401123
.append(formattedPropertyName).append("();\n")
11411124
.append(indent).append("codec.put").append(toUpperFirstChar(propertyName))
1142-
.append("(");
1143-
1144-
if (null == characterEncoding)
1145-
{
1146-
sb.append("reinterpret_cast<const char*>(").append(varName).append(".data()), ")
1147-
.append("static_cast<").append(lengthTypeName).append(">(").append(varName).append(".size())");
1148-
}
1149-
else
1150-
{
1151-
sb.append(varName);
1152-
}
1153-
1154-
sb.append(");\n");
1125+
.append("(").append(varName).append(");\n");
11551126
}
11561127
}
11571128
}
@@ -1629,9 +1600,7 @@ private void generateVarData(
16291600
if (token.signal() == Signal.BEGIN_VAR_DATA)
16301601
{
16311602
final String propertyName = token.name();
1632-
final Token varDataToken = Generators.findFirst("varData", tokens, i);
1633-
final String characterEncoding = varDataToken.encoding().characterEncoding();
1634-
final String dtoType = characterEncoding == null ? "std::vector<std::uint8_t>" : "std::string";
1603+
final String dtoType = "std::string";
16351604

16361605
final String fieldName = "m_" + toLowerFirstChar(propertyName);
16371606
final String formattedPropertyName = formatPropertyName(propertyName);

0 commit comments

Comments
 (0)