ManageIQ / binary_struct

BinaryStruct is a class for dealing with binary structured data.
MIT License
4 stars 11 forks source link

Support Hash syntax for the definition. #7

Closed Fryguy closed 9 years ago

Fryguy commented 9 years ago

The following is a lot clearer to me, and since Hashes are ordered, its just as effective. In the past, we couldn't do this because of the unordered nature of Hash in Ruby <= 1.8.7.

gif_header = BinaryStruct.new(
  :magic              => "a3"
  :version            => "a3",
  :width              => "S",
  :height             => "S",
  :flags              => "a",
  :bg_color_index     => "C",
  :pixel_aspect_ratio => "C",
)

Note that for a major version we may want to deprecate the "backwards" format. We still need associative Arrays for if you want multiple nil keys, but I think just supporting Hash and associative Arrays makes the code much simpler.