zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Emit Source Positions for Compounds

Open johannes-wolf opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. For mapping back to blob-positions, we need an option to get the blob-position an object (compound/struct) was read from. This is specifically needed for compound types only.

Describe the solution you'd like The idea is to add a new zserio C++ generator option (e.g. -withSourcePosition) that returns an object's blob-position in bits.

Describe alternatives you've considered Calculating the offsets by summing the results of getBitSize() is not feasible due to potential complexities involved.

Additional context A working implementation can be found in PR #648.

johannes-wolf avatar Jul 16 '24 07:07 johannes-wolf

The current solution introduces new command line argument -withBitPositionCode. This command line argument enables generating of the bitPosition() method for all Structure, Choice and Union types. The bitPosition() method returns the bit position in the parsed blob after reading.

Note that the returned bit position is valid only directly after read! If the Zserio object has been changed after reading, the result is unspecified!

Because of the note above, better solution would be to generate bitPosition() method only for immutable objects (using withoutWriterCode option). However, this solution does not address the user's use case.

Another solution could be to overload reader constructor to introduce observer which will be called during parsing. This observer would get reference to the Zserio object together with its bit position in the blob. Such solution would allow application to implement whatever it wants. However, this solution would require bigger effort on both sides.

Because of that, the current solution, which can be easily misused, has been chosen. However, it will be clearly stated in the Zserio User Guide that this feature is experimental, is not part of API, and can be removed without any warning.

mikir avatar Aug 06 '24 07:08 mikir

There is a new request not to get only bit positions but bit sizes as well. This is because it is very difficult to get correct bit sizes for packed compounds.

We suggest to redesing the current solution in the following way:

  • The command line withBitPosition will be renamed to withParsingInfo.

  • The generated method withBitPosition will be renamed to parsingInfo:

    const ::zserio::ParsingInfo& parsingInfo() const;
    
    struct ParsingInfo
    {
        size_t bitPosition;
        size_t bitSize;
    };
    

This will allow to add more parsing information in the future without any change of the design.

mikir avatar Sep 06 '24 06:09 mikir