Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/benches/car_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn encode(state: &mut State) -> SbeResult<usize> {
let mut acceleration = AccelerationEncoder::default();
let mut extras = OptionalExtras::default();

car = car.wrap(WriteBuf::new(buffer), message_header::ENCODED_LENGTH);
car = car.wrap(WriteBuf::new(buffer), message_header_codec::ENCODED_LENGTH);
car = car.header(0).parent()?;

car.code(Model::A);
Expand Down
2 changes: 1 addition & 1 deletion rust/benches/md_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn encode_md(state: &mut State) -> SbeResult<usize> {
let mut market_data = MarketDataIncrementalRefreshTradesEncoder::default();
let mut md_inc_grp = MdIncGrpEncoder::default();

market_data = market_data.wrap(WriteBuf::new(buffer), message_header::ENCODED_LENGTH);
market_data = market_data.wrap(WriteBuf::new(buffer), message_header_codec::ENCODED_LENGTH);
market_data = market_data.header(0).parent()?;

market_data.transact_time(1234);
Expand Down
4 changes: 2 additions & 2 deletions rust/tests/baseline_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn decode_car_and_assert_expected_content(buffer: &[u8]) -> SbeResult<()> {

let buf = ReadBuf::new(buffer);
let header = MessageHeaderDecoder::default().wrap(buf, 0);
assert_eq!(car::SBE_TEMPLATE_ID, header.template_id());
assert_eq!(car_codec::SBE_TEMPLATE_ID, header.template_id());
car = car.header(header);

// Car...
Expand Down Expand Up @@ -167,7 +167,7 @@ fn encode_car_from_scratch() -> SbeResult<(usize, Vec<u8>)> {

car = car.wrap(
WriteBuf::new(buffer.as_mut_slice()),
message_header::ENCODED_LENGTH,
message_header_codec::ENCODED_LENGTH,
);
car = car.header(0).parent()?;

Expand Down
4 changes: 2 additions & 2 deletions rust/tests/big_endian_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn decode_car_and_assert_expected_content(buffer: &[u8]) -> SbeResult<()> {

let buf = ReadBuf::new(buffer);
let header = MessageHeaderDecoder::default().wrap(buf, 0);
assert_eq!(car::SBE_TEMPLATE_ID, header.template_id());
assert_eq!(car_codec::SBE_TEMPLATE_ID, header.template_id());
car = car.header(header);

// Car...
Expand Down Expand Up @@ -161,7 +161,7 @@ fn encode_car_from_scratch() -> SbeResult<(usize, Vec<u8>)> {

car = car.wrap(
WriteBuf::new(buffer.as_mut_slice()),
message_header::ENCODED_LENGTH,
message_header_codec::ENCODED_LENGTH,
);
car = car.header(0).parent()?;

Expand Down
4 changes: 2 additions & 2 deletions rust/tests/extension_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn decode_car_and_assert_expected_content(buffer: &[u8]) -> SbeResult<()> {

let buf = ReadBuf::new(buffer);
let header = MessageHeaderDecoder::default().wrap(buf, 0);
assert_eq!(car::SBE_TEMPLATE_ID, header.template_id());
assert_eq!(car_codec::SBE_TEMPLATE_ID, header.template_id());
car = car.header(header);

// Car...
Expand Down Expand Up @@ -168,7 +168,7 @@ fn encode_car_from_scratch() -> SbeResult<(usize, Vec<u8>)> {

car = car.wrap(
WriteBuf::new(buffer.as_mut_slice()),
message_header::ENCODED_LENGTH,
message_header_codec::ENCODED_LENGTH,
);
car = car.header(0).parent()?;

Expand Down
16 changes: 8 additions & 8 deletions rust/tests/issue_435_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ::issue_435::*;
fn create_encoder(buffer: &mut Vec<u8>) -> Issue435Encoder {
let issue_435 = Issue435Encoder::default().wrap(
WriteBuf::new(buffer.as_mut_slice()),
message_header::ENCODED_LENGTH,
message_header_codec::ENCODED_LENGTH,
);
let mut header = issue_435.header(0);
header.s(*SetRef::default().set_one(true));
Expand All @@ -12,9 +12,9 @@ fn create_encoder(buffer: &mut Vec<u8>) -> Issue435Encoder {

#[test]
fn issue_435_ref_test() -> SbeResult<()> {
assert_eq!(9, message_header::ENCODED_LENGTH);
assert_eq!(1, issue_435::SBE_BLOCK_LENGTH);
assert_eq!(0, issue_435::SBE_SCHEMA_VERSION);
assert_eq!(9, message_header_codec::ENCODED_LENGTH);
assert_eq!(1, issue_435_codec::SBE_BLOCK_LENGTH);
assert_eq!(0, issue_435_codec::SBE_SCHEMA_VERSION);

// encode...
let mut buffer = vec![0u8; 256];
Expand All @@ -24,10 +24,10 @@ fn issue_435_ref_test() -> SbeResult<()> {
// decode...
let buf = ReadBuf::new(buffer.as_slice());
let header = MessageHeaderDecoder::default().wrap(buf, 0);
assert_eq!(issue_435::SBE_BLOCK_LENGTH, header.block_length());
assert_eq!(issue_435::SBE_SCHEMA_VERSION, header.version());
assert_eq!(issue_435::SBE_TEMPLATE_ID, header.template_id());
assert_eq!(issue_435::SBE_SCHEMA_ID, header.schema_id());
assert_eq!(issue_435_codec::SBE_BLOCK_LENGTH, header.block_length());
assert_eq!(issue_435_codec::SBE_SCHEMA_VERSION, header.version());
assert_eq!(issue_435_codec::SBE_TEMPLATE_ID, header.template_id());
assert_eq!(issue_435_codec::SBE_SCHEMA_ID, header.schema_id());
assert_eq!(*SetRef::default().set_one(true), header.s());

let decoder = Issue435Decoder::default().header(header);
Expand Down
2 changes: 1 addition & 1 deletion sbe-tool/src/main/java/uk/co/real_logic/sbe/SbeTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public class SbeTool
* Specifies token that should be appended to keywords to avoid compilation errors.
* <p>
* If none is supplied then use of keywords results in an error during schema parsing. The
* underscore character is a good example fo a token to use.
* underscore character is a good example of a token to use.
*/
public static final String KEYWORD_APPEND_TOKEN = "sbe.keyword.append.token";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
*/
package uk.co.real_logic.sbe.generation.rust;

import org.agrona.generation.OutputManager;
import uk.co.real_logic.sbe.generation.rust.RustGenerator.CodecType;

import java.io.IOException;
import java.io.Writer;
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;

import static java.nio.ByteOrder.LITTLE_ENDIAN;
import static uk.co.real_logic.sbe.generation.rust.RustGenerator.*;
Expand All @@ -36,11 +31,7 @@
*/
class LibRsDef
{
private final LinkedHashMap<String, HashSet<CodecType>> modules = new LinkedHashMap<>();
private final ArrayList<String> enumDefs = new ArrayList<>();
private final ArrayList<String> bitSetDefs = new ArrayList<>();

private final OutputManager outputManager;
private final RustOutputManager outputManager;
private final ByteOrder byteOrder;

/**
Expand All @@ -50,60 +41,42 @@ class LibRsDef
* @param byteOrder for the Encoding.
*/
LibRsDef(
final OutputManager outputManager,
final RustOutputManager outputManager,
final ByteOrder byteOrder)
{
this.outputManager = outputManager;
this.byteOrder = byteOrder;
}

void addMod(final String modName, final CodecType codecType)
{
modules.computeIfAbsent(modName, __ -> new HashSet<>()).add(codecType);
}

void addEnum(final String enumDef)
{
enumDefs.add(enumDef);
}

void addBitSet(final String bitSetDef)
{
bitSetDefs.add(bitSetDef);
}

void generate() throws IOException
{
try (Writer libRs = outputManager.createOutput("lib"))
{
indent(libRs, 0, "#![forbid(unsafe_code)]\n");
indent(libRs, 0, "#![allow(clippy::upper_case_acronyms)]\n");
indent(libRs, 0, "#![allow(non_camel_case_types)]\n");
indent(libRs, 0, "use core::{convert::TryInto};\n\n");
indent(libRs, 0, "use ::core::{convert::TryInto};\n\n");

final ArrayList<String> modules = new ArrayList<>();
Files.walk(outputManager.getSrcDirPath())
.filter(Files::isRegularFile)
.map(path -> path.getFileName().toString())
.filter(fileName -> fileName.endsWith(".rs"))
.filter(fileName -> !fileName.equals("lib.rs"))
.map(fileName -> fileName.substring(0, fileName.length() - 3))
.forEach(modules::add);

// add modules
for (final String mod : modules.keySet())
for (final String mod : modules)
{
indent(libRs, 0, "pub mod %s;\n", toLowerSnakeCase(mod));
}
indent(libRs, 0, "\n");

// add re-export of modules
for (final Map.Entry<String, HashSet<CodecType>> entry : modules.entrySet())
for (final String module : modules)
{
final String mod = entry.getKey();
final HashSet<CodecType> codecTypes = entry.getValue();

if (codecTypes.size() == 1)
{
indent(libRs, 0, "pub use %s::%s::*;\n",
toLowerSnakeCase(mod),
toLowerSnakeCase(codecTypes.toArray()[0].toString()));
}
else
{
indent(libRs, 0, "pub use %s::{decoder::*, encoder::*};\n", toLowerSnakeCase(mod));
}
indent(libRs, 0, "pub use %s::*;\n", toLowerSnakeCase(module));
}
indent(libRs, 0, "\n");

Expand All @@ -115,20 +88,6 @@ void generate() throws IOException

generateReadBuf(libRs, byteOrder);
generateWriteBuf(libRs, byteOrder);

// append generated enums
for (final String code : enumDefs)
{
libRs.append(code);
indent(libRs, 0, "\n");
}

// append generated bitSets
for (final String code : bitSetDefs)
{
libRs.append(code);
indent(libRs, 0, "\n");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void appendMessageHeaderDecoderFn(final Appendable out) throws IOException
indent(out, 3, "let acting_version = header.version();\n\n");
indent(out, 3, "self.wrap(\n");
indent(out, 4, "header.parent().unwrap(),\n");
indent(out, 4, "message_header::ENCODED_LENGTH,\n");
indent(out, 4, "message_header_codec::ENCODED_LENGTH,\n");
indent(out, 4, "acting_block_length,\n");
indent(out, 4, "acting_version,\n");
indent(out, 3, ")\n");
Expand Down
Loading