Skip to content

Commit e375627

Browse files
committed
[golang] Add meta attribute PRESENCE to generated codecs. Issue #483.
1 parent a1a6819 commit e375627

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ task(generateGolangCodecsWithXSD, type: JavaExec) {
523523
'sbe-tool/src/test/resources/FixBinary.xml',
524524
'sbe-tool/src/test/resources/issue435.xml',
525525
'sbe-tool/src/test/resources/issue472.xml',
526+
'sbe-tool/src/test/resources/issue483.xml',
526527
'sbe-tool/src/test/resources/since-deprecated-test-schema.xml',
527528
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
528529
'gocode/resources/example-composite.xml',
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package issue483
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestPresence(t *testing.T) {
8+
issue483 := new(Issue483)
9+
10+
if issue483.UnsetMetaAttribute(4) != "required" {
11+
t.Log("Unset attribute's presence should be 'required'")
12+
t.Fail()
13+
}
14+
15+
if issue483.RequiredMetaAttribute(4) != "required" {
16+
t.Log("Required attribute's presence should be 'required'")
17+
t.Fail()
18+
}
19+
20+
if issue483.ConstantMetaAttribute(4) != "constant" {
21+
t.Log("Constant attribute's presence should be 'constant'")
22+
t.Fail()
23+
}
24+
25+
if issue483.OptionalMetaAttribute(4) != "optional" {
26+
t.Log("Optional attribute's presence should be 'optional'")
27+
t.Fail()
28+
}
29+
}

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,8 @@ private static void generateFieldMetaAttributeMethod(
21422142
final String epoch = encoding.epoch() == null ? "" : encoding.epoch();
21432143
final String timeUnit = encoding.timeUnit() == null ? "" : encoding.timeUnit();
21442144
final String semanticType = encoding.semanticType() == null ? "" : encoding.semanticType();
2145+
final String presence = encoding.presence() == null ? "" : encoding.presence().toString().toLowerCase();
2146+
21452147
sb.append(String.format(
21462148
"\nfunc (%1$s %2$s) %3$sMetaAttribute(meta int) string {\n" +
21472149
"\tswitch meta {\n" +
@@ -2151,6 +2153,8 @@ private static void generateFieldMetaAttributeMethod(
21512153
"\t\treturn \"%5$s\"\n" +
21522154
"\tcase 3:\n" +
21532155
"\t\treturn \"%6$s\"\n" +
2156+
"\tcase 4:\n" +
2157+
"\t\treturn \"%7$s\"\n" +
21542158
"\t}\n" +
21552159
"\treturn \"\"\n" +
21562160
"}\n",
@@ -2159,7 +2163,8 @@ private static void generateFieldMetaAttributeMethod(
21592163
toUpperFirstChar(token.name()),
21602164
epoch,
21612165
timeUnit,
2162-
semanticType));
2166+
semanticType,
2167+
presence));
21632168
}
21642169

21652170
private CharSequence generateMinValueLiteral(final PrimitiveType primitiveType, final Encoding encoding)

0 commit comments

Comments
 (0)