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
170
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
180
Decentralise ALL THE THINGS
halfbyte
0
170
Railsgirls - Coaches dinner introduction
halfbyte
0
63
SSL Deployment Best Practices
halfbyte
0
440
Metaphors are like knives. You can use them to cut yourself and if you throw rocks at them, they fall apart
halfbyte
0
1.6k
Livecoding Music and Graphics in the browser
halfbyte
0
230
Geeks and Music
halfbyte
0
180
JSON - Schmason
halfbyte
0
230
Javascript Audio APIs - Let's make some noise
halfbyte
0
140
Other Decks in Programming
See All in Programming
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
140
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
610
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
4
13k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
430
Vue.js学習の振り返り
hiro_xre
2
130
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
2
2k
カスタムしながら理解するGraphQL Connection
yanagii
0
680
CSC509 Lecture 07
javiergs
PRO
0
140
offers_20241022_imakiire.pdf
imakurusu
2
310
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
3
1k
Workflow automationによるインシデント原因調査の自動化
showwin
1
120
#pixiv小説画像メーカー はこうしてできた / The Making of the pixiv Novel Image Maker
roiban
0
220
Featured
See All Featured
Speed Design
sergeychernyshev
24
560
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
13
1.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Six Lessons from altMBA
skipperchong
26
3.4k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
A Modern Web Designer's Workflow
chriscoyier
692
190k
A Philosophy of Restraint
colly
203
16k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
Side Projects
sachag
452
42k
Unsuck your backbone
ammeep
668
57k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Adopting Sorbet at Scale
ufuk
73
9k
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)