-
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.
[Rust] Updated RustGenerator.generatePrimitiveOptionalDecoder() to re…
…solve Issue #972 (#981) Co-authored-by: Michael Ward <[email protected]>
- Loading branch information
Showing
5 changed files
with
64 additions
and
8 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,37 @@ | ||
use issue_972::*; | ||
|
||
fn create_encoder(buffer: &mut Vec<u8>) -> Issue972Encoder { | ||
let issue_972 = Issue972Encoder::default().wrap( | ||
WriteBuf::new(buffer.as_mut_slice()), | ||
message_header_codec::ENCODED_LENGTH, | ||
); | ||
let mut header = issue_972.header(0); | ||
header.parent().unwrap() | ||
} | ||
|
||
#[test] | ||
fn round_trip() -> SbeResult<()> { | ||
// encode... | ||
let mut buffer = vec![0u8; 256]; | ||
let encoder = create_encoder(&mut buffer); | ||
let mut new_composite_encoder = encoder.new_field_encoder(); | ||
new_composite_encoder.f1(2007); | ||
new_composite_encoder.f2(2012); | ||
|
||
// decode... | ||
let buf = ReadBuf::new(buffer.as_slice()); | ||
let header = MessageHeaderDecoder::default().wrap(buf, 0); | ||
assert_eq!(SBE_BLOCK_LENGTH, header.block_length()); | ||
assert_eq!(SBE_SCHEMA_VERSION, header.version()); | ||
assert_eq!(SBE_TEMPLATE_ID, header.template_id()); | ||
assert_eq!(SBE_SCHEMA_ID, header.schema_id()); | ||
|
||
let decoder = Issue972Decoder::default().header(header); | ||
if let Either::Right(composite) = decoder.new_field_decoder() { | ||
assert_eq!(2007, composite.f1().unwrap()); | ||
assert_eq!(2012, composite.f2().unwrap()); | ||
} else { | ||
panic!() | ||
} | ||
Ok(()) | ||
} |
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,25 @@ | ||
<sbe:messageSchema | ||
xmlns:sbe="http://fixprotocol.io/2016/sbe" | ||
package="issue972" | ||
id="972" | ||
version="2" | ||
semanticVersion="5.0.0" | ||
byteOrder="littleEndian"> | ||
<types> | ||
<composite name="messageHeader"> | ||
<type name="blockLength" primitiveType="uint16" description="Length of the root of the FIX message contained before repeating groups or variable/conditions fields."/> | ||
<type name="templateId" primitiveType="uint16" description="Template ID used to encode the message."/> | ||
<type name="schemaId" primitiveType="uint16" description="ID of the system publishing the message."/> | ||
<type name="version" primitiveType="uint16" description="Schema version."/> | ||
</composite> | ||
|
||
<composite name="NewComposite" sinceVersion="1"> | ||
<type name="f1" primitiveType="uint16" presence="optional" nullValue="0" semanticType="Int"/> | ||
<type name="f2" primitiveType="uint32" presence="optional" nullValue="0" semanticType="Int" offset="4"/> | ||
</composite> | ||
</types> | ||
<sbe:message name="issue972" id="1"> | ||
<field name="oldField" id="1" type="uint16" semanticType="Int"/> | ||
<field name="newField" id="2" type="NewComposite" presence="optional" sinceVersion="1" /> | ||
</sbe:message> | ||
</sbe:messageSchema> |