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
230
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
260
Decentralise ALL THE THINGS
halfbyte
0
200
Railsgirls - Coaches dinner introduction
halfbyte
0
69
SSL Deployment Best Practices
halfbyte
0
510
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
300
Geeks and Music
halfbyte
0
200
JSON - Schmason
halfbyte
0
270
Javascript Audio APIs - Let's make some noise
halfbyte
0
170
Other Decks in Programming
See All in Programming
機能追加とリーダー業務の類似性
rinchoku
2
1.2k
[FEConf 2025] 모노레포 절망편, 14개 레포로 부활하기까지 걸린 1년
mmmaxkim
0
1.6k
意外と簡単!?フロントエンドでパスキー認証を実現する WebAuthn
teamlab
PRO
2
720
AIでLINEスタンプを作ってみた
eycjur
1
230
プロパティベーステストによるUIテスト: LLMによるプロパティ定義生成でエッジケースを捉える
tetta_pdnt
0
300
Laravel Boost 超入門
fire_arlo
2
210
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
320
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
270
デザイナーが Androidエンジニアに 挑戦してみた
874wokiite
0
280
AIを活用し、今後に備えるための技術知識 / Basic Knowledge to Utilize AI
kishida
21
5.6k
個人軟體時代
ethanhuang13
0
320
Rancher と Terraform
fufuhu
2
240
Featured
See All Featured
The Language of Interfaces
destraynor
161
25k
Practical Orchestrator
shlominoach
190
11k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
GraphQLとの向き合い方2022年版
quramy
49
14k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
236
140k
Statistics for Hackers
jakevdp
799
220k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
The Art of Programming - Codeland 2020
erikaheidi
55
13k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
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)