-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add new arguments for generated MessageDecoder#header method When decoding multiple messages from a single byte buffer, the second and following message decoder should offset to the new header offset plus header length. * Update code to reflect method signature change in decoder's header method * Add test for introduced changes --------- Co-authored-by: Elvis Wang <[email protected]>
- Loading branch information
Showing
16 changed files
with
112 additions
and
14 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
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
Binary file not shown.
Binary file not shown.
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
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
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,71 @@ | ||
use issue_987::{ | ||
issue_987_codec::{Issue987Decoder, Issue987Encoder, SBE_BLOCK_LENGTH, SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_TEMPLATE_ID}, message_header_codec::MessageHeaderDecoder, * | ||
}; | ||
|
||
fn create_encoder(buffer: &mut Vec<u8>, off: usize) -> Issue987Encoder { | ||
let encoder = Issue987Encoder::default().wrap( | ||
WriteBuf::new(buffer.as_mut_slice()), | ||
off + message_header_codec::ENCODED_LENGTH, | ||
); | ||
let mut header = encoder.header(off); | ||
header.parent().unwrap() | ||
} | ||
|
||
#[test] | ||
fn encode_2_messages_and_then_decode() -> SbeResult<()> { | ||
let mut buffer = vec![0u8; 256]; | ||
|
||
let mut off = 0; | ||
|
||
// encode message 1 | ||
let mut encoder = create_encoder(&mut buffer, off); | ||
encoder.old_field(10); | ||
let mut other_encoder = encoder.new_field_encoder(); | ||
other_encoder.f1(11); | ||
other_encoder.f2(12); | ||
let encoder = other_encoder.parent().unwrap(); | ||
|
||
// Update offset | ||
off += message_header_codec::ENCODED_LENGTH + encoder.encoded_length(); | ||
|
||
// encode message 2 | ||
let mut encoder = create_encoder(&mut buffer, off); | ||
encoder.old_field(20); | ||
let mut other_encoder = encoder.new_field_encoder(); | ||
other_encoder.f1(21); | ||
other_encoder.f2(22); | ||
|
||
// decoding ... | ||
off = 0; | ||
|
||
// decode message 1 | ||
let buf = ReadBuf::new(buffer.as_slice()); | ||
let header = MessageHeaderDecoder::default().wrap(buf, off); | ||
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 = Issue987Decoder::default().header(header, off); | ||
assert_eq!(10, decoder.old_field()); | ||
let other_decoder = decoder.new_field_decoder(); | ||
assert_eq!(11, other_decoder.f1()); | ||
assert_eq!(12, other_decoder.f2()); | ||
|
||
// Update offset | ||
off += message_header_codec::ENCODED_LENGTH + decoder.encoded_length(); | ||
|
||
// decode message 2 | ||
let buf = ReadBuf::new(buffer.as_slice()); | ||
let header = MessageHeaderDecoder::default().wrap(buf, off); | ||
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 = Issue987Decoder::default().header(header, off); | ||
assert_eq!(20, decoder.old_field()); | ||
let other_decoder = decoder.new_field_decoder(); | ||
assert_eq!(21, other_decoder.f1()); | ||
assert_eq!(22, other_decoder.f2()); | ||
|
||
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="issue987" | ||
id="987" | ||
version="1" | ||
semanticVersion="1.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"> | ||
<type name="f1" primitiveType="uint16" semanticType="Int"/> | ||
<type name="f2" primitiveType="uint32" semanticType="Int" offset="4"/> | ||
</composite> | ||
</types> | ||
<sbe:message name="issue987" id="1"> | ||
<field name="oldField" id="1" type="uint16" semanticType="Int"/> | ||
<field name="newField" id="2" type="NewComposite" /> | ||
</sbe:message> | ||
</sbe:messageSchema> |