Skip to content

Issue#661 Always return a valid BitSet type #663

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ csharp/sbe-generated/extension
csharp/sbe-generated/issue435
csharp/sbe-generated/issue483
csharp/sbe-generated/issue560
csharp/sbe-generated/issue661
csharp/sbe-generated/since-deprecated
csharp/sbe-generated/mktdata/*.cs
csharp/sbe-generated/uk_co_real_logic_sbe_benchmarks_fix
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ task generateGolangCodecsWithXSD(type: JavaExec) {
'sbe-tool/src/test/resources/issue483.xml',
'sbe-tool/src/test/resources/issue488.xml',
'sbe-tool/src/test/resources/issue560.xml',
'sbe-tool/src/test/resources/issue661.xml',
'sbe-tool/src/test/resources/since-deprecated-test-schema.xml',
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
'gocode/resources/example-composite.xml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static uk.co.real_logic.sbe.ir.GenerationUtil.collectGroups;
import static uk.co.real_logic.sbe.ir.GenerationUtil.collectFields;

@SuppressWarnings("MethodLength")
public class CSharpGenerator implements CodeGenerator
{
private static final String META_ATTRIBUTE_ENUM = "MetaAttribute";
Expand Down Expand Up @@ -358,7 +357,6 @@ private CharSequence generateVarData(final List<Token> tokens, final String inde
indent + "public const int %sHeaderSize = %d;\n",
propertyName,
sizeOfLengthField));

sb.append(String.format(indent + "\n" +
indent + "public int %1$sLength()\n" +
indent + "{\n" +
Expand All @@ -369,12 +367,10 @@ private CharSequence generateVarData(final List<Token> tokens, final String inde
sizeOfLengthField,
lengthTypePrefix,
byteOrderStr));

sb.append(String.format("\n" +
indent + "public int Get%1$s(byte[] dst, int dstOffset, int length) =>\n" +
indent + INDENT + "Get%1$s(new Span<byte>(dst, dstOffset, length));\n",
propertyName));

sb.append(String.format("\n" +
indent + "public int Get%1$s(Span<byte> dst)\n" +
indent + "{\n" +
Expand All @@ -393,7 +389,6 @@ private CharSequence generateVarData(final List<Token> tokens, final String inde
sizeOfLengthField,
lengthTypePrefix,
byteOrderStr));

sb.append(String.format(indent + "\n" +
indent + "// Allocates and returns a new byte array\n" +
indent + "public byte[] Get%1$sBytes()\n" +
Expand All @@ -412,12 +407,10 @@ private CharSequence generateVarData(final List<Token> tokens, final String inde
sizeOfLengthField,
lengthTypePrefix,
byteOrderStr));

sb.append(String.format("\n" +
indent + "public int Set%1$s(byte[] src, int srcOffset, int length) =>\n" +
indent + INDENT + "Set%1$s(new ReadOnlySpan<byte>(src, srcOffset, length));\n",
propertyName));

sb.append(String.format("\n" +
indent + "public int Set%1$s(ReadOnlySpan<byte> src)\n" +
indent + "{\n" +
Expand Down Expand Up @@ -499,7 +492,7 @@ private CharSequence generateCompositePropertyElements(final List<Token> tokens,
final Token token = tokens.get(i);
final String propertyName = formatPropertyName(token.name());

// FIXME: do I need to pass class name down here for disambiguation
// FIXME: do I need to pass classname down here for disambiguation
switch (token.signal())
{
case ENCODING:
Expand Down Expand Up @@ -765,6 +758,22 @@ private CharSequence generateArrayFieldNotPresentCondition(
sinceVersion);
}

private CharSequence generateBitSetNotPresentCondition(
final int sinceVersion,
final String indent,
final String bitSetName)
{
if (0 == sinceVersion)
{
return "";
}

return String.format(
indent + INDENT + INDENT + INDENT + "if (_actingVersion < %1$d) return (%2$s)0;\n\n",
sinceVersion,
bitSetName);
}

private CharSequence generateTypeFieldNotPresentCondition(
final int sinceVersion,
final String indent)
Expand Down Expand Up @@ -1223,7 +1232,7 @@ private String generateBitSetProperty(final String propertyName, final Token tok
indent + INDENT + "}\n",
bitSetName,
toUpperFirstChar(propertyName),
generateTypeFieldNotPresentCondition(token.version(), indent),
generateBitSetNotPresentCondition(token.version(), indent, bitSetName),
bitSetName,
typePrefix,
offset,
Expand Down
25 changes: 25 additions & 0 deletions sbe-tool/src/test/resources/issue661.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
package="issue661"
id="661"
version="1"
semanticVersion="1.0"
description="issue 661 test case"
byteOrder="bigEndian">
<types>
<set name="set" encodingType="uint8">
<choice name="One">0</choice>
<choice name="Two">1</choice>
</set>
<composite name="messageHeader" description="Message identifiers and length of message root">
<type name="blockLength" primitiveType="uint16"/>
<type name="templateId" primitiveType="uint16"/>
<type name="schemaId" primitiveType="uint16"/>
<type name="version" primitiveType="uint16"/>
</composite>
</types>
<sbe:message name="issue661" id="1" description="issue 661 test">
<field name="set0" type="set" id="10"/>
<field name="set1" type="set" id="11" sinceVersion="1"/>
</sbe:message>
</sbe:messageSchema>