binary data - BinData::Record with Array read fails while write works -
In the example below, I can create a new BinData :: record containing a BinData :: array element , And am able to create a binary string from that new type of new object, however, when I try to instantiate a new object from that binary string, the new object is not well-formed.
'bindata' class IntegerArray & lt; BinData :: Ara UIT 16L Initial_Value: 0 and Class Test & lt; BinData :: record round_array: end of field obj = test.new obj [: area] [15]} str.inspect # "\ x0F \ x00" puts str.unpack ("S & lt; *") # 15 newobj = Test read (ARR) newobj.inspect # # puts "#" "field" = & Gt; []} I have tried to remove the initial_man of the array from the same result, thanks in advance for your help.
After a little experimentation, the following solution works:
requires 'bundda' class number here & lt; BinData :: Ara UIT 16L Initial_Value: 0 and Class Test & lt; BinData :: record number_are: area, read_until :: eof end obj = test.new obj [: area] .sample ([1, 2, 3, 4, 5]) str = obj.to_binary_s puts obj.num_bytes # 10 Obj.inspect # {"field" = & gt; [1, 2, 3, 4, 5]} str.inspect # "\ x01 \ x00 \ x02 \ x00 \ x03 \ x00 \ x04 \ x00 \ x05 \ x00" returns newobj = test.read (str) puts newobj .num_bytes # 10 puts newobj.inspect # {"field" = & gt; [1, 2, 3, 4, 5]} Use read_until :: eof while defining a note array field without reading it The defined value of initial_length will be read (which is exclusive with read_until ).
Comments
Post a Comment