From: Dion Mendel Date: 2010-10-04T15:51:24+09:00 Subject: Re: any good tools for reading networking data with optional TLV Ramana Gollamudi wrote: > I tried to see if bindata works but the documentation is unclear > on whether it can handle multiple TLVS that may exist in different > combination in each packet? I am the author of BinData. Yes BinData handles optional TLVs (type-length-value). You didn't specify if your TLVs are nested or flat. An example of flat TLVs is given below. Nested TLVs are slightly more complicated and require more code so I haven't provided an example. Contact me offlist if you need more details. Here is an example of a data format (MyFormat) supporting multiple, optional, unordered TLVs. class CustomType1 < BinData::Record int8 :a int8 :b ... end ... class Tlv < BinData::Record endian :big uint8 :t uint32 :l choice :v, :selection => :chooser do string "unknown", :read_length => :l custom_type_1 "v1" custom_type_2 "v2" ... end def chooser if t == xx and l == yy "v1" elsif t == ww and l == zz ... else "unknown" end end end class MyFormat < BinData::Record ... array :options, :type => :tlv, :read_until => lambda { my_terminating_condition } end -- Posted via http://www.ruby-forum.com/.