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
89
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
130
Decentralise ALL THE THINGS
halfbyte
0
150
Railsgirls - Coaches dinner introduction
halfbyte
0
37
SSL Deployment Best Practices
halfbyte
0
230
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
150
Geeks and Music
halfbyte
0
96
JSON - Schmason
halfbyte
0
150
Javascript Audio APIs - Let's make some noise
halfbyte
0
82
Other Decks in Programming
See All in Programming
ゴーファーくんと辿るプログラミング言語の歴史/history-of-programming-languages-with-gopher
iwasiman
11
5k
ベストプラクティス・ドリフト
sssssssssssshhhhhhhhhh
1
210
企業内スモールデータでのデータ解析
hamage9
0
890
AWS Config Custom Rule、ノーコードでできるかな?
watany
0
250
Rに管理されてみる
kazutan
0
250
ファーストペンギンを志すものに伝えたい - 1人目のアジャイル推進者がたどった成功と失敗
psj59129
0
100
Recap CDN, Edge, WebAssembly | ワインと鍋.js#1
sadnessojisan
2
1.2k
これからのスクラムマスターのキャリアプランの話をしよう - スクラムマスターの前に広がる世界
psj59129
0
200
More Than Micro Frontends: 3 Further Use Cases for Module Federation @DWX 2022
manfredsteyer
PRO
0
360
動画合成アーキテクチャを実装してみて
satorunooshie
0
540
Lookerとdbtの共存
ttccddtoki
0
620
Isar勉強会
hoddy3190
0
400
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
219
17k
GraphQLの誤解/rethinking-graphql
sonatard
31
6.8k
Unsuck your backbone
ammeep
659
55k
Large-scale JavaScript Application Architecture
addyosmani
499
110k
Atom: Resistance is Futile
akmur
255
20k
What the flash - Photography Introduction
edds
62
10k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
37
3.3k
A Tale of Four Properties
chriscoyier
149
21k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
15
980
The World Runs on Bad Software
bkeepers
PRO
57
5.4k
Six Lessons from altMBA
skipperchong
14
1.4k
Infographics Made Easy
chrislema
233
17k
Transcript
Parsing and Writing Binary Data in Ruby Jan Krutisch @halfbyte
jan.krutisch@mindmatters.de
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)