Skip to content

Instantly share code, notes, and snippets.

@hkwi
Last active August 29, 2015 14:24
Show Gist options
  • Save hkwi/e23f19f2a4e8ee8b55fd to your computer and use it in GitHub Desktop.
Save hkwi/e23f19f2a4e8ee8b55fd to your computer and use it in GitHub Desktop.
ruby bindata choice by two fields example
require "bindata"
class D < BinData::Record
endian :big
uint8 :dd
end
class E < BinData::Record
endian :big
uint8 :ee
end
class F < BinData::Record
endian :big
uint8 :ff
end
class C < BinData::Record
endian :big
uint8 :a
uint8 :b
choice :f, selection: lambda { [a, b] } do
d [0,0]
e [0,1]
f :default
end
end
C.read("\x00\x00\x01")
C.read("\x00\x01\x01")
C.read("\x43\x21\x01")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment