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

Add support for record and multiendian #17

Closed
wants to merge 2 commits into from
Closed

Add support for record and multiendian #17

wants to merge 2 commits into from

Conversation

jlukas
Copy link

@jlukas jlukas commented Nov 21, 2013

record can be used to specify dynamic types as fields of a record or struct:

def type(arguments)
  BinData::Struct(...)
end

class A < BinData::Record
  record :field, type: type(arguments)
end

multiendian can be used to automatically duplicate a type for big and little endian

BinData::Record.multiendian(:type_name) do
  uint32 :field
end

class A < BinData::Record
  endian :little
  type_name :field # knows to use little-endian version of type_name
end

class B < BinData::Record
  endian :big
  type_name :field # knows to use big-endian version of type_name
end

Jacob Lukas added 2 commits November 21, 2013 13:44
record can be used to specify dynamic types as fields of a record or struct:

def type(arguments)
  BinData::Struct(...)
end

class A < BinData::Record
  record :field, type: type(arguments)
end

multiendian can be used to automatically duplicate a type for big and little endian

BinData::Record.multiendian(:type_name) do
  uint32 :field
end

class A < BinData::Record do
  endian :little
  type_name :field # knows to use little-endian version of type_name
end

class B < BinData::Record do
  endian :big
  type_name :field # knows to use big-endian version of type_name
end
@dmendel
Copy link
Owner

dmendel commented Nov 24, 2013

Thanks for your code proposal.

I've committed a change to master so that the endian keyword applies to custom types as well as built in numerics.

class CoordLe < BinData::Record
  endian :little
  int16  :x
  int16  :y
end

class CoordBe < BinData::Record
  endian :big
  int16  :x
  int16  :y
end

class Rectangle < BinData::Record
  endian :little
  coord  :upper_left     # <-- Here CoordLe is automatically
  coord  :lower_right    # <-- assumed
end

Your record keyword:

I think the change I previously noted removes the need for this keyword. Let me know if you have a use case where record is needed.

A declaration shouldn't contain implementation details such as whether a type is dynamically defined. This keyword makes declarations over complicated.


I'm still considering the multi endian declaration. If I implement it, it will have to apply to Records, Primitives, Arrays and Choices. At the moment, I don't like the proposed syntax as it is too different to current declarations.

@dmendel dmendel closed this Dec 4, 2013
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

Successfully merging this pull request may close these issues.

2 participants