Skip to content

Commit 3f63562

Browse files
committed
[Java] Add bitset support to JsonPrinter. Issue #560.
1 parent 28cf8d6 commit 3f63562

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/json/JsonTokenListener.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,29 @@ public void onBitSet(
106106
final int toIndex,
107107
final int actingVersion)
108108
{
109+
final Token typeToken = tokens.get(fromIndex + 1);
110+
final long encodedValue = readEncodingAsLong(buffer, bufferIndex, typeToken, actingVersion);
111+
112+
property(fieldToken);
113+
114+
output.append("{ ");
115+
for (int i = fromIndex + 1; i < toIndex; i++)
116+
{
117+
output.append('"').append(tokens.get(i).name()).append("\": ");
118+
119+
final long bitPosition = tokens.get(i).encoding().constValue().longValue();
120+
final boolean flag = (encodedValue & (1L << bitPosition)) != 0;
121+
122+
output.append(Boolean.toString(flag));
123+
124+
if (i < (toIndex - 1))
125+
{
126+
output.append(", ");
127+
}
128+
}
129+
output.append(" }");
130+
131+
next();
109132
}
110133

111134
public void onBeginComposite(

sbe-tool/src/test/java/uk/co/real_logic/sbe/json/JsonPrinterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void exampleMessagePrintedAsJson() throws Exception
6161
" \"code\": \"A\",\n" +
6262
" \"someNumbers\": [0, 1, 2, 3, 4],\n" +
6363
" \"vehicleCode\": \"abcdef\",\n" +
64+
" \"extras\": { \"sunRoof\": false, \"sportsPack\": true, \"cruiseControl\": true },\n" +
6465
" \"capacity\": 2000,\n" +
6566
" \"numCylinders\": 4,\n" +
6667
" \"maxRpm\": 9000,\n" +

0 commit comments

Comments
 (0)