Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Parsing Binary Data
Search
Jan Krutisch
June 29, 2012
Programming
260
0
Share
Parsing Binary Data
A lighting talk about parsing binary data in ruby with bindata gem.
Jan Krutisch
June 29, 2012
More Decks by Jan Krutisch
See All by Jan Krutisch
Decentralize ALL THE THINGS - Eurucamp 2014
halfbyte
3
290
Decentralise ALL THE THINGS
halfbyte
0
220
Railsgirls - Coaches dinner introduction
halfbyte
0
96
SSL Deployment Best Practices
halfbyte
0
550
Metaphors are like knives. You can use them to cut yourself and if you throw rocks at them, they fall apart
halfbyte
0
1.7k
Livecoding Music and Graphics in the browser
halfbyte
0
350
Geeks and Music
halfbyte
0
230
JSON - Schmason
halfbyte
0
290
Javascript Audio APIs - Let's make some noise
halfbyte
0
210
Other Decks in Programming
See All in Programming
【ディップ|26年新卒研修資料】OpenAPI/Swagger REST API研修
dip_tech
PRO
0
160
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
130
20260514 - build with ai 2026 - build LINE Bot with Gemini CLI
line_developers_tw
PRO
0
440
Road to RubyKaigi: Play Hard(ware)
makicamel
1
570
SkillsをS3 Filesに置く時のあれこれ
watany
3
1.6k
Back to the roots of date
jinroq
0
840
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
160
Programming with a DJ Controller — not vibe coding
m_seki
3
850
cloudnative conference 2026 flyle
azihsoyn
0
180
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
820
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
3k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
420
Featured
See All Featured
Navigating Team Friction
lara
192
16k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Scaling GitHub
holman
464
140k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Visualization
eitanlees
151
17k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.7k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
790
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
300
Balancing Empowerment & Direction
lara
6
1.1k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
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)