forked from dmendel/bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual.haml
407 lines (391 loc) · 16.8 KB
/
manual.haml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
!!!
%html{ :xmlns => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", :lang => "en" }
%head
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-Type" }
%meta{ :name => "description", :content =>"How to easily read and write binary data in Ruby" }
%meta{ :keywords =>"ruby, binary, binary data, parse binary data, read binary data, write binary data, binary file, read binary file, write binary file" }
%title
Reading, writing and parsing binary data in Ruby
:javascript
var TINY={};function T$(i){return document.getElementById(i)}function T$$(e,p){return p.getElementsByTagName(e)}TINY.accordion=function(){function slider(n){this.n=n;this.a=[]}slider.prototype.init=function(t,e,m,o,k){var a=T$(t),i=s=0,n=a.childNodes,l=n.length;this.s=k||0;this.m=m||0;for(i;i<l;i++){var v=n[i];if(v.nodeType!=3){this.a[s]={};this.a[s].h=h=T$$(e,v)[0];this.a[s].c=c=T$$('div',v)[0];h.onclick=new Function(this.n+'.pr(0,'+s+')');if(o==s){h.className=this.s;c.style.height='auto';c.d=1}else{c.style.height=0;c.d=-1}s++}}this.l=s};slider.prototype.pr=function(f,d){for(var i=0;i<this.l;i++){var h=this.a[i].h,c=this.a[i].c,k=c.style.height;k=k=='auto'?1:parseInt(k);clearInterval(c.t);if((k!=1&&c.d==-1)&&(f==1||i==d)){c.style.height='';c.m=c.offsetHeight;c.style.height=k+'px';c.d=1;h.className=this.s;su(c,1)}else if(k>0&&(f==-1||this.m||i==d)){c.d=-1;h.className='';su(c,-1)}}};function su(c){c.t=setInterval(function(){sl(c)},20)};function sl(c){var h=c.offsetHeight,d=c.d==1?c.m-h:h;c.style.height=h+(Math.ceil(d/5)*c.d)+'px';c.style.opacity=h/c.m;c.style.filter='alpha(opacity='+h*100/c.m+')';if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'}clearInterval(c.t)}};return{slider:slider}}();
var menu1, menu2, menu3, menu4, menu5, menu6, menu7;
var menu8, menu9, menu10, menu11, menu12, menu13, menu14, menu15;
function init_accordion() {
menu1 = new TINY.accordion.slider("menu1"); menu1.init("menu1","a",1,-1);
menu2 = new TINY.accordion.slider("menu2"); menu2.init("menu2","a",1,-1);
menu3 = new TINY.accordion.slider("menu3"); menu3.init("menu3","a",1,-1);
menu4 = new TINY.accordion.slider("menu4"); menu4.init("menu4","a",1,-1);
menu5 = new TINY.accordion.slider("menu5"); menu5.init("menu5","a",1,-1);
menu6 = new TINY.accordion.slider("menu6"); menu6.init("menu6","a",1,-1);
menu7 = new TINY.accordion.slider("menu7"); menu7.init("menu7","a",1,-1);
menu8 = new TINY.accordion.slider("menu8"); menu8.init("menu8","a",1,-1);
menu9 = new TINY.accordion.slider("menu9"); menu9.init("menu9","a",1,-1);
menu10 = new TINY.accordion.slider("menu10"); menu10.init("menu10","a",1,-1);
menu11 = new TINY.accordion.slider("menu11"); menu11.init("menu11","a",1,-1);
menu12 = new TINY.accordion.slider("menu12"); menu12.init("menu12","a",1,-1);
menu13 = new TINY.accordion.slider("menu13"); menu13.init("menu13","a",1,-1);
menu14 = new TINY.accordion.slider("menu14"); menu14.init("menu14","a",1,-1);
menu15 = new TINY.accordion.slider("menu15"); menu15.init("menu15","a",1,-1);
};
window.onload = init_accordion;
%style{:type => "text/css", :media => "screen"}
:plain
body {
margin:0; padding:0; border:0;
height:100%; max-height:100%;
overflow:hidden;
background-color:#FFF;
}
#left_frame {
position:absolute; overflow:hidden;
top:0; bottom:0; left:0;
width:240px; height:100%;
}
#main_frame {
position:fixed; overflow:auto;
top:0; right:0; bottom:0; left:240px;
}
* html body { /*IE6 hack*/
padding: 0 0 0 240px;
}
* html #main_frame { /*IE6 hack*/
height: 100%; width: 100%;
}
.menu_top_level {margin:5px;}
.menu_top_level ul {list-style:none; margin:0; padding:0;}
.menu_top_level li {margin-top:5px;}
.menu_top_level .acc-section {overflow:hidden;}
.menu_top_level .acc-content {width:100%; margin:0; padding:0; background:#FFF}
.menu_top_level li a {
display:block; cursor:pointer; text-decoration: none;
border:1px solid #9BC;
padding: 0;
font:bold 12px/2 Verdana, Arial, Helvetica;
}
.menu_top_level li a:link, .menu_top_level li a:visited { color: #131; background:#FFE;}
.menu_top_level li a:hover {background: #9C9; color:#FFE;}
.menu_top_level .level1 li a { padding-left: 15px; }
.menu_top_level .level2 li a { padding-left: 30px; }
.menu_top_level .level3 li a { padding-left: 45px; }
#main_content {
margin: 20px; padding-left: 3em;
width: 40em;
font-family: Georgia, Times;
}
#main_content h1 { margin-left: -1em;}
#main_content h2 { margin-left: -1em;}
#main_content pre {
margin-left: 2em; padding: 4px;
background-color: #EFF;
border: solid 1px #BDD;
}
#main_content .ruby .normal {}
#main_content .ruby .comment { color: #005; font-style: italic; }
#main_content .ruby .keyword { color: #A00; font-weight: bold; }
#main_content .ruby .method { color: #077; }
#main_content .ruby .class { color: #074; }
#main_content .ruby .module { color: #050; }
#main_content .ruby .punct { color: #447; font-weight: bold; }
#main_content .ruby .symbol { color: #099; }
#main_content .ruby .string { color: #944; background: #FFE; }
#main_content .ruby .char { color: #F07; }
#main_content .ruby .ident { color: #004; }
#main_content .ruby .constant { color: #07F; }
#main_content .ruby .regex { color: #B66; background: #FEF; }
#main_content .ruby .number { color: #F99; }
#main_content .ruby .attribute { color: #7BB; }
#main_content .ruby .global { color: #7FB; }
#main_content .ruby .expr { color: #227; }
#main_content .ruby .escape { color: #277; }
%script{:type => "text/javascript"}
:plain
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20958115-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
%body
#left_frame
.menu_top_level
%ul.level1#menu1
%li
%a{ :href => "#bindata" }
BinData
.acc-section
.acc-content
%ul.level2#menu2
%li
%a{ :href => "#what_is_it_for" }
What is it for?
.acc-section
.acc-content
%li
%a{ :href => "#license" }
License
.acc-section
.acc-content
%li
%a{ :href => "#donate" }
Donate
.acc-section
.acc-content
%li
%a{ :href => "#installation" }
Installation
.acc-section
.acc-content
%li
%a{ :href => "#overview" }
Overview
.acc-section
.acc-content
%li
%a{ :href => "#records" }
Records
.acc-section
.acc-content
%ul.level2#menu3
%li
%a{ :href => "#specifying_default_endian" }
Specifying default endian
.acc-section
.acc-content
%li
%a{ :href => "#dependencies_between_fields" }
Dependencies between fields
.acc-section
.acc-content
%li
%a{ :href => "#nested_records" }
Nested Records
.acc-section
.acc-content
%li
%a{ :href => "#optional_fields" }
Optional fields
.acc-section
.acc-content
%li
%a{ :href => "#primitive_types" }
Primitive Types
.acc-section
.acc-content
%ul.level2#menu4
%li
%a{ :href => "#numerics" }
Numerics
.acc-section
.acc-content
%ul.level3#menu5
%li
%a{ :href => "#byte_based_integers" }
Byte based integers
.acc-section
.acc-content
%li
%a{ :href => "#bit_based_integers" }
Bit based integers
.acc-section
.acc-content
%li
%a{ :href => "#floating_point_numbers" }
Floating point numbers
.acc-section
.acc-content
%li
%a{ :href => "#example" }
Example
.acc-section
.acc-content
%li
%a{ :href => "#strings" }
Strings
.acc-section
.acc-content
%ul.level3#menu6
%li
%a{ :href => "#fixed_sized_strings" }
Fixed Sized Strings
.acc-section
.acc-content
%li
%a{ :href => "#zero_terminated_strings" }
Zero Terminated Strings
.acc-section
.acc-content
%li
%a{ :href => "#user_defined_primitive_types" }
User-defined Primitive Types
.acc-section
.acc-content
%ul.level3#menu7
%li
%a{ :href => "#advanced_user_defined_primitive_types" }
Advanced Example
.acc-section
.acc-content
%li
%a{ :href => "#compound_types" }
Compound Types
.acc-section
.acc-content
%ul.level2#menu8
%li
%a{ :href => "#arrays" }
Arrays
.acc-section
.acc-content
%ul.level3#menu9
%li
%a{ :href => "#array_syntax" }
Array syntax
.acc-section
.acc-content
%li
%a{ :href => "#array_parameters" }
Array parameters
.acc-section
.acc-content
%li
%a{ :href => "#choices" }
Choices
.acc-section
.acc-content
%ul.level3#menu10
%li
%a{ :href => "#choice_syntax" }
Choice syntax
.acc-section
.acc-content
%li
%a{ :href => "#choice_parameters" }
Choice parameters
.acc-section
.acc-content
%li
%a{ :href => "#default_selection" }
Default Selection
.acc-section
.acc-content
%li
%a{ :href => "#common_operations" }
Common Operations
.acc-section
.acc-content
%ul.level2#menu11
%li
%a{ :href => "#reading_and_writing" }
Reading and writing
.acc-section
.acc-content
%li
%a{ :href => "#manipulating" }
Manipulating
.acc-section
.acc-content
%li
%a{ :href => "#inspecting" }
Inspecting
.acc-section
.acc-content
%li
%a{ :href => "#advanced_topics" }
Advanced Topics
.acc-section
.acc-content
%ul.level2#menu12
%li
%a{ :href => "#debugging" }
Debugging
.acc-section
.acc-content
%ul.level3#menu13
%li
%a{ :href => "#tracing" }
Tracing
.acc-section
.acc-content
%li
%a{ :href => "#rest" }
Rest
.acc-section
.acc-content
%li
%a{ :href => "#hidden_fields" }
Hidden fields
.acc-section
.acc-content
%li
%a{ :href => "#parameterizing_user_defined_types" }
Parameterizing Types
.acc-section
.acc-content
%ul.level3#menu14
%li
%a{ :href => "#mandatory_parameters" }
Mandatory Parameters
.acc-section
.acc-content
%li
%a{ :href => "#default_parameters" }
Default Parameters
.acc-section
.acc-content
%li
%a{ :href => "#extending_existing_types" }
Extending existing Types
.acc-section
.acc-content
%li
%a{ :href => "#dynamically_creating_types" }
Dynamically creating Types
.acc-section
.acc-content
%li
%a{ :href => "#skipping_over_unused_data" }
Skipping over unused data
.acc-section
.acc-content
%li
%a{ :href => "#determining_stream_length" }
Determining stream length
.acc-section
.acc-content
%li
%a{ :href => "#advanced_bitfields" }
Advanced Bitfields
.acc-section
.acc-content
%li
%a{ :href => "#faq" }
FAQ
.acc-section
.acc-content
%ul.level2#menu15
%li
%a{ :href => "#im_using_ruby_19_how_do_i_use_string_encodings_with_bindata" }
String encoding - Ruby 1.9
.acc-section
.acc-content
%li
%a{ :href => "#how_do_i_speed_up_initialization" }
Performance
.acc-section
.acc-content
%li
%a{ :href => "#how_do_i_model_this_complex_nested_format" }
Recursive declarations
.acc-section
.acc-content
%li
%a{ :href => "#alternatives" }
Alternatives
.acc-section
.acc-content
#main_frame
#main_content
:maruku
#{File.read("manual.md")}