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

Feature request: Add tracing support, for debugging purposes #35

Closed
adfoster-r7 opened this issue Nov 12, 2022 · 0 comments · Fixed by #36
Closed

Feature request: Add tracing support, for debugging purposes #35

adfoster-r7 opened this issue Nov 12, 2022 · 0 comments · Fixed by #36

Comments

@adfoster-r7
Copy link
Contributor

It would be cool to add support for outputting parsing information as the input stream is context. This functionality would have been very useful at the start when I was implementing the initial Kerberos specification

As an example - a library that does this is https://github.com/dmendel/bindata which is a declarative library for parsing binary structure which has a tracing feature:

require 'bindata'

class Polygon < BinData::Record
  endian :little
  uint8 :num_points, :value => lambda { points.length }
  array :points, :initial_length => :num_points do
    double :x
    double :y
  end
end

data =
  "\x03\x00\x00\x00\x00\x00\x00\xf0\x3f\x00\x00\x00\x00\x00\x00\x00" \
  "\x40\x00\x00\x00\x00\x00\x00\x08\x40\x00\x00\x00\x00\x00\x00\x10" \
  "\x40\x00\x00\x00\x00\x00\x00\x14\x40\x00\x00\x00\x00\x00\x00\x18" \
  "\x40".b

BinData::trace_reading($stdout) do
  puts Polygon.read(data)
end

Outputs:

obj.num_points => 3
obj.points[0].x => 1.0
obj.points[0].y => 2.0
obj.points[1].x => 3.0
obj.points[1].y => 4.0
obj.points[2].x => 5.0
obj.points[2].y => 6.0
{:num_points=>3, :points=>[{:x=>1.0, :y=>2.0}, {:x=>3.0, :y=>4.0}, {:x=>5.0, :y=>6.0}]}

The API could be similar for RASN1, and it would be useful for users that are parsing complex structures. At the minute a parsing failure results in a crash, and I manually delete fields until I get things to parse again successfully

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

Successfully merging a pull request may close this issue.

2 participants