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
0
210
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
210
Decentralise ALL THE THINGS
halfbyte
0
170
Railsgirls - Coaches dinner introduction
halfbyte
0
64
SSL Deployment Best Practices
halfbyte
0
480
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
270
Geeks and Music
halfbyte
0
190
JSON - Schmason
halfbyte
0
250
Javascript Audio APIs - Let's make some noise
halfbyte
0
160
Other Decks in Programming
See All in Programming
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
130
Ruby's Line Breaks
yui_knk
2
480
DomainException と Result 型で作る型安全なエラーハンドリング
karszawa
0
890
Rollupのビルド時間高速化によるプレビュー表示速度改善とバンドラとASTを駆使したプロダクト開発の難しさ
plaidtech
PRO
1
160
Agentic Applications with Symfony
el_stoffel
2
270
Vibe Codingをせずに Clineを使っている
watany
17
6.1k
「”誤った使い方をすることが困難”な設計」で良いコードの基礎を固めよう / phpcon-odawara-2025
taniguhey
0
120
custom_lintで始めるチームルール管理
akaboshinit
0
200
DataStoreをテストする
mkeeda
0
280
[NG India] Event-Based State Management with NgRx SignalStore
markostanimirovic
1
110
Strategic Design (DDD)for the Frontend @DDD Meetup Stuttgart
manfredsteyer
PRO
0
100
リストビュー画面UX改善の振り返り
splcywolf
0
130
Featured
See All Featured
For a Future-Friendly Web
brad_frost
176
9.7k
Side Projects
sachag
452
42k
Designing for Performance
lara
607
69k
Unsuck your backbone
ammeep
670
57k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
2.9k
Done Done
chrislema
183
16k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
650
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
13
1.4k
Into the Great Unknown - MozCon
thekraken
37
1.7k
How STYLIGHT went responsive
nonsquared
99
5.5k
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)