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
490
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
Amazon CloudWatchの地味だけど強力な機能紹介!
itotsum
0
230
サービスレベルを管理してアジャイルを加速しよう!! / slm-accelerate-agility
tomoyakitaura
1
200
スモールスタートで始めるためのLambda×モノリス(Lambdalith)
akihisaikeda
2
370
Serving TUIs over SSH with Go
caarlos0
0
590
Rubyの!メソッドをちゃんと理解する
alstrocrack
1
120
ComposeでWebアプリを作る技術
tbsten
0
130
SwiftDataのカスタムデータストアを試してみた
1mash0
0
140
Browser and UI #2 HTML/ARIA
ken7253
2
170
Road to RubyKaigi: Making Tinny Chiptunes with Ruby
makicamel
4
540
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
7
1.4k
파급효과: From AI to Android Development
l2hyunwoo
0
160
fieldalignmentから見るGoの構造体
kuro_kurorrr
0
130
Featured
See All Featured
Building Applications with DynamoDB
mza
94
6.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
5
560
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.3k
Code Review Best Practice
trishagee
67
18k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.4k
GraphQLとの向き合い方2022年版
quramy
46
14k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
5
590
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)