-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Go] Add tests with lower-case enums and bitsets.
- Loading branch information
1 parent
b5bb3c1
commit 660c96b
Showing
10 changed files
with
760 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package issue505 | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestConstant(t *testing.T) { | ||
message := new(SomeMessage) | ||
SomeMessageInit(message) | ||
|
||
if message.EngineType != EngineType.Gas { | ||
t.Log("message.EngineType != EngineType.Gas:\n", message.EngineType, EngineType.Gas) | ||
t.Fail() | ||
} | ||
|
||
m := NewSbeGoMarshaller() | ||
var buf = new(bytes.Buffer) | ||
var out = *new(SomeMessage) | ||
if err := out.Decode(m, buf, message.SbeSchemaVersion(), message.SbeBlockLength(), true); err != nil { | ||
t.Log("Decoding Error", err) | ||
t.Fail() | ||
} | ||
|
||
if out.EngineType != EngineType.Gas { | ||
t.Log("out.EngineType != EngineType.Gas:\n", out.EngineType, EngineType.Gas) | ||
t.Fail() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Generated SBE (Simple Binary Encoding) message codec | ||
|
||
package test973 | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
type EventType [8]bool | ||
type EventTypeChoiceValue uint8 | ||
type EventTypeChoiceValues struct { | ||
A EventTypeChoiceValue | ||
Bb EventTypeChoiceValue | ||
Ccc EventTypeChoiceValue | ||
D EventTypeChoiceValue | ||
EeEee EventTypeChoiceValue | ||
} | ||
|
||
var EventTypeChoice = EventTypeChoiceValues{0, 1, 2, 3, 4} | ||
|
||
func (e *EventType) Encode(_m *SbeGoMarshaller, _w io.Writer) error { | ||
var wireval uint8 = 0 | ||
for k, v := range e { | ||
if v { | ||
wireval |= (1 << uint(k)) | ||
} | ||
} | ||
return _m.WriteUint8(_w, wireval) | ||
} | ||
|
||
func (e *EventType) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16) error { | ||
var wireval uint8 | ||
|
||
if err := _m.ReadUint8(_r, &wireval); err != nil { | ||
return err | ||
} | ||
|
||
var idx uint | ||
for idx = 0; idx < 8; idx++ { | ||
e[idx] = (wireval & (1 << idx)) > 0 | ||
} | ||
return nil | ||
} | ||
|
||
func (EventType) EncodedLength() int64 { | ||
return 1 | ||
} | ||
|
||
func (*EventType) ASinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (e *EventType) AInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= e.ASinceVersion() | ||
} | ||
|
||
func (*EventType) ADeprecated() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*EventType) BbSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (e *EventType) BbInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= e.BbSinceVersion() | ||
} | ||
|
||
func (*EventType) BbDeprecated() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*EventType) CccSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (e *EventType) CccInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= e.CccSinceVersion() | ||
} | ||
|
||
func (*EventType) CccDeprecated() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*EventType) DSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (e *EventType) DInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= e.DSinceVersion() | ||
} | ||
|
||
func (*EventType) DDeprecated() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*EventType) EeEeeSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (e *EventType) EeEeeInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= e.EeEeeSinceVersion() | ||
} | ||
|
||
func (*EventType) EeEeeDeprecated() uint16 { | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// Generated SBE (Simple Binary Encoding) message codec | ||
|
||
package test973 | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"math" | ||
) | ||
|
||
type MessageHeader struct { | ||
BlockLength uint16 | ||
TemplateId uint16 | ||
SchemaId uint16 | ||
Version uint16 | ||
} | ||
|
||
func (m *MessageHeader) Encode(_m *SbeGoMarshaller, _w io.Writer) error { | ||
if err := _m.WriteUint16(_w, m.BlockLength); err != nil { | ||
return err | ||
} | ||
if err := _m.WriteUint16(_w, m.TemplateId); err != nil { | ||
return err | ||
} | ||
if err := _m.WriteUint16(_w, m.SchemaId); err != nil { | ||
return err | ||
} | ||
if err := _m.WriteUint16(_w, m.Version); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (m *MessageHeader) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16) error { | ||
if !m.BlockLengthInActingVersion(actingVersion) { | ||
m.BlockLength = m.BlockLengthNullValue() | ||
} else { | ||
if err := _m.ReadUint16(_r, &m.BlockLength); err != nil { | ||
return err | ||
} | ||
} | ||
if !m.TemplateIdInActingVersion(actingVersion) { | ||
m.TemplateId = m.TemplateIdNullValue() | ||
} else { | ||
if err := _m.ReadUint16(_r, &m.TemplateId); err != nil { | ||
return err | ||
} | ||
} | ||
if !m.SchemaIdInActingVersion(actingVersion) { | ||
m.SchemaId = m.SchemaIdNullValue() | ||
} else { | ||
if err := _m.ReadUint16(_r, &m.SchemaId); err != nil { | ||
return err | ||
} | ||
} | ||
if !m.VersionInActingVersion(actingVersion) { | ||
m.Version = m.VersionNullValue() | ||
} else { | ||
if err := _m.ReadUint16(_r, &m.Version); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (m *MessageHeader) RangeCheck(actingVersion uint16, schemaVersion uint16) error { | ||
if m.BlockLengthInActingVersion(actingVersion) { | ||
if m.BlockLength < m.BlockLengthMinValue() || m.BlockLength > m.BlockLengthMaxValue() { | ||
return fmt.Errorf("Range check failed on m.BlockLength (%v < %v > %v)", m.BlockLengthMinValue(), m.BlockLength, m.BlockLengthMaxValue()) | ||
} | ||
} | ||
if m.TemplateIdInActingVersion(actingVersion) { | ||
if m.TemplateId < m.TemplateIdMinValue() || m.TemplateId > m.TemplateIdMaxValue() { | ||
return fmt.Errorf("Range check failed on m.TemplateId (%v < %v > %v)", m.TemplateIdMinValue(), m.TemplateId, m.TemplateIdMaxValue()) | ||
} | ||
} | ||
if m.SchemaIdInActingVersion(actingVersion) { | ||
if m.SchemaId < m.SchemaIdMinValue() || m.SchemaId > m.SchemaIdMaxValue() { | ||
return fmt.Errorf("Range check failed on m.SchemaId (%v < %v > %v)", m.SchemaIdMinValue(), m.SchemaId, m.SchemaIdMaxValue()) | ||
} | ||
} | ||
if m.VersionInActingVersion(actingVersion) { | ||
if m.Version < m.VersionMinValue() || m.Version > m.VersionMaxValue() { | ||
return fmt.Errorf("Range check failed on m.Version (%v < %v > %v)", m.VersionMinValue(), m.Version, m.VersionMaxValue()) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func MessageHeaderInit(m *MessageHeader) { | ||
return | ||
} | ||
|
||
func (*MessageHeader) EncodedLength() int64 { | ||
return 8 | ||
} | ||
|
||
func (*MessageHeader) BlockLengthMinValue() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*MessageHeader) BlockLengthMaxValue() uint16 { | ||
return math.MaxUint16 - 1 | ||
} | ||
|
||
func (*MessageHeader) BlockLengthNullValue() uint16 { | ||
return math.MaxUint16 | ||
} | ||
|
||
func (*MessageHeader) BlockLengthSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (m *MessageHeader) BlockLengthInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= m.BlockLengthSinceVersion() | ||
} | ||
|
||
func (*MessageHeader) BlockLengthDeprecated() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*MessageHeader) TemplateIdMinValue() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*MessageHeader) TemplateIdMaxValue() uint16 { | ||
return math.MaxUint16 - 1 | ||
} | ||
|
||
func (*MessageHeader) TemplateIdNullValue() uint16 { | ||
return math.MaxUint16 | ||
} | ||
|
||
func (*MessageHeader) TemplateIdSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (m *MessageHeader) TemplateIdInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= m.TemplateIdSinceVersion() | ||
} | ||
|
||
func (*MessageHeader) TemplateIdDeprecated() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*MessageHeader) SchemaIdMinValue() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*MessageHeader) SchemaIdMaxValue() uint16 { | ||
return math.MaxUint16 - 1 | ||
} | ||
|
||
func (*MessageHeader) SchemaIdNullValue() uint16 { | ||
return math.MaxUint16 | ||
} | ||
|
||
func (*MessageHeader) SchemaIdSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (m *MessageHeader) SchemaIdInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= m.SchemaIdSinceVersion() | ||
} | ||
|
||
func (*MessageHeader) SchemaIdDeprecated() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*MessageHeader) VersionMinValue() uint16 { | ||
return 0 | ||
} | ||
|
||
func (*MessageHeader) VersionMaxValue() uint16 { | ||
return math.MaxUint16 - 1 | ||
} | ||
|
||
func (*MessageHeader) VersionNullValue() uint16 { | ||
return math.MaxUint16 | ||
} | ||
|
||
func (*MessageHeader) VersionSinceVersion() uint16 { | ||
return 0 | ||
} | ||
|
||
func (m *MessageHeader) VersionInActingVersion(actingVersion uint16) bool { | ||
return actingVersion >= m.VersionSinceVersion() | ||
} | ||
|
||
func (*MessageHeader) VersionDeprecated() uint16 { | ||
return 0 | ||
} |
Oops, something went wrong.