jbangert-bindata 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +1 -0
  2. data/BSDL +22 -0
  3. data/COPYING +52 -0
  4. data/ChangeLog.rdoc +204 -0
  5. data/Gemfile +2 -0
  6. data/INSTALL +11 -0
  7. data/NEWS.rdoc +164 -0
  8. data/README.md +54 -0
  9. data/Rakefile +13 -0
  10. data/bindata.gemspec +31 -0
  11. data/doc/manual.haml +407 -0
  12. data/doc/manual.md +1649 -0
  13. data/examples/NBT.txt +149 -0
  14. data/examples/gzip.rb +161 -0
  15. data/examples/ip_address.rb +22 -0
  16. data/examples/list.rb +124 -0
  17. data/examples/nbt.rb +178 -0
  18. data/lib/bindata.rb +33 -0
  19. data/lib/bindata/alignment.rb +83 -0
  20. data/lib/bindata/array.rb +335 -0
  21. data/lib/bindata/base.rb +388 -0
  22. data/lib/bindata/base_primitive.rb +214 -0
  23. data/lib/bindata/bits.rb +87 -0
  24. data/lib/bindata/choice.rb +216 -0
  25. data/lib/bindata/count_bytes_remaining.rb +35 -0
  26. data/lib/bindata/deprecated.rb +50 -0
  27. data/lib/bindata/dsl.rb +312 -0
  28. data/lib/bindata/float.rb +80 -0
  29. data/lib/bindata/int.rb +184 -0
  30. data/lib/bindata/io.rb +274 -0
  31. data/lib/bindata/lazy.rb +105 -0
  32. data/lib/bindata/offset.rb +91 -0
  33. data/lib/bindata/params.rb +135 -0
  34. data/lib/bindata/primitive.rb +135 -0
  35. data/lib/bindata/record.rb +110 -0
  36. data/lib/bindata/registry.rb +92 -0
  37. data/lib/bindata/rest.rb +35 -0
  38. data/lib/bindata/sanitize.rb +290 -0
  39. data/lib/bindata/skip.rb +48 -0
  40. data/lib/bindata/string.rb +145 -0
  41. data/lib/bindata/stringz.rb +96 -0
  42. data/lib/bindata/struct.rb +388 -0
  43. data/lib/bindata/trace.rb +94 -0
  44. data/lib/bindata/version.rb +3 -0
  45. data/setup.rb +1585 -0
  46. data/spec/alignment_spec.rb +61 -0
  47. data/spec/array_spec.rb +331 -0
  48. data/spec/base_primitive_spec.rb +238 -0
  49. data/spec/base_spec.rb +376 -0
  50. data/spec/bits_spec.rb +163 -0
  51. data/spec/choice_spec.rb +263 -0
  52. data/spec/count_bytes_remaining_spec.rb +38 -0
  53. data/spec/deprecated_spec.rb +31 -0
  54. data/spec/example.rb +21 -0
  55. data/spec/float_spec.rb +37 -0
  56. data/spec/int_spec.rb +216 -0
  57. data/spec/io_spec.rb +352 -0
  58. data/spec/lazy_spec.rb +217 -0
  59. data/spec/primitive_spec.rb +202 -0
  60. data/spec/record_spec.rb +530 -0
  61. data/spec/registry_spec.rb +108 -0
  62. data/spec/rest_spec.rb +26 -0
  63. data/spec/skip_spec.rb +27 -0
  64. data/spec/spec_common.rb +58 -0
  65. data/spec/string_spec.rb +300 -0
  66. data/spec/stringz_spec.rb +118 -0
  67. data/spec/struct_spec.rb +350 -0
  68. data/spec/system_spec.rb +380 -0
  69. data/tasks/manual.rake +36 -0
  70. data/tasks/rspec.rake +17 -0
  71. metadata +208 -0
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/BSDL ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 2007-2012 Dion Mendel. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/COPYING ADDED
@@ -0,0 +1,52 @@
1
+ BinData is copyrighted free software by Dion Mendel <dion@lostrealm.com>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial).
42
+
43
+ 5. The scripts and library files supplied as input to or produced as
44
+ output from the software do not automatically fall under the
45
+ copyright of the software, but belong to whomever generated them,
46
+ and may be sold commercially, and may be aggregated with this
47
+ software.
48
+
49
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
50
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52
+ PURPOSE.
@@ -0,0 +1,204 @@
1
+ = BinData Changelog
2
+
3
+ == Version 1.5.1 (2013-xx-xx)
4
+
5
+ * Rework build system and include .gemspec. Requested by Simon Shortman.
6
+ * Fixed bug when Choice#clear didn't clear everything. Thanks to Simon
7
+ Shortman for the bug report.
8
+ * Moved BinData::VERSION into its own file. Thanks to John Van Enk.
9
+
10
+ == Version 1.5.0 (2013-05-21)
11
+
12
+ * Moved to github.
13
+ * Updated to Ruby 2.0
14
+ * Arrays now accept BinData object factories for :type (feature request by
15
+ Matt Dainty).
16
+ * Dynamically generated BinData objects can use the :name parameter to
17
+ register themselves.
18
+ * Remove functionality that has been deprecated for two years.
19
+
20
+ == Version 1.4.5 (2012-07-24)
21
+
22
+ * Added the :pad_front option for padding to occur at the front of a String.
23
+ (suggested by Eduardo Mourão).
24
+
25
+ == Version 1.4.4 (2012-06-21)
26
+
27
+ * Fixed bug where user defined boolean primitive wouldn't set its
28
+ value to false (reported by Frank Roland).
29
+ * Fixed infinite looping bug caused by nested Choices.
30
+ * Renamed String parameter :pad_char to :pad_byte.
31
+ * Updated manual.
32
+
33
+ == Version 1.4.3 (2011-10-01)
34
+
35
+ * Exceptions no longer ignored inside lambdas when reading until eof
36
+ in an array (thanks John Labovitz).
37
+ * Fixed interaction bug between choices and records (reported by
38
+ Refrigerator Johnny).
39
+
40
+ == Version 1.4.2 (2011-08-06)
41
+
42
+ * \=~ now works for strings.
43
+
44
+ == Version 1.4.1 (2011-06-20)
45
+
46
+ * Added :default option for Choices.
47
+ * Added count_bytes_remaining keyword.
48
+ * Increased speed of lazy evaluation.
49
+
50
+ == Version 1.4.0 (2011-06-14)
51
+
52
+ * Record#snapshot now returns fields in order.
53
+ * Removed the need to call #register_self in subclasses.
54
+ * Wrapper is now deprecated. Use subclassing instead.
55
+ * Updated license to mimic changes to the Ruby License.
56
+ * Refactoring to reduce memory usage.
57
+
58
+ == Version 1.3.1 (2011-01-25)
59
+
60
+ * Fixed file permissions problem.
61
+
62
+ == Version 1.3.0 (2011-01-25)
63
+
64
+ * BinData objects can now assign values when instantiating.
65
+ * Improved support for bit-based alignment.
66
+ * Updated reference manual.
67
+ * Added examples for declaring recursive structures.
68
+ * Objects deriving from BinData::Base should no longer override #initialize.
69
+ * Added BinData::Base(#new, #initialize_instance) to speed up
70
+ instantiation of multiple objects.
71
+ * Updated specs to rspec-1.3.0
72
+ * BinData::Struct.hide now expects symbols instead of strings.
73
+
74
+ == Version 1.2.2 (2010-12-14)
75
+
76
+ * Added Base.bindata_name method.
77
+ * Removed Base#done_read to reduce memory usage and cpu usage.
78
+ * Derived classes should now use do_read et al, instead of _do_read.
79
+ * Added predefinition of record fields to improve speed.
80
+ * Made compatible with ruby 1.9.2. Thanks to Andrew Watts.
81
+
82
+ == Version 1.2.1 (2010-07-20)
83
+
84
+ * Updated specs to be compatible with ruby 1.9.1
85
+
86
+ == Version 1.2.0 (2010-07-09)
87
+
88
+ * Deprecated Base#register. Use #register_self or #register_subclasses instead.
89
+ * Syntax improvement. Array, Structs and Choices can now use blocks to
90
+ specify fields.
91
+ * Reduced startup time (suggestion courtesy of Mike Ryan).
92
+
93
+ == Version 1.1.0 (2009-11-24)
94
+
95
+ * Allow anonymous fields in Records and Primitives.
96
+ * Add the ability to skip over unused data.
97
+ * Allow Records, Primitives and Wrappers to be derived from.
98
+ * Classes for integers are now defined on demand.
99
+
100
+ == Version 1.0.0 (2009-09-13)
101
+
102
+ * Is now compatible with Ruby 1.9
103
+ * Added reference manual.
104
+ * Added #rel_offset to Base.
105
+ * Removed support for deprecated functionality.
106
+
107
+ == Version 0.11.1 (2009-08-28)
108
+
109
+ * Allow wrapped types to work with struct's :onlyif parameter
110
+ * Use Array#index instead of #find_index for compatibility with Ruby 1.8.6
111
+ (patch courtesy of Joe Rozner).
112
+
113
+ == Version 0.11.0 (2009-06-28)
114
+
115
+ * Sanitizing code was refactored for speed.
116
+ * Arbitrary sized integers and bit fields are now automatically instantiated.
117
+ * Add ability to wrap existing types and override their parameters.
118
+
119
+ == Version 0.10.0 (2009-04-17)
120
+
121
+ * Arbitrary byte sized integers are now supported (e.g. 24bit, 808bit).
122
+ * Renamed String :trim_value parameter to :trim_padding.
123
+ * BinData::Array now behaves more like Ruby's Array.
124
+ * Added debug_name
125
+ * Added ability to trace reading
126
+ * Primitives now behave as their value. Calling #value is no longer needed.
127
+ * Renamed #to_s -> #to_binary_s to avoid confusion with Ruby's #to_s.
128
+ * Added #assign as the generic way to assign values to objects.
129
+ * Added :copy_on_change parameter to Choice.
130
+ * Implement #offset for all objects.
131
+ * Renamed Single -> BasePrimitive.
132
+ * Renamed SingleValue -> Primitive.
133
+ * Renamed MultiValue -> Record.
134
+ * The :onlyif parameter now only applies to fields inside Structs.
135
+ * LazyEvaluator can now supply arguments when invoking methods
136
+
137
+ == Version 0.9.3 (2008-12-03)
138
+
139
+ * Arrays can now :read_until => :eof
140
+ * TCPSocket and UDPSocket can now be used as input streams (patch courtesy
141
+ of Peter Suschlik).
142
+ * Added 128 bit integers.
143
+ * Significant memory usage reduction.
144
+ * Added custom mandatory and default parameters for user defined MultiValues.
145
+
146
+ == Version 0.9.2 (2008-07-18)
147
+
148
+ * Added lazy instantiation to allow recursive definitions.
149
+ * Array elements can be appended at any position.
150
+ * Deprecated the :readwrite parameter.
151
+ * Removed feature where Struct fields names could be nil.
152
+ * Reworked sanitizing system.
153
+
154
+ == Version 0.9.1 (2008-06-15)
155
+
156
+ * Implemented bit fields.
157
+ * Added :onlyif parameter to Base for specifying optional fields.
158
+ * Fixed IO offset bug with SingleValues.
159
+
160
+ == Version 0.9.0 (2008-06-02)
161
+
162
+ * Added :adjust_offset option to automatically seek to a given offset.
163
+ * Modified #read to accept strings as well as IO streams.
164
+ * Choice now accepts sparse arrays and hashes as :choice.
165
+ * Added BinData::Rest to help with debugging.
166
+ * Major internal restructuring - memory usage is much better.
167
+ * Improved documentation.
168
+
169
+ == Version 0.8.1 (2008-01-14)
170
+
171
+ * Reduced memory consumption.
172
+ * Increased execution speed.
173
+ * Deprecated BinData::Base.parameters.
174
+ * Fixed spec syntax (thanks to David Goodlad).
175
+
176
+ == Version 0.8.0 (2007-10-14)
177
+
178
+ * Add reserved field names to Struct.
179
+ * Prevent warnings about method redefinition.
180
+ * Allow Struct to masquerade as one of its fields.
181
+ * Renamed String param :initial_length to :read_length.
182
+ * BinData::Array now behaves more like the internal Ruby array.
183
+
184
+ == Version 0.7.0 (2007-08-26)
185
+
186
+ * Arrays now support terminating conditions as well as fixed length reads.
187
+ * Updated specs to new rspec syntax (0.9).
188
+ * Added scoped resolution of variables in lambdas.
189
+ * Added ability to append elements to arrays.
190
+
191
+ == Version 0.6.0 (2007-03-28)
192
+
193
+ * Added 64 bit integers.
194
+ * Added floating point numbers.
195
+ * Added endian keyword to Struct to reduce the amount of typing needed.
196
+
197
+ == Version 0.5.1 (2007-03-21)
198
+
199
+ * Updated documentation.
200
+ * Struct now raises an error if a field name shadows an existing method.
201
+
202
+ == Version 0.5.0 (2007-03-14)
203
+
204
+ * Initial public release.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/INSTALL ADDED
@@ -0,0 +1,11 @@
1
+ This package is designed to be installed with rubygems. If you don't
2
+ have rubygems installed on your system, the older setup.rb is
3
+ included as a convenience.
4
+
5
+ ($ su)
6
+ # ruby setup.rb
7
+
8
+ This simple step installs bindata under the default location for Ruby
9
+ libraries. You can also customize the installation by supplying some
10
+ options to setup.rb.
11
+ Try "ruby setup.rb --help".
@@ -0,0 +1,164 @@
1
+ = 1.5.0
2
+
3
+ Finally moved the source code to github.
4
+
5
+ Deprecated functionality has been removed to cleanup the codebase.
6
+
7
+ = 1.4.4
8
+
9
+ == Deprecations
10
+
11
+ The BinData::String parameter :pad_char has been renamed to :pad_byte. This
12
+ aids readibilty as Ruby 1.9 characters are not necessarily one byte.
13
+
14
+ = 1.4.0
15
+
16
+ == Deprecations
17
+
18
+ There is no longer any need to call #register_self when inheriting from
19
+ BinData::Base.
20
+
21
+ BinData::Wrapper is deprecated. You should use direct inheritance instead.
22
+
23
+ If your code looks like:
24
+ class Uint8Array < BinData::Wrapper
25
+ default_parameter :initial_element_value => 0
26
+
27
+ array :initial_length => 2 do
28
+ uint8 :initial_value => :initial_element_value
29
+ end
30
+ end
31
+
32
+ It should be changed to:
33
+ class Uint8Array < BinData::Array
34
+ default_parameter :initial_element_value => 0
35
+ default_parameter :initial_length => 2
36
+
37
+ uint8 :initial_value => :initial_element_value
38
+ end
39
+
40
+ See http://bindata.rubyforge.org/manual.html#extending_existing_types for details.
41
+
42
+ = 1.3.0
43
+
44
+ == New features
45
+
46
+ You can now assign values to BinData objects when instantiating them.
47
+
48
+ Previously:
49
+ obj = BinData::Stringz.new(:max_length => 10)
50
+ obj.assign("abc")
51
+
52
+ Now:
53
+ obj = BinData::Stringz.new("abc", :max_length => 10)
54
+
55
+ == Backwards incompatible changes
56
+
57
+ This version makes some backwards incompatible changes for more advanced
58
+ users of BinData.
59
+
60
+ This only affects you if you have created your own custom types by
61
+ subclassing BinData::Base or BinData::BasePrimitive.
62
+
63
+ All instance variables must now be initialized in #initialize_instance.
64
+ Implementing #initialize is no longer allowed.
65
+
66
+ Run your existing code in $VERBOSE mode ("ruby -w"), and BinData will
67
+ inform you of any changes you need to make to your code.
68
+
69
+ If your code previously looked like:
70
+
71
+ class MyType < BinData::Base
72
+ register_self
73
+
74
+ def initialize(parameters = {}, parent = nil)
75
+ super
76
+
77
+ @var1 = ...
78
+ @var2 = ...
79
+ end
80
+ ...
81
+ end
82
+
83
+ You must change it to look like:
84
+
85
+ class MyType < BinData::Base
86
+ register_self
87
+
88
+ def initialize_instance
89
+ @var1 = ...
90
+ @var2 = ...
91
+ end
92
+ ...
93
+ end
94
+
95
+ = 1.0.0
96
+
97
+ Version 1.0.0 removes all deprecated features. If you are upgrading from a
98
+ version prior to 0.10.0 you will need to make changes to your code before it
99
+ will work with BinData 1.0.0 or later.
100
+
101
+ It is recommended to first upgrade to 0.11.1, and run your code with the -w
102
+ command line switch. This will turn on warning messages that should give you
103
+ hints about which parts of your code need changing. See the NEWS for 0.10.0
104
+ for details of the deprecated features.
105
+
106
+ = 0.10.0
107
+
108
+ There are several new features in this release. The major ones are:
109
+
110
+ * Debugging declarations is now easier with the ability to trace values when
111
+ reading.
112
+
113
+ BinData::trace_reading(STDERR) do
114
+ obj_not_quite_working_correctly.read(io)
115
+ end
116
+
117
+ Will result in a debugging trace written to STDERR.
118
+
119
+ * Support for arbitrary sized integers and bit fields.
120
+
121
+ * Struct/Array field/element access now returns a BinData object, rather than
122
+ the underlying Fixnum or String. The BinData object will behave like it's
123
+ underlying primitive so existing code should continue to work. This allows
124
+ for an improved syntax in your declarations.
125
+
126
+ If your code requires access to the underlying primitive, you can access it
127
+ with the #value method.
128
+
129
+ There are several deprecations and one backwards incompatible change in this
130
+ release. Turn on $VERBOSE mode (-w command line switch) to see warnings
131
+ regarding these deprecations.
132
+
133
+ == IMPORTANT - Ruby does not warn you about this change!
134
+
135
+ * The #to_s method for getting the binary string representation of a data
136
+ object has been renamed to #to_binary_s. If you use this method you must
137
+ manually change your code or you will get strange results.
138
+
139
+ == Deprecations. Ruby will warn you of these when in $VERBOSE mode.
140
+
141
+ Code using these deprecated features will still work in this release but will
142
+ fail to work in some future release. Change your code now.
143
+
144
+ * BinData::SingleValue has been renamed to BinData::Primitive.
145
+
146
+ * BinData::MultiValue has been renamed to BinData::Record.
147
+
148
+ * String :trim_value parameter has been renamed to :trim_padding.
149
+
150
+ * Registry.instance should be replaced with RegisteredClasses.
151
+
152
+ * struct.offset_of("field") should be replaced with struct.field.offset.
153
+
154
+ * struct.clear("field") should be replaced with struct.field.clear.
155
+
156
+ * struct.clear?("field") should be replaced with struct.field.clear?.
157
+
158
+ * struct.num_bytes("field") should be replaced with struct.field.num_bytes.
159
+
160
+ * array.clear(n) should be replaced with array[n].clear.
161
+
162
+ * array.clear?(n) should be replaced with array[n].clear?.
163
+
164
+ * array.num_bytes(n) should be replaced with array[n].num_bytes.