Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Parsing Binary Data
Jan Krutisch
June 29, 2012
Programming
0
95
Parsing Binary Data
A lighting talk about parsing binary data in ruby with bindata gem.
Jan Krutisch
June 29, 2012
Tweet
Share
More Decks by Jan Krutisch
See All by Jan Krutisch
Decentralize ALL THE THINGS - Eurucamp 2014
halfbyte
3
160
Decentralise ALL THE THINGS
halfbyte
0
150
Railsgirls - Coaches dinner introduction
halfbyte
0
40
SSL Deployment Best Practices
halfbyte
0
270
Metaphors are like knives. You can use them to cut yourself and if you throw rocks at them, they fall apart
halfbyte
0
1.5k
Livecoding Music and Graphics in the browser
halfbyte
0
160
Geeks and Music
halfbyte
0
100
JSON - Schmason
halfbyte
0
160
Javascript Audio APIs - Let's make some noise
halfbyte
0
120
Other Decks in Programming
See All in Programming
ECS Service Connectでマイクロサービスを繋いでみた
xblood
0
750
ちょうぜつ改め21世紀ふつうのソフトウェア設計
tanakahisateru
7
6.5k
ITエンジニア特化型Q&Aサイトteratailを 言語、DB、クラウドなど フルリプレイスした話
leveragestech
0
460
OSSから学んだPR Descriptionの書き方
fugakkbn
4
140
Circuit⚡
monaapk
0
200
爆速の日経電子版開発の今
shinyaigeek
2
660
OSC大阪 パスワード認証は人類には早すぎる ~ IDaaSを使ったソーシャルログインのすすめ ~
authyasan
7
1.5k
Prácticas de Seguridad en Kubernetes
pablokbs
0
130
Rust、何もわからない...#6発表資料
ryu19
0
140
(新米)エンジニアリングマネージャーのしごと #RSGT2023
murabayashi
9
6k
Listかもしれない
irof
1
290
Hasura の Relationship と権限管理
karszawa
0
180
Featured
See All Featured
Writing Fast Ruby
sferik
613
58k
Bootstrapping a Software Product
garrettdimon
299
110k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
31
20k
Navigating Team Friction
lara
177
12k
From Idea to $5000 a Month in 5 Months
shpigford
374
44k
Art, The Web, and Tiny UX
lynnandtonic
284
18k
Six Lessons from altMBA
skipperchong
15
2.3k
Designing Experiences People Love
moore
130
22k
The Mythical Team-Month
searls
210
40k
The Language of Interfaces
destraynor
149
21k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
38
3.6k
Keith and Marios Guide to Fast Websites
keithpitt
407
21k
Transcript
Parsing and Writing Binary Data in Ruby Jan Krutisch @halfbyte
[email protected]
señor developer
None
Protracker "mod" files
Binary Format
None
‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣
Sequence Data Mod File Contents
‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣
Sequence Data Mod File Contents Array of Structs (=Array of Hashes)
‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣
Sequence Data Mod File Contents Array of Structs (=Array of Hashes) Array of Blobs
‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣
Sequence Data Mod File Contents Array of Structs (=Array of Hashes) Array of Blobs Arrays of Arrays of Arrays of Structs
‣ Instrument Metadata ‣ Sample Data ‣ Pattern Data ‣
Sequence Data Mod File Contents Array of Structs (=Array of Hashes) Array of Blobs Arrays of Arrays of Arrays of Structs Array of Integers
Simple Approach
Serializer / Deserializer
Different Datatypes
Protracker Datatypes
Protracker Datatypes ‣ 8Bit signed binary blobs
Protracker Datatypes ‣ 8Bit signed binary blobs ‣ UInt8
Protracker Datatypes ‣ 8Bit signed binary blobs ‣ UInt8 ‣
UInt16 (Endianness?)
Protracker Datatypes ‣ 8Bit signed binary blobs ‣ UInt8 ‣
UInt16 (Endianness?) ‣ \0-Terminated/Padded Strings
Protracker Datatypes ‣ 8Bit signed binary blobs ‣ UInt8 ‣
UInt16 (Endianness?) ‣ \0-Terminated/Padded Strings ‣ Int4 (Yes, that‘s a signed halfbyte)
And this...
None
Procedural Mess
Declarative
gem "bindata"
class ProtrackerModule < BinData::Record endian :big string :name, :length =>
20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
class ProtrackerModule < BinData::Record endian :big string :name, :length =>
20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
class ProtrackerModule < BinData::Record endian :big string :name, :length =>
20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
class ProtrackerModule < BinData::Record endian :big string :name, :length =>
20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
class ProtrackerModule < BinData::Record endian :big string :name, :length =>
20, :trim_padding => true array :samples, :type => Sample, :length => 31 uint8 :pattern_table_length uint8 :unused array :pattern_table, :type => :uint8, :initial_length => 128 [...]
array :patterns, :type => Pattern, :initial_length => lambda { pattern_table.max
+ 1 }
None
Demo
señor developer http://senordevelopershop.spreadshirt.de/ (europe) http://senordeveloper.spreadshirt.com/ (intl)