Last active
August 29, 2015 14:24
-
-
Save hkwi/e23f19f2a4e8ee8b55fd to your computer and use it in GitHub Desktop.
ruby bindata choice by two fields example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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