Skip to content

Generate noChoicesSet convenience method for Sets #575

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jul 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ private void generateBitSet(final List<Token> tokens) throws IOException
try (Writer out = outputManager.createOutput(decoderName))
{
generateFixedFlyweightHeader(token, decoderName, out, readOnlyBuffer, fqReadOnlyBuffer);
out.append(generateNoChoicesSet(token.encoding().primitiveType()));
out.append(generateChoiceDecoders(messageBody));
out.append(generateChoiceDisplay(messageBody));
out.append("}\n");
Expand Down Expand Up @@ -2740,6 +2741,34 @@ private String generatePut(
throw new IllegalArgumentException("primitive type not supported: " + type);
}

private String generateNoChoicesSet(final PrimitiveType type)
{
return String.format(
"\n public boolean isEmpty()\n" +
" {\n" +
" return %1$s;\n" +
" }\n", generateChoiceUnsetInner(type));
}

private String generateChoiceUnsetInner(PrimitiveType type) {
switch (type)
{
case UINT8:
return "0 == buffer.getByte(offset)";

case UINT16:
return "0 == buffer.getShort(offset)";

case UINT32:
return "0 == buffer.getInt(offset)";

case UINT64:
return "0 == buffer.getLong(offset)";
}

throw new IllegalArgumentException("primitive type not supported: " + type);
}

private String generateChoiceGet(final PrimitiveType type, final String bitIndex, final String byteOrder)
{
switch (type)
Expand Down