arthurlm / quickfix-rs

Unofficial rust binding of QuickFIX library
https://docs.rs/quickfix/latest/quickfix/
Other
13 stars 5 forks source link

Iterate a repeating group #18

Closed s6577t closed 1 week ago

s6577t commented 2 weeks ago

If I want to iterate the entries in a repeating group, such as market data entries, currently the number of entries needs to be explicitly extracted:

                let msg: &Message = // ... assigned somehwere
                 ...
                let no: usize = msg
                    .get_field(field_id::NO_MD_ENTRIES)
                    .unwrap()
                    .parse()
                    .unwrap();

                for i in 1..=no {
                    let g = md_sfr.clone_group_no_md_entries(i).unwrap();
                    let r#type = g.get_md_entry_type();
                    let px = g.get_md_entry_px();
                    let sz = g.get_md_entry_size().to_string();
                    ...
                }

This is not at all unreasonable since it looks like the expected API from quickfix c++ but an iterator would be nice. Maybe a good way to implement this would in quickfix-msg-gen?

arthurlm commented 2 weeks ago

Hi

I just pushed few commits. This should resolve the issue:

  1. I added helper to get group item len: https://github.com/arthurlm/quickfix-rs/commit/111c9be34aeec3aa60637fb65486a149cf93f29c + https://github.com/arthurlm/quickfix-rs/commit/41d600b48f6976da4c0a6f8909df32011ed52e62 This should simplify accessing how many groups there is in the message.
  2. Then I added iterator over group (as requested): https://github.com/arthurlm/quickfix-rs/commit/29ed45045f4f3cd83da698cf90de546cf062495b

Can you give it a try before I release a new version 🙏 ? Also can you please give me a feedback on this 😁 ?

If everything works for you as expected, I can then make a new release and close this issue.

s6577t commented 1 week ago

This works perfectly when using the count and iterator 🙌🏻