Skip to content

Commit b910940

Browse files
authored
feat: expose Buffer type needed for codegen (#184)
* Expose Buffer needed for generated FIX definitions * Remove remaining traces of fefix references in code
1 parent 89af718 commit b910940

11 files changed

Lines changed: 32 additions & 26 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hotfix-codegen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ indoc = "2"
2323

2424
[dev-dependencies]
2525
hotfix-dictionary = { version = "0.0.26", path = "../hotfix-dictionary", features = ["fix40", "fix41", "fix42", "fix43", "fix50"] }
26-
syn = { version = "2", features = ["parsing"] }
26+
syn = { version = "2", features = ["full", "parsing"] }

crates/hotfix-codegen/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use hotfix_dictionary::{self as dict, TagU32};
44
use indoc::indoc;
55
use std::marker::PhantomData;
66

7-
const FEFIX_VERSION: &str = env!("CARGO_PKG_VERSION");
7+
const HOTFIX_VERSION: &str = env!("CARGO_PKG_VERSION");
88

99
/// Creates a [`String`] that contains a multiline Rust "Doc" comment explaining
1010
/// that all subsequent code was automatically generated.
@@ -14,21 +14,21 @@ const FEFIX_VERSION: &str = env!("CARGO_PKG_VERSION");
1414
/// leading whitespace.
1515
///
1616
/// ```text
17-
/// // Generated automatically by FerrumFIX. Do not modify manually.
17+
/// // Generated automatically by HotFIX. Do not modify manually.
1818
/// ```
1919
pub fn generated_code_notice() -> String {
2020
use chrono::prelude::*;
2121

2222
format!(
2323
indoc!(
2424
r#"
25-
// Generated automatically by FerrumFIX {} on {}.
25+
// Generated automatically by HotFIX {} on {}.
2626
//
2727
// DO NOT MODIFY MANUALLY.
2828
// DO NOT COMMIT TO VERSION CONTROL.
2929
// ALL CHANGES WILL BE OVERWRITTEN."#
3030
),
31-
FEFIX_VERSION,
31+
HOTFIX_VERSION,
3232
Utc::now().to_rfc2822(),
3333
)
3434
}
@@ -102,8 +102,8 @@ pub struct Settings {
102102
pub indentation: String,
103103
/// The indentation level of all generated Rust code. Zero by default.
104104
pub indentation_depth: u32,
105-
/// The name of the `fefix` crate for imports. `fefix` by default.
106-
pub fefix_crate_name: String,
105+
/// The name of the `hotfix` crate for imports. `hotfix` by default.
106+
pub hotfix_crate_name: String,
107107
/// A list of derive macros on top of all generated FIX datatype `enum`s. E.g.:
108108
///
109109
/// ```
@@ -147,7 +147,7 @@ impl Default for Settings {
147147
"FieldType".to_string(),
148148
],
149149
attributes_for_allowed_values: vec![],
150-
fefix_crate_name: "hotfix".to_string(),
150+
hotfix_crate_name: "hotfix".to_string(),
151151
phantom: PhantomData,
152152
}
153153
}
@@ -214,9 +214,9 @@ pub fn gen_definitions(fix_dictionary: &dict::Dictionary, settings: &Settings) -
214214
215215
// {top_comment}
216216
217-
use {fefix_path}::dict::FieldLocation;
218-
use {fefix_path}::dict::FixDatatype;
219-
use {fefix_path}::{{FieldType, HardCodedFixFieldDefinition}};
217+
use {hotfix_path}::dict::FieldLocation;
218+
use {hotfix_path}::dict::FixDatatype;
219+
use {hotfix_path}::{{FieldType, HardCodedFixFieldDefinition}};
220220
221221
{enum_definitions}
222222
@@ -226,7 +226,7 @@ pub fn gen_definitions(fix_dictionary: &dict::Dictionary, settings: &Settings) -
226226
top_comment = top_comment,
227227
enum_definitions = enums,
228228
field_defs = field_defs,
229-
fefix_path = settings.fefix_crate_name,
229+
hotfix_path = settings.hotfix_crate_name,
230230
);
231231
code
232232
}

crates/hotfix-derive/src/derive_fix_value.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ pub fn derive_fix_value(input: TokenStream) -> TokenStream {
3636
})
3737
.take_enum()
3838
.expect("Invalid enum");
39-
let fefix_crate_info =
39+
let hotfix_crate_info =
4040
proc_macro_crate::crate_name("hotfix-message").expect("Cargo.toml hotfix issues");
41-
let fefix_crate_name = match fefix_crate_info {
41+
let hotfix_crate_name = match hotfix_crate_info {
4242
proc_macro_crate::FoundCrate::Itself => Ident::new("crate", Span::call_site()),
4343
proc_macro_crate::FoundCrate::Name(s) => Ident::new(s.as_str(), Span::call_site()),
4444
};
@@ -49,7 +49,7 @@ pub fn derive_fix_value(input: TokenStream) -> TokenStream {
4949

5050
fn serialize_with<B>(&self, buffer: &mut B, _settings: Self::SerializeSettings) -> usize
5151
where
52-
B: #fefix_crate_name::Buffer,
52+
B: #hotfix_crate_name::Buffer,
5353
{
5454
match self {
5555
#(#matching_cases)*
@@ -70,13 +70,13 @@ pub fn derive_fix_value(input: TokenStream) -> TokenStream {
7070
#[derive(Debug, Clone, FromVariant)]
7171
#[darling(attributes(hotfix))]
7272
struct EnumVariantInfo {
73-
ident: syn::Ident,
73+
ident: Ident,
7474
variant: String,
7575
}
7676

7777
#[derive(Debug, Clone, FromDeriveInput)]
7878
#[darling(attributes(hotfix))]
7979
struct DataFieldWithVariants {
80-
ident: syn::Ident,
80+
ident: Ident,
8181
data: darling::ast::Data<EnumVariantInfo, darling::util::Ignored>,
8282
}

crates/hotfix-derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Derive macros for FerrumFIX.
1+
//! Derive macros for HotFIX.
22
33
#![deny(missing_debug_implementations, clippy::useless_conversion)]
44

crates/hotfix-message/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "hotfix-message"
33
description = "FIX messages for HotFIX."
4-
version.workspace = true
4+
version = "0.1.0"
55
authors.workspace = true
66
edition.workspace = true
77
license.workspace = true

crates/hotfix-message/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn codegen(fix_dictionary: Dictionary, filename: &str) -> io::Result<()> {
2323
// writing.
2424
let dir = PathBuf::from(var("OUT_DIR").unwrap());
2525
let codegen_settings = &mut codegen::Settings::default();
26-
codegen_settings.fefix_crate_name = "crate".to_string();
26+
codegen_settings.hotfix_crate_name = "crate".to_string();
2727
let code = codegen::gen_definitions(&fix_dictionary, codegen_settings);
2828
let path = dir.join(filename);
2929
let file = &mut File::create(path)?;

crates/hotfix-message/src/encoding/buffer.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/// Operations on a growable in-memory buffer.
22
///
3-
/// This trait is intented to be used as a thin compatibility layer between
3+
/// This trait is intended to be used as a thin compatibility layer between
44
/// [`Vec<u8>`] and
55
/// [`bytes::BytesMut`](https://docs.rs/bytes/1.1.0/bytes/struct.BytesMut.html).
6-
/// By writing generic code that operates on [`Buffer`], FerrumFIX users can
6+
/// By writing generic code that operates on [`Buffer`], HotFIX users can
77
/// decide for themselves if they want to use `bytes` and still use most of the
88
/// features.
99
///
@@ -23,6 +23,12 @@ pub trait Buffer {
2323
self.as_slice().len()
2424
}
2525

26+
/// Returns `true` if the buffer is empty.
27+
#[inline]
28+
fn is_empty(&self) -> bool {
29+
self.len() == 0
30+
}
31+
2632
/// Returns the number of bytes that `self` can hold without reallocating.
2733
fn capacity(&self) -> usize;
2834

crates/hotfix-message/src/encoding/definitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! # What is this and why is this necessary?
44
//!
5-
//! FerrumFIX internals rely on [`Dictionary`](crate::Dictionary) for accessing
5+
//! HotFIX internals rely on [`Dictionary`](crate::Dictionary) for accessing
66
//! details about fields, messages and other abstract entities defined in the
77
//! FIX Dictionary specifications. Although this approach works quite well, it
88
//! can become daunting to query a [`Dictionary`](crate::Dictionary) for even

crates/hotfix-message/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod parser;
88
pub(crate) mod parts;
99
mod tags;
1010

11-
use encoding::Buffer;
11+
pub use encoding::Buffer;
1212
pub use encoding::HardCodedFixFieldDefinition;
1313
pub use encoding::field_access::FieldType;
1414
pub use encoding::field_types;

0 commit comments

Comments
 (0)