Skip to content

vector :classes_from

tqbf edited this page Sep 13, 2010 · 1 revision

I accept no responsibility for this design.



require 'ruckus'

class Meep < Ruckus::Structure
    n32 :count

    module Commands
        FOO_COMMAND = 1
        BAR_COMMAND = 2

        class FooCommand < Ruckus::Structure
            byte :kind
            byte :a
            byte :b
            byte :c
            byte :d
        end

        class BarCommand < Ruckus::Structure
            byte :kind
            n32 :val
        end
    end

    vector :commands,
           :keys_from => Commands,
           :classes_from => Commands,
           :key_finder => lambda {|x| x[0]},
           :count => :value,
           :from_field => :count
end

@testbuf = "\x00\x00\x00\x03\x01\x69\x69\x69\x69\x02\x69\x69\x69\x69\x01\x00\x00\x00\x01"


Clone this wiki locally