Skip to content

Commit

Permalink
[golang] Add meta attribute PRESENCE to generated codecs. Issue real-…
Browse files Browse the repository at this point in the history
  • Loading branch information
billsegall committed Aug 4, 2017
1 parent a1a6819 commit e375627
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ task(generateGolangCodecsWithXSD, type: JavaExec) {
'sbe-tool/src/test/resources/FixBinary.xml',
'sbe-tool/src/test/resources/issue435.xml',
'sbe-tool/src/test/resources/issue472.xml',
'sbe-tool/src/test/resources/issue483.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
29 changes: 29 additions & 0 deletions gocode/src/issue483/Issue483_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package issue483

import (
"testing"
)

func TestPresence(t *testing.T) {
issue483 := new(Issue483)

if issue483.UnsetMetaAttribute(4) != "required" {
t.Log("Unset attribute's presence should be 'required'")
t.Fail()
}

if issue483.RequiredMetaAttribute(4) != "required" {
t.Log("Required attribute's presence should be 'required'")
t.Fail()
}

if issue483.ConstantMetaAttribute(4) != "constant" {
t.Log("Constant attribute's presence should be 'constant'")
t.Fail()
}

if issue483.OptionalMetaAttribute(4) != "optional" {
t.Log("Optional attribute's presence should be 'optional'")
t.Fail()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,8 @@ private static void generateFieldMetaAttributeMethod(
final String epoch = encoding.epoch() == null ? "" : encoding.epoch();
final String timeUnit = encoding.timeUnit() == null ? "" : encoding.timeUnit();
final String semanticType = encoding.semanticType() == null ? "" : encoding.semanticType();
final String presence = encoding.presence() == null ? "" : encoding.presence().toString().toLowerCase();

sb.append(String.format(
"\nfunc (%1$s %2$s) %3$sMetaAttribute(meta int) string {\n" +
"\tswitch meta {\n" +
Expand All @@ -2151,6 +2153,8 @@ private static void generateFieldMetaAttributeMethod(
"\t\treturn \"%5$s\"\n" +
"\tcase 3:\n" +
"\t\treturn \"%6$s\"\n" +
"\tcase 4:\n" +
"\t\treturn \"%7$s\"\n" +
"\t}\n" +
"\treturn \"\"\n" +
"}\n",
Expand All @@ -2159,7 +2163,8 @@ private static void generateFieldMetaAttributeMethod(
toUpperFirstChar(token.name()),
epoch,
timeUnit,
semanticType));
semanticType,
presence));
}

private CharSequence generateMinValueLiteral(final PrimitiveType primitiveType, final Encoding encoding)
Expand Down

0 comments on commit e375627

Please sign in to comment.