Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while decoding #130

Closed
rkyrahulyadav opened this issue May 13, 2024 · 3 comments
Closed

Issue while decoding #130

rkyrahulyadav opened this issue May 13, 2024 · 3 comments

Comments

@rkyrahulyadav
Copy link

Hi,
i am getting a data-buff from a function that is FAST encoded and using mFAST for decoding the mssg.

`void BroadcastManagerFO::readBroadcast(unsigned char *databuf, int nbytes) {
// Read XML template from file

const mfast::templates_description* descriptions[] = {
MDIFastTemplates::description() // generated from fast_type_gen
};

mfast::fast_decoder decoder;

// In current implementation, decoder.include() can only be called
// exactly once per decoder/encoder
decoder.include(descriptions);

const char* first = reinterpret_cast<const char*>(databuf);
const char* last = reinterpret_cast<const char*>(databuf + nbytes);
std::cout<<"NBYTES:"<<nbytes<<std::endl;

mfast::message_cref msg = decoder.decode(first, last);
// Caveat 1: the variable *first* would be updated to the start of next unread position after decode().
// Caveat 2: msg is only valid before next decoder.decode() is called or decoder object is destroyed.
 std::cout<<"MSGID: "<<msg.id()<<" "<<msg.name()<<std::endl;
 

if (msg.id() == MDIFastTemplates::MDPacketHeader::the_id)
{   
     MDIFastTemplates::MDPacketHeader_cref ref = static_cast<MDIFastTemplates::MDPacketHeader_cref>(msg);
    
     uint32_t sequenceNumber;
     memcpy(&sequenceNumber , ref.get_PacketSeqNum().data() , 4);
     std::cout << ref.get_SenderCompID().name()<<" "<< ref.get_SenderCompID().value()<<" "<<ref.get_SenderCompID().id()<<std::endl;
     std::cout << ref.get_PacketSeqNum().name()<<" "<<sequenceNumber<<" "<<std::endl;
     first = first + 17;
    message_printer printer(std::cout);
    printer.visit(ref, 0);
}



 if(msg.id() == MDIFastTemplates::DepthSnapshot::the_id){
      MDIFastTemplates::DepthSnapshot_cref ref = static_cast<MDIFastTemplates::DepthSnapshot_cref>(msg);
      std::cout<<ref.get_MsgType().name()<<" "<<ref.get_MsgType().value()<<" "<<ref.get_MsgType().id()<<std::endl;
}

std::cout<<"--------------------DONE-----------------------"<<std::endl;

}`

Here databuff containing...Header + some other template
but why i am not able to get other template id apart from header?
is anything i am doing wrong

@ksergey
Copy link
Contributor

ksergey commented May 13, 2024

@rkyrahulyadav

If I understand right your databuf points to buffer which contains few FAST messages. In this case you can write something like:

while (first != last) { 
  auto msg = decoder.decode(first, last);
  
  // process msg...
}

@rkyrahulyadav
Copy link
Author

@ksergey i did that thing earlier. but still it printing only template id of header.
it should decode a header then some other template id.

@rkyrahulyadav
Copy link
Author

Do anyone use mFast in production for FAST decoding to data of exchanges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants