Skip to content

Commit 2f698d2

Browse files
committed
[C++] Add method to put var length string from std::string_view.
1 parent 10e9bf2 commit 2f698d2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,22 @@ private void generateVarData(
602602
lengthCppType,
603603
lengthToken.encoding().applicableMaxValue().longValue());
604604

605+
new Formatter(sb).format("\n" +
606+
indent + " #if __cplusplus >= 201703L\n" +
607+
indent + " %1$s &put%2$s(const std::string_view str)\n" +
608+
indent + " {\n" +
609+
indent + " if (str.length() > %4$d)\n" +
610+
indent + " {\n" +
611+
indent + " throw std::runtime_error(\"std::string too long for length type [E109]\");\n" +
612+
indent + " }\n" +
613+
indent + " return put%2$s(str.data(), static_cast<%3$s>(str.length()));" +
614+
indent + " }\n" +
615+
indent + " #endif\n",
616+
className,
617+
propertyName,
618+
lengthCppType,
619+
lengthToken.encoding().applicableMaxValue().longValue());
620+
605621
i += token.componentTokenCount();
606622
}
607623
}

0 commit comments

Comments
 (0)