Weitere ähnliche Inhalte
Kürzlich hochgeladen (12)
BinDataで バイナリデータを 楽に扱う
- 11. require 'bindata'
class SampleBase < BinData::Record
endian :big
uint8 :head
uint8 :len
string :str, :read_length => :len
uint8 :tail
end
p SampleBase.read("~u0004abcd@")
- 15. require 'bindata'
class SampleBase < BinData::Record
endian :big
uint8 :head
uint8 :len
string :str, :read_length => :len
uint8 :tail
end
p SampleBase.read("~u0004abcd@")
Gem “bindata”
を導入します。
- 16. require 'bindata'
class SampleBase < BinData::Record
endian :big
uint8 :head
uint8 :len
string :str, :read_length => :len
uint8 :tail
end
p SampleBase.read("~u0004abcd@")
普通に使う分には、
BinData::Record
を継承するだけで
十分実用に足ります
- 17. require 'bindata'
class SampleBase < BinData::Record
endian :big
uint8 :head
uint8 :len
string :str, :read_length => :len
uint8 :tail
end
p SampleBase.read("~u0004abcd@")
エンディアンの指定も可能です。
要素毎の設定も容易。
- 18. require 'bindata'
class SampleBase < BinData::Record
endian :big
uint8 :head
uint8 :len
string :str, :read_length => :len
uint8 :tail
end
p SampleBase.read("~u0004abcd@")
ビット列と文字が混
在可能!
- 23. require 'bindata'
class SampleBase < BinData::Record
endian :big
uint8 :head
uint8 :len
array :body, :type => :uint8, :initial_length => :len
uint8 :tail
end
p SampleBase.read("~u0004u0042u0011u0012u0000 @")
型を変換するだけ