Skip to content

Commit 2edef0e

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java
2 parents 6e0c0a5 + 0d530c5 commit 2edef0e

File tree

24 files changed

+1648
-374
lines changed

24 files changed

+1648
-374
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ cppbuild/Win32
6666
gocode/pkg
6767
gocode/src/baseline/*.go
6868
!gocode/src/baseline/*_test.go
69+
gocode/src/baseline-bigendian/*.go
70+
!gocode/src/baseline/-bigendian/*_test.go
6971
gocode/src/composite/*.go
7072
!gocode/src/composite/*_test.go
7173
gocode/src/composite_elements/*.go
@@ -80,6 +82,8 @@ gocode/src/*/*/*.go
8082
!gocode/src/*/*/*_test.go
8183
gocode/src/example-schema/example-schema*
8284
gocode/src/example-schema/cpu.out
85+
gocode/src/example-socket-clientserver/example-socket-clientserver
86+
gocode/src/example-schema/cpu.out
8387
gocode/src/extension
8488
gocode/src/extension2
8589

gocode/Makefile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@ SCHEMA_DIR=$(ROOT)/sbe-samples/src/main/resources
3131
EXAMPLES_SCHEMA=$(SCHEMA_DIR)/example-schema.xml
3232
EXTENSION_SCHEMA=$(SCHEMA_DIR)/example-extension-schema.xml
3333
EXTENSION2_SCHEMA=$(XMLLOCAL)/example-extension-2-schema.xml
34+
BIGENDIAN_SCHEMA=$(XMLLOCAL)/example-bigendian.xml
3435
GROUP_EXTENSION=$(XMLLOCAL)/group-with-data-extension-schema.xml
3536

3637
# Convenience during development
3738
#SAVE_FORMAT=mkdir -p fmt && cp *.go fmt &&
3839
SAVE_FORMAT=
3940

40-
$(OUTPUTDIR)/example-schema/example-schema: $(SBE_JAR) $(OUTPUTDIR)/baseline/Car.go $(OUTPUTDIR)/extension/Car.go $(OUTPUTDIR)/extension2/Car.go $(OUTPUTDIR)/example-schema/CarExample.go
41+
$(OUTPUTDIR)/example-schema/example-schema: $(SBE_JAR) $(OUTPUTDIR)/baseline/SbeMarshalling.go $(OUTPUTDIR)/baseline-bigendian/SbeMarshalling.go $(OUTPUTDIR)/extension/SbeMarshalling.go $(OUTPUTDIR)/extension2/SbeMarshalling.go $(OUTPUTDIR)/example-schema/CarExample.go $(OUTPUTDIR)/example-schema/CarExample_test.go
4142
(export GOPATH=$(GOPATH) && \
4243
cd $(OUTPUTDIR)/example-schema && \
4344
go build && \
4445
go fmt && \
4546
./example-schema)
4647

4748
clean:
48-
rm -f $(OUTPUTDIR)/baseline/Car.go $(OUTPUTDIR)/extension/Car.go $(OUTPUTDIR)/extension2/Car.go
49+
rm -f $(OUTPUTDIR)/*/SbeMarshalling.go $(OUTPUTDIR)/*/*/SbeMarshalling.go
4950

50-
$(OUTPUTDIR)/baseline/Car.go: $(SBE_JAR)
51+
$(OUTPUTDIR)/baseline/SbeMarshalling.go: $(SBE_JAR)
5152
$(JAVA) \
5253
-Dsbe.output.dir=$(OUTPUTDIR) \
5354
-Dsbe.generate.ir="false" \
@@ -61,7 +62,21 @@ $(OUTPUTDIR)/baseline/Car.go: $(SBE_JAR)
6162
go test && \
6263
go install)
6364

64-
$(OUTPUTDIR)/extension/Car.go: $(SBE_JAR)
65+
$(OUTPUTDIR)/baseline-bigendian/SbeMarshalling.go: $(SBE_JAR)
66+
$(JAVA) \
67+
-Dsbe.output.dir=$(OUTPUTDIR) \
68+
-Dsbe.generate.ir="false" \
69+
-Dsbe.target.language="golang" \
70+
-jar ${SBE_JAR} \
71+
$(BIGENDIAN_SCHEMA)
72+
(export GOPATH=$(GOPATH) && \
73+
cd $(OUTPUTDIR)/baseline-bigendian && \
74+
go build && \
75+
go fmt && \
76+
go test && \
77+
go install)
78+
79+
$(OUTPUTDIR)/extension/SbeMarshalling.go: $(SBE_JAR)
6580
$(JAVA) \
6681
-Dsbe.output.dir=$(OUTPUTDIR) \
6782
-Dsbe.generate.ir="false" \
@@ -73,7 +88,7 @@ $(OUTPUTDIR)/extension/Car.go: $(SBE_JAR)
7388
go build && \
7489
go install)
7590

76-
$(OUTPUTDIR)/extension2/Car.go: $(SBE_JAR)
91+
$(OUTPUTDIR)/extension2/SbeMarshalling.go: $(SBE_JAR)
7792
$(JAVA) \
7893
-Dsbe.output.dir=$(OUTPUTDIR) \
7994
-Dsbe.generate.ir="false" \
@@ -89,7 +104,7 @@ bench: $(SBE_JAR) $(OUTPUTDIR)/example-schema/example-schema
89104
(export GOPATH=$(GOPATH) && \
90105
cd $(OUTPUTDIR)/example-schema && \
91106
go test --bench . -cpuprofile=cpu.out && \
92-
go tool pprof -text example-schema cpu.out)
107+
go tool pprof -text example-schema.test cpu.out)
93108

94109
test: fix-binary nested-group nested-group-extension basic-vardata basic-group basic-types simple composite composite-elements
95110

gocode/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,8 @@ decide what to with golang `Time`'s nanosecond timer when converting
124124

125125
Roadmap
126126
=======
127-
* Examples documented
127+
* Further examples and doumentation
128128
* Windows developer support (currently tested on Linux/MacOS)
129-
* Enhance Design/Rationale document (this one)
130-
* presence=optional
131129
* Unnecessary code removal (e.g., GroupSizeEncoding)
132130
* Further Unicode support
133131
* Testing/Bug fixes
134-
* Benchmarking & Performance Enhancements
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
3+
package="baseline-bigendian"
4+
id="1"
5+
version="0"
6+
semanticVersion="5.2"
7+
description="Example schema"
8+
byteOrder="bigEndian">
9+
<types>
10+
<composite name="messageHeader" description="Message identifiers and length of message root">
11+
<type name="blockLength" primitiveType="uint16"/>
12+
<type name="templateId" primitiveType="uint16"/>
13+
<type name="schemaId" primitiveType="uint16"/>
14+
<type name="version" primitiveType="uint16"/>
15+
</composite>
16+
<composite name="groupSizeEncoding" description="Repeating group dimensions">
17+
<type name="blockLength" primitiveType="uint16"/>
18+
<type name="numInGroup" primitiveType="uint16"/>
19+
</composite>
20+
<composite name="varDataEncoding">
21+
<type name="length" primitiveType="uint32" maxValue="1073741824"/>
22+
<type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/>
23+
</composite>
24+
</types>
25+
<types>
26+
<type name="ModelYear" primitiveType="uint16"/>
27+
<type name="VehicleCode" primitiveType="char" length="6" characterEncoding="ASCII"/>
28+
<type name="Ron" primitiveType="uint8" minValue="90" maxValue="110"/>
29+
<type name="someNumbers" primitiveType="uint32" length="5"/>
30+
<composite name="Booster">
31+
<enum name="BoostType" encodingType="char">
32+
<validValue name="TURBO">T</validValue>
33+
<validValue name="SUPERCHARGER">S</validValue>
34+
<validValue name="NITROUS">N</validValue>
35+
<validValue name="KERS">K</validValue>
36+
</enum>
37+
<type name="horsePower" primitiveType="uint8"/>
38+
</composite>
39+
<composite name="Engine">
40+
<type name="capacity" primitiveType="uint16"/>
41+
<type name="numCylinders" primitiveType="uint8"/>
42+
<type name="maxRpm" primitiveType="uint16" presence="constant">9000</type>
43+
<type name="manufacturerCode" primitiveType="char" length="3"/>
44+
<type name="fuel" primitiveType="char" presence="constant">Petrol</type>
45+
<ref name="booster" type="Booster"/>
46+
</composite>
47+
<enum name="BooleanType" encodingType="uint8">
48+
<validValue name="F">0</validValue>
49+
<validValue name="T">1</validValue>
50+
</enum>
51+
<enum name="Model" encodingType="char">
52+
<validValue name="A">A</validValue>
53+
<validValue name="B">B</validValue>
54+
<validValue name="C">C</validValue>
55+
</enum>
56+
<set name="OptionalExtras" encodingType="uint8">
57+
<choice name="sunRoof">0</choice>
58+
<choice name="sportsPack">1</choice>
59+
<choice name="cruiseControl">2</choice>
60+
</set>
61+
</types>
62+
<sbe:message name="Car" id="1" description="Description of a basic Car">
63+
<field name="serialNumber" id="1" type="uint64"/>
64+
<field name="modelYear" id="2" type="ModelYear"/>
65+
<field name="available" id="3" type="BooleanType"/>
66+
<field name="code" id="4" type="Model"/>
67+
<field name="someNumbers" id="5" type="someNumbers"/>
68+
<field name="vehicleCode" id="6" type="VehicleCode"/>
69+
<field name="extras" id="7" type="OptionalExtras"/>
70+
<field name="discountedModel" id="8" type="Model" presence="constant" valueRef="Model.C"/>
71+
<field name="engine" id="9" type="Engine"/>
72+
<group name="fuelFigures" id="10" dimensionType="groupSizeEncoding">
73+
<field name="speed" id="11" type="uint16"/>
74+
<field name="mpg" id="12" type="float"/>
75+
<data name="usageDescription" id="200" type="varDataEncoding"/>
76+
</group>
77+
<group name="performanceFigures" id="13" dimensionType="groupSizeEncoding">
78+
<field name="octaneRating" id="14" type="Ron"/>
79+
<group name="acceleration" id="15" dimensionType="groupSizeEncoding">
80+
<field name="mph" id="16" type="uint16"/>
81+
<field name="seconds" id="17" type="float"/>
82+
</group>
83+
</group>
84+
<data name="manufacturer" id="18" type="varDataEncoding"/>
85+
<data name="model" id="19" type="varDataEncoding"/>
86+
<data name="activationCode" id="20" type="varDataEncoding"/>
87+
</sbe:message>
88+
</sbe:messageSchema>

gocode/resources/simple.xml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,27 @@
1818
<type name="ascii6" primitiveType="char" semanticType="String" length="6" characterEncoding="ASCII"/>
1919
<type name="ascii1" primitiveType="char" semanticType="String" length="1" characterEncoding="ASCII"/>
2020
<type name="int2" primitiveType="int32" length="2"/>
21+
<type name="uint64nv" presence="optional" nullValue="18446744073709551615" description="Large Null Value test" primitiveType="uint64"/>
22+
2123
<!-- not yet
2224
<type name="utf86" primitiveType="char" semanticType="String" length="6" characterEncoding="UTF-8"/>
2325
<type name="utf166" primitiveType="char" semanticType="String" length="6" characterEncoding="UTF-8"/>
2426
-->
2527
</types>
2628
<sbe:message name="Simple0" id="11" semanticType="womble" description="A very simple first example" blockLength="76">
27-
<field name="U64" id="1" type="uint64" deprecated="2" sinceVersion="1"/>
28-
<field name="U32" id="2" type="uint32"/>
29-
<field name="U16" id="3" type="uint16"/>
30-
<field name="U8" id="4" type="uint8"/>
31-
<field name="S8" id="5" type="int8" offset="31"/>
32-
<field name="S16" id="6" type="int16"/>
33-
<field name="S32" id="7" type="int32"/>
34-
<field name="S64" id="8" type="int64"/>
35-
<field name="F32" id="9" type="float"/>
36-
<field name="D64" id="10" type="double"/>
37-
<field name="String6ASCII" id="11" type="ascii6"/>
38-
<field name="String1ASCII" id="12" type="ascii1"/>
39-
<field name="Int2" id="13" type="int2"/>
29+
<field name="U64nv" id="10" type="uint64nv" sinceVersion="1"/>
30+
<field name="U64" id="20" type="uint64" deprecated="2" sinceVersion="1" presence="optional" nullValue="18446744073709551615"/>
31+
<field name="U32" id="30" type="uint32"/>
32+
<field name="U16" id="40" type="uint16"/>
33+
<field name="U8" id="50" type="uint8"/>
34+
<field name="S8" id="60" type="int8" offset="31"/>
35+
<field name="S16" id="70" type="int16"/>
36+
<field name="S32" id="80" type="int32"/>
37+
<field name="S64" id="90" type="int64"/>
38+
<field name="F32" id="100" type="float"/>
39+
<field name="D64" id="110" type="double"/>
40+
<field name="String6ASCII" id="120" type="ascii6"/>
41+
<field name="String1ASCII" id="130" type="ascii1"/>
42+
<field name="Int2" id="140" type="int2"/>
4043
</sbe:message>
4144
</sbe:messageSchema>
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package baseline_bigendian
2+
3+
import (
4+
"bytes"
5+
_ "fmt"
6+
"testing"
7+
)
8+
9+
func TestEncodeDecodeCar(t *testing.T) {
10+
11+
m := NewSbeGoMarshaller()
12+
var vehicleCode [6]byte
13+
copy(vehicleCode[:], "abcdef")
14+
15+
var manufacturerCode [3]byte
16+
copy(manufacturerCode[:], "123")
17+
18+
var optionalExtras [8]bool
19+
optionalExtras[OptionalExtrasChoice.CruiseControl] = true
20+
optionalExtras[OptionalExtrasChoice.SportsPack] = true
21+
22+
var engine Engine
23+
engine = Engine{2000, 4, 0, manufacturerCode, [6]byte{}, EngineBooster{BoostType.NITROUS, 200}}
24+
25+
manufacturer := []uint8("Honda")
26+
model := []uint8("Civic VTi")
27+
activationCode := []uint8("deadbeef")
28+
29+
var fuel []CarFuelFigures
30+
fuel = append(fuel, CarFuelFigures{30, 35.9, []uint8("Urban Cycle")})
31+
fuel = append(fuel, CarFuelFigures{55, 49.0, []uint8("Combined Cycle")})
32+
fuel = append(fuel, CarFuelFigures{75, 40.0, []uint8("Highway Cycle")})
33+
34+
var acc1 []CarPerformanceFiguresAcceleration
35+
acc1 = append(acc1, CarPerformanceFiguresAcceleration{30, 3.8})
36+
acc1 = append(acc1, CarPerformanceFiguresAcceleration{60, 7.5})
37+
acc1 = append(acc1, CarPerformanceFiguresAcceleration{100, 12.2})
38+
39+
var acc2 []CarPerformanceFiguresAcceleration
40+
acc2 = append(acc2, CarPerformanceFiguresAcceleration{30, 3.8})
41+
acc2 = append(acc2, CarPerformanceFiguresAcceleration{60, 7.5})
42+
acc2 = append(acc2, CarPerformanceFiguresAcceleration{100, 12.2})
43+
44+
var pf []CarPerformanceFigures
45+
pf = append(pf, CarPerformanceFigures{95, acc1})
46+
pf = append(pf, CarPerformanceFigures{99, acc2})
47+
48+
in := Car{1234, 2013, BooleanType.T, Model.A, [5]uint32{0, 1, 2, 3, 4}, vehicleCode, optionalExtras, Model.A, engine, fuel, pf, manufacturer, model, activationCode}
49+
50+
var buf = new(bytes.Buffer)
51+
if err := in.Encode(m, buf, true); err != nil {
52+
t.Logf("Encoding Error", err)
53+
t.Fail()
54+
}
55+
56+
var out Car = *new(Car)
57+
if err := out.Decode(m, buf, in.SbeSchemaVersion(), in.SbeBlockLength(), true); err != nil {
58+
t.Logf("Decoding Error", err)
59+
t.Fail()
60+
}
61+
62+
if in.SerialNumber != out.SerialNumber {
63+
t.Logf("in.SerialNumber != out.SerialNumber:\n", in.SerialNumber, out.SerialNumber)
64+
t.Fail()
65+
}
66+
if in.ModelYear != out.ModelYear {
67+
t.Logf("in.ModelYear != out.ModelYear:\n", in.ModelYear, out.ModelYear)
68+
t.Fail()
69+
}
70+
if in.Available != out.Available {
71+
t.Logf("in.Available != out.Available:\n", in.Available, out.Available)
72+
t.Fail()
73+
}
74+
if in.Code != out.Code {
75+
t.Logf("in.Code != out.Code:\n", in.Code, out.Code)
76+
t.Fail()
77+
}
78+
if in.SomeNumbers != out.SomeNumbers {
79+
t.Logf("in.SomeNumbers != out.SomeNumbers:\n", in.SomeNumbers, out.SomeNumbers)
80+
t.Fail()
81+
}
82+
if in.VehicleCode != out.VehicleCode {
83+
t.Logf("in.VehicleCode != out.VehicleCode:\n", in.VehicleCode, out.VehicleCode)
84+
t.Fail()
85+
}
86+
if in.Extras != out.Extras {
87+
t.Logf("in.Extras != out.Extras:\n", in.Extras, out.Extras)
88+
t.Fail()
89+
}
90+
91+
// DiscountedModel is constant
92+
if Model.C != out.DiscountedModel {
93+
t.Logf("in.DiscountedModel != out.DiscountedModel:\n", in.DiscountedModel, out.DiscountedModel)
94+
t.Fail()
95+
}
96+
97+
// Engine has two constant values which should come back filled in
98+
if in.Engine == out.Engine {
99+
t.Logf("in.Engine == out.Engine (and they should be different):\n", in.Engine, out.Engine)
100+
t.Fail()
101+
}
102+
103+
copy(in.Engine.Fuel[:], "Petrol")
104+
in.Engine.MaxRpm = 9000
105+
if in.Engine != out.Engine {
106+
t.Logf("in.Engine != out.Engine:\n", in.Engine, out.Engine)
107+
t.Fail()
108+
}
109+
110+
return
111+
112+
}
113+
114+
func TestDecodeJavaBuffer(t *testing.T) {
115+
116+
// The byte array is from the java example for interop test
117+
// made by editing example-schgema to be bigendian and running
118+
// with the example with -Dsbe.encoding.filename
119+
// and then decoded using od -tu1
120+
data := []byte{0, 47, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210, 7, 221, 1, 65, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 97, 98, 99, 100, 101, 102, 6, 7, 208, 4, 49, 50, 51, 78, 200, 0, 6, 0, 3, 0, 30, 66, 15, 153, 154, 0, 0, 0, 11, 85, 114, 98, 97, 110, 32, 67, 121, 99, 108, 101, 0, 55, 66, 68, 0, 0, 0, 0, 0, 14, 67, 111, 109, 98, 105, 110, 101, 100, 32, 67, 121, 99, 108, 101, 0, 75, 66, 32, 0, 0, 0, 0, 0, 13, 72, 105, 103, 104, 119, 97, 121, 32, 67, 121, 99, 108, 101, 0, 1, 0, 2, 95, 0, 6, 0, 3, 0, 30, 64, 128, 0, 0, 0, 60, 64, 240, 0, 0, 0, 100, 65, 67, 51, 51, 99, 0, 6, 0, 3, 0, 30, 64, 115, 51, 51, 0, 60, 64, 227, 51, 51, 0, 100, 65, 60, 204, 205, 0, 0, 0, 5, 72, 111, 110, 100, 97, 0, 0, 0, 9, 67, 105, 118, 105, 99, 32, 86, 84, 105, 0, 0, 0, 6, 97, 98, 99, 100, 101, 102}
121+
122+
buf := bytes.NewBuffer(data)
123+
m := NewSbeGoMarshaller()
124+
125+
var hdr SbeGoMessageHeader
126+
if err := hdr.Decode(m, buf); err != nil {
127+
t.Logf("Failed to decode message header", err)
128+
t.Fail()
129+
}
130+
131+
// fmt.Println("BlockLength = ", m.BlockLength)
132+
// fmt.Println("TemplateId = ", m.TemplateId)
133+
// fmt.Println("SchemaId = ", m.SchemaId)
134+
// fmt.Println("Version = ", m.Version)
135+
// fmt.Println("bytes: ", buf.Len())
136+
var c Car
137+
if err := c.Decode(m, buf, hdr.Version, hdr.BlockLength, true); err != nil {
138+
t.Logf("Failed to decode car", err)
139+
t.Fail()
140+
}
141+
// fmt.Println(c)
142+
return
143+
}

0 commit comments

Comments
 (0)