Skip to content

Commit 39e3947

Browse files
author
Vadim Platonov
committed
[Rust] Generate Debug for bit set
1 parent 25ef95f commit 39e3947

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/rust/RustGenerator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,34 @@ private static void generateSingleBitSet(final List<Token> tokens, final OutputM
196196

197197
writer.append("}\n");
198198
}
199+
200+
try (Writer writer = outputManager.createOutput(setType + " bit set debug"))
201+
{
202+
indent(writer, 0, "impl core::fmt::Debug for %s {\n", setType);
203+
indent(writer, 1, "fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {\n");
204+
indent(writer, 2, "write!(fmt, \"%s[", setType);
205+
206+
final StringBuilder string = new StringBuilder();
207+
final StringBuilder arguments = new StringBuilder();
208+
for (final Token token : tokens)
209+
{
210+
if (Signal.CHOICE != token.signal())
211+
{
212+
continue;
213+
}
214+
215+
final String choiceName = formatMethodName(token.name());
216+
final String choiceBitIndex = token.encoding().constValue().toString();
217+
218+
string.append(choiceName + "(" + choiceBitIndex + ")={},");
219+
arguments.append("self.get_" + choiceName + "(),");
220+
}
221+
222+
writer.append(string.toString() + "]\",\n");
223+
indent(writer, 3, arguments.toString() + ")\n");
224+
indent(writer, 1, "}\n");
225+
writer.append("}\n");
226+
}
199227
}
200228

201229
private static void generateMessageEncoder(

0 commit comments

Comments
 (0)