Skip to content

Commit fbd0955

Browse files
committed
Fix a bug in populating optional values when they are arrays
1 parent 027fe21 commit fbd0955

File tree

3 files changed

+18
-99
lines changed

3 files changed

+18
-99
lines changed

gocode/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ src/baseline/SbeMarshalling.go: $(DEP)
5959
# they geenrate into the same directory but golang doesn't allow that
6060
test: $(DEP)
6161
(export GOPATH=$(GOPATH) && \
62-
(for t in baseline extension extension2; do \
62+
(for t in baseline extension; do \
6363
export GOPATH=$(GOPATH) && \
6464
cd $(GOPATH)/src/$$t && \
6565
go build && \

gocode/resources/example-extension-2-schema.xml

Lines changed: 0 additions & 94 deletions
This file was deleted.

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,23 @@ private void generateOptionalInitPrimitive(
494494
final Encoding encoding = token.encoding();
495495

496496
// Optional items get initialized to their NullValue
497-
sb.append(String.format(
498-
"\t%1$s = %2$s\n",
499-
varName,
500-
generateNullValueLiteral(encoding.primitiveType(), encoding)));
497+
if (token.arrayLength() > 1)
498+
{
499+
sb.append(String.format(
500+
"\tfor idx := 0; idx < %1$d; idx++ {\n" +
501+
"\t\t%2$s[idx] = %3$s\n" +
502+
"\t}\n",
503+
token.arrayLength(),
504+
varName,
505+
generateNullValueLiteral(encoding.primitiveType(), encoding)));
506+
}
507+
else
508+
{
509+
sb.append(String.format(
510+
"\t%1$s = %2$s\n",
511+
varName,
512+
generateNullValueLiteral(encoding.primitiveType(), encoding)));
513+
}
501514
}
502515

503516
private void generateConstantInitPrimitive(

0 commit comments

Comments
 (0)