Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:04:59+00:00 2026-06-01T20:04:59+00:00

What I try to do is to make a class based on templates, which

  • 0

What I try to do is to make a class based on templates, which will act as a python-bitstring or Python Hachoir. And the final goal is to describe some rules or patterns to parse a given binary files (101 hex editor has similar cool feature – Binary Templates).

Here is a simple example of how I see the realization:

typedef struct _BINARYFILEFORMAT
{
  short sMagic;
  int sField_1, sField_2;
  short sFrameLength;
  int OverallLength;
}
  BinaryFileFormat;

void main(int argc, char** argv)
{
  // Storage for parsed file
  BinaryFileFormat bff;

  // Describing new pattern to parse a binary file with statistical information
  Rule r = "<Magic>:2,
            <Field_1>:4,
            <Field_2>:4,
            <FrameLength>:2,
            <OverallLength>:4";

  // Parse the file and place all data into the structure
  BinaryParser bp(r, "<path_to_file>", bff);

  // Now we can work with BinaryFileFormat structure
  // ...
}

So, the question #1 is: how can I do such thing in c++? Is it possible at all? Simple clue or hint will be enough to move in right direction for me.

The question #2 is: is it possible to dynamically create a corresponding structure (in example it’s BINARYFILEFORMAT) to store all binary data?

P.S. I know, deserialization do the similar things, but not in my case – at final result I want to avoid of using any structures (of course, if it would be possible).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:05:00+00:00Added an answer on June 1, 2026 at 8:05 pm

    This sort of thing is usually done as a precompile step. A grammar definition is read by some tool. and this tool outputs C++ code that has data structures to hold the model as well as the code necessary to serialize and deserialize it to a file.

    However you can look at boost::spirit and friends as a way to do this in C++ at (normal) compile-time.

    If you want to do it yourself you can do something like…

    Rule r = Rule("Magic", &BinaryFileFormat::sMagic, 2) +
             Rule("Field1", &BinaryFileFormat::sField_1, 4) +
             Rule("Field2", &BinaryFileFormat::sField_2, 4) +
             ...;
    

    …and use type deduction to determine correct primitive encoding/decoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to make an Android application which communicates with a non-standard ISO15693 (NFC-V)
I try to make a displaying list with onmouseover() with some links but they
I will try to make this as clear as I can, but if you
I want to make a static class that would load some settings from XML
Consider a class that is supposed to make parameter suggestion, given some clues, and
I try to make a view that will display a treeview on one side
I am making a UIView-based class for use as a tableHeaderView. It will have
I try to make a registration form. When user post the fields, i check
I try to make an animation with an image in my view but it
I try to make Ext.Data.Store working... With a normal proxy it works great: var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.