bit-struct 0.13.6 → 0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 608b421ed008ebeb58562339819ffcd658042440
4
+ data.tar.gz: 261e61fdd294f8ac987e52b7fbce9611d0ee9460
5
+ SHA512:
6
+ metadata.gz: 7df8011e8550844695ef884a39a1f16afaf7e602633c6e518fe3ed869d9873f79b653881a8600b3fcc97dcd5e4e98d45d79d9f53f0b24de496d62d7992fd09a0
7
+ data.tar.gz: c906b109cc5a76d39fe06cbfcd36e84b870d8dd431bae19914d85ab8f545df9aed59579731533df552dc57707f96799126b6ea73de13c39c0a7e7278808c1027
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ bit-struct 0.14
2
+
3
+ - updated for ruby 2.0
4
+
1
5
  bit-struct 0.13.6
2
6
 
3
7
  - Fixed bug in #to_a. Thanks Michael Edgar.
@@ -1,4 +1,4 @@
1
- = BitStruct
1
+ # BitStruct #
2
2
 
3
3
  Class for packed binary data stored in ruby Strings. BitStruct accessors, generated from user declared fields, use pack/unpack to treat substrings as fields with a specified portable format.
4
4
 
@@ -37,25 +37,25 @@ Field options (specifiable as :foo => val or "foo" => val) include:
37
37
  * *fixed*: float stored as fixed-point integer, with specified scale factor
38
38
 
39
39
 
40
- == Installation
40
+ ## Installation ##
41
41
 
42
42
  For .gem:
43
43
 
44
- gem install bit-struct
44
+ gem install bit-struct
45
45
 
46
46
  For .tgz, unpack and then:
47
47
 
48
- ruby install.rb config
49
- ruby install.rb setup
50
- ruby install.rb install
48
+ ruby install.rb config
49
+ ruby install.rb setup
50
+ ruby install.rb install
51
51
 
52
- == Uses
52
+ ## Uses ##
53
53
 
54
54
  BitStruct is useful for defining packets used in network protocols. This is especially useful for raw IP--see examples/ping-recv.rb. All multibyte numeric fields are stored by default in network order.
55
55
 
56
56
  BitStruct is most efficient when your data is primarily treated as a binary string, and only secondarily treated as a data structure. (For instance, you are routing packets from one socket to another, possibly looking at one or two fields as it passes through or munging some headers.) If accessor operations are a bottleneck, a better approach is to define a class that wraps an array and uses pack/unpack when the object needs to behave like a binary string.
57
57
 
58
- == Features
58
+ ## Features ##
59
59
 
60
60
  * Extensible with user-defined field classes.
61
61
 
@@ -77,13 +77,13 @@ BitStruct is most efficient when your data is primarily treated as a binary stri
77
77
 
78
78
  * Includes tests, examples, and rdoc API documentation.
79
79
 
80
- == Limitations
80
+ ## Limitations ##
81
81
 
82
82
  * Fields that are not aligned on byte boundaries may cross no more than two bytes boundaries. (See examples/byte-bdy.rb.)
83
83
 
84
84
  * No variable length fields (except the #rest field).
85
85
 
86
- == Future plans
86
+ ## Future plans ##
87
87
 
88
88
  * Currently, the library is written in pure ruby. The implementation uses Array#pack and String#unpack calls, as well as shifting and masking in pure ruby. Future versions will optionally generate a customized C extension for better efficiency.
89
89
 
@@ -91,97 +91,99 @@ BitStruct is most efficient when your data is primarily treated as a binary stri
91
91
 
92
92
  * Remove field size and alignment limitations.
93
93
 
94
- == Example
94
+ ## Example ##
95
95
 
96
96
  An IP packet can be defined and used like this:
97
97
 
98
- require 'bit-struct'
99
-
100
- class IP < BitStruct
101
- unsigned :ip_v, 4, "Version"
102
- unsigned :ip_hl, 4, "Header length"
103
- unsigned :ip_tos, 8, "TOS"
104
- unsigned :ip_len, 16, "Length"
105
- unsigned :ip_id, 16, "ID"
106
- unsigned :ip_off, 16, "Frag offset"
107
- unsigned :ip_ttl, 8, "TTL"
108
- unsigned :ip_p, 8, "Protocol"
109
- unsigned :ip_sum, 16, "Checksum"
110
- octets :ip_src, 32, "Source addr"
111
- octets :ip_dst, 32, "Dest addr"
112
- rest :body, "Body of message"
113
-
114
- note " rest is application defined message body"
115
-
116
- initial_value.ip_v = 4
117
- initial_value.ip_hl = 5
118
- end
119
-
120
- ip = IP.new
121
- ip.ip_tos = 0
122
- ip.ip_len = 0
123
- ip.ip_id = 0
124
- ip.ip_off = 0
125
- ip.ip_ttl = 255
126
- ip.ip_p = 255
127
- ip.ip_sum = 0
128
- ip.ip_src = "192.168.1.4"
129
- ip.ip_dst = "192.168.1.255"
130
- ip.body = "This is the payload text."
131
- ip.ip_len = ip.length
132
-
133
- puts ip.inspect
134
- puts "-"*50
135
- puts ip.inspect_detailed
136
- puts "-"*50
137
- puts IP.describe
98
+ ```ruby
99
+ require 'bit-struct'
100
+
101
+ class IP < BitStruct
102
+ unsigned :ip_v, 4, "Version"
103
+ unsigned :ip_hl, 4, "Header length"
104
+ unsigned :ip_tos, 8, "TOS"
105
+ unsigned :ip_len, 16, "Length"
106
+ unsigned :ip_id, 16, "ID"
107
+ unsigned :ip_off, 16, "Frag offset"
108
+ unsigned :ip_ttl, 8, "TTL"
109
+ unsigned :ip_p, 8, "Protocol"
110
+ unsigned :ip_sum, 16, "Checksum"
111
+ octets :ip_src, 32, "Source addr"
112
+ octets :ip_dst, 32, "Dest addr"
113
+ rest :body, "Body of message"
114
+
115
+ note " rest is application defined message body"
116
+
117
+ initial_value.ip_v = 4
118
+ initial_value.ip_hl = 5
119
+ end
120
+
121
+ ip = IP.new
122
+ ip.ip_tos = 0
123
+ ip.ip_len = 0
124
+ ip.ip_id = 0
125
+ ip.ip_off = 0
126
+ ip.ip_ttl = 255
127
+ ip.ip_p = 255
128
+ ip.ip_sum = 0
129
+ ip.ip_src = "192.168.1.4"
130
+ ip.ip_dst = "192.168.1.255"
131
+ ip.body = "This is the payload text."
132
+ ip.ip_len = ip.length
133
+
134
+ puts ip.inspect
135
+ puts "-"*50
136
+ puts ip.inspect_detailed
137
+ puts "-"*50
138
+ puts IP.describe
139
+ ```
138
140
 
139
141
  (Note that you can also construct an IP packet by passing a string to new, or by passing a hash of <tt>field,value</tt> pairs, or by providing a block that is yielded the new BitStruct.)
140
142
 
141
143
  The output of this fragment is:
142
144
 
143
- #<IP ip_v=4, ip_hl=5, ip_tos=0, ip_len=45, ip_id=0, ip_off=0, ip_ttl=255, ip_p=255, ip_sum=0, ip_src="192.168.1.4", ip_dst="192.168.1.255", body="This is the payload text.">
144
- --------------------------------------------------
145
- IP:
146
- Version = 4
147
- Header length = 5
148
- TOS = 0
149
- Length = 45
150
- ID = 0
151
- Frag offset = 0
152
- TTL = 255
153
- Protocol = 255
154
- Checksum = 0
155
- Source addr = "192.168.1.4"
156
- Dest addr = "192.168.1.255"
157
- Body of message = "This is the payload text."
158
- --------------------------------------------------
159
-
160
- Description of IP Packet:
161
- byte: type name [size] description
162
- ----------------------------------------------------------------------
163
- @0: unsigned ip_v [ 4b] Version
164
- @0: unsigned ip_hl [ 4b] Header length
165
- @1: unsigned ip_tos [ 8b] TOS
166
- @2: unsigned ip_len [ 16b] Length
167
- @4: unsigned ip_id [ 16b] ID
168
- @6: unsigned ip_off [ 16b] Frag offset
169
- @8: unsigned ip_ttl [ 8b] TTL
170
- @9: unsigned ip_p [ 8b] Protocol
171
- @10: unsigned ip_sum [ 16b] Checksum
172
- @12: octets ip_src [ 32b] Source addr
173
- @16: octets ip_dst [ 32b] Dest addr
174
- rest is application defined message body
175
-
176
- == Web site
177
-
178
- The current version of this software can be found at http://redshift.sourceforge.net/bit-struct.
179
-
180
- == License
145
+ #<IP ip_v=4, ip_hl=5, ip_tos=0, ip_len=45, ip_id=0, ip_off=0, ip_ttl=255, ip_p=255, ip_sum=0, ip_src="192.168.1.4", ip_dst="192.168.1.255", body="This is the payload text.">
146
+ --------------------------------------------------
147
+ IP:
148
+ Version = 4
149
+ Header length = 5
150
+ TOS = 0
151
+ Length = 45
152
+ ID = 0
153
+ Frag offset = 0
154
+ TTL = 255
155
+ Protocol = 255
156
+ Checksum = 0
157
+ Source addr = "192.168.1.4"
158
+ Dest addr = "192.168.1.255"
159
+ Body of message = "This is the payload text."
160
+ --------------------------------------------------
161
+
162
+ Description of IP Packet:
163
+ byte: type name [size] description
164
+ ----------------------------------------------------------------------
165
+ @0: unsigned ip_v [ 4b] Version
166
+ @0: unsigned ip_hl [ 4b] Header length
167
+ @1: unsigned ip_tos [ 8b] TOS
168
+ @2: unsigned ip_len [ 16b] Length
169
+ @4: unsigned ip_id [ 16b] ID
170
+ @6: unsigned ip_off [ 16b] Frag offset
171
+ @8: unsigned ip_ttl [ 8b] TTL
172
+ @9: unsigned ip_p [ 8b] Protocol
173
+ @10: unsigned ip_sum [ 16b] Checksum
174
+ @12: octets ip_src [ 32b] Source addr
175
+ @16: octets ip_dst [ 32b] Dest addr
176
+ rest is application defined message body
177
+
178
+ ## Web site ##
179
+
180
+ The current version of this software can be found at https://github.com/vjoel/bit-struct.
181
+
182
+ ## License ##
181
183
 
182
184
  This software is distributed under the Ruby license. See http://www.ruby-lang.org.
183
185
 
184
- == Author
186
+ ## Author ##
185
187
 
186
188
  Joel VanderWerf, mailto:vjoel@users.sourceforge.net
187
- Copyright (c) 2005-2009, Joel VanderWerf.
189
+ Copyright (c) 2005-2013, Joel VanderWerf.
@@ -89,8 +89,8 @@ class BitStruct < String
89
89
  val = obj.send(name)
90
90
  str =
91
91
  begin
92
- val.inspect(opts)
93
- rescue ArgumentError # assume: "wrong number of arguments (1 for 0)"
92
+ val.inspect_with_options(opts)
93
+ rescue NoMethodError
94
94
  val.inspect
95
95
  end
96
96
  (f=@format) ? (f % str) : str
@@ -487,7 +487,7 @@ class BitStruct < String
487
487
  }
488
488
 
489
489
  # A standard inspect method which does not add newlines.
490
- def inspect(opts = DEFAULT_INSPECT_OPTS)
490
+ def inspect_with_options(opts = DEFAULT_INSPECT_OPTS)
491
491
  field_format = opts[:field_format]
492
492
  field_name_meth = opts[:field_name_meth]
493
493
 
@@ -511,6 +511,8 @@ class BitStruct < String
511
511
  end
512
512
  end
513
513
 
514
+ alias inspect inspect_with_options
515
+
514
516
  # A more visually appealing inspect method that puts each field/value on
515
517
  # a separate line. Very useful when output is scrolling by on a screen.
516
518
  #
@@ -153,7 +153,7 @@ class BitStruct::Vector < String
153
153
  end
154
154
  end
155
155
 
156
- def inspect(opts = BitStruct::DEFAULT_INSPECT_OPTS)
156
+ def inspect_with_options(opts = BitStruct::DEFAULT_INSPECT_OPTS)
157
157
  if opts[:include_class]
158
158
  opts = opts.dup
159
159
  opts[:include_class] = false
@@ -166,6 +166,8 @@ class BitStruct::Vector < String
166
166
  lb, rb = opts[:brackets]
167
167
  [lb, s, rb].join
168
168
  end
169
+
170
+ alias inspect inspect_with_options
169
171
 
170
172
  def inspect_detailed
171
173
  inspect(BitStruct::DETAILED_INSPECT_OPTS)
@@ -27,8 +27,27 @@ class BitStruct
27
27
  end
28
28
  end
29
29
 
30
+ elsif RUBY_VERSION =~ /^2\./
31
+ def encode_with coder
32
+ yaml_fields = fields.select {|field| field.inspectable?}
33
+ props = yaml_fields.map {|f| f.name.to_s}
34
+ if (rest_field = self.class.rest_field)
35
+ props << rest_field.name.to_s
36
+ end
37
+ props.each do |prop|
38
+ coder[prop] = send(prop)
39
+ end
40
+ end
41
+
42
+ def init_with coder
43
+ self << self.class.initial_value
44
+ coder.map.each do |k, v|
45
+ send("#{k}=", v)
46
+ end
47
+ end
48
+
30
49
  else
31
- yaml_as "tag:path.berkeley.edu,2006:bitstruct"
50
+ yaml_as "tag:github.com:vjoel/bit-struct"
32
51
 
33
52
  def to_yaml_properties # :nodoc:
34
53
  yaml_fields = fields.select {|field| field.inspectable?}
metadata CHANGED
@@ -1,127 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bit-struct
3
- version: !ruby/object:Gem::Version
4
- version: 0.13.6
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.14'
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Joel VanderWerf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-07-27 00:00:00 -07:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: bones
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 2.5.1
24
- version:
25
- description: |
26
- Library for packed binary data stored in ruby Strings. Useful for accessing fields in network packets and binary files.
27
-
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Library for packed binary data stored in ruby Strings. Useful for accessing
14
+ fields in network packets and binary files.
28
15
  email: vjoel@users.sourceforge.net
29
16
  executables: []
30
-
31
17
  extensions: []
32
-
33
- extra_rdoc_files:
18
+ extra_rdoc_files:
34
19
  - History.txt
35
- - README.txt
36
- files:
37
- - .gitignore
20
+ - README.md
21
+ files:
38
22
  - History.txt
39
- - README.txt
40
- - Rakefile
41
- - TODO
42
- - examples/ara-player-data.rb
43
- - examples/bignum.rb
23
+ - README.md
24
+ - lib/bit-struct/pad-field.rb
25
+ - lib/bit-struct/octet-field.rb
26
+ - lib/bit-struct/fields.rb
27
+ - lib/bit-struct/hex-octet-field.rb
28
+ - lib/bit-struct/yaml.rb
29
+ - lib/bit-struct/nested-field.rb
30
+ - lib/bit-struct/char-field.rb
31
+ - lib/bit-struct/unsigned-field.rb
32
+ - lib/bit-struct/vector.rb
33
+ - lib/bit-struct/bit-struct.rb
34
+ - lib/bit-struct/float-field.rb
35
+ - lib/bit-struct/vector-field.rb
36
+ - lib/bit-struct/text-field.rb
37
+ - lib/bit-struct/signed-field.rb
38
+ - lib/bit-struct.rb
44
39
  - examples/bits.rb
45
- - examples/byte-bdy.rb
40
+ - examples/nested-block.rb
41
+ - examples/raw.rb
42
+ - examples/md.rb
46
43
  - examples/field-ripper.rb
44
+ - examples/ping-recv.rb
45
+ - examples/switch-endian.rb
46
+ - examples/pad.rb
47
+ - examples/ara-player-data.rb
48
+ - examples/rest.rb
47
49
  - examples/fixed-point.rb
48
- - examples/ip.rb
49
50
  - examples/longlong.rb
50
- - examples/md.rb
51
- - examples/modular-def.rb
52
- - examples/native.rb
53
- - examples/nested-block.rb
51
+ - examples/vector.rb
52
+ - examples/byte-bdy.rb
54
53
  - examples/nested.rb
55
- - examples/pad.rb
56
- - examples/ping-recv.rb
57
54
  - examples/ping.rb
55
+ - examples/ip.rb
56
+ - examples/modular-def.rb
57
+ - examples/native.rb
58
58
  - examples/player-data.rb
59
- - examples/raw.rb
60
- - examples/rest.rb
61
- - examples/switch-endian.rb
62
- - examples/vector.rb
63
- - install.rb
64
- - lib/bit-struct.rb
65
- - lib/bit-struct/bit-struct.rb
66
- - lib/bit-struct/char-field.rb
67
- - lib/bit-struct/fields.rb
68
- - lib/bit-struct/float-field.rb
69
- - lib/bit-struct/hex-octet-field.rb
70
- - lib/bit-struct/nested-field.rb
71
- - lib/bit-struct/octet-field.rb
72
- - lib/bit-struct/pad-field.rb
73
- - lib/bit-struct/signed-field.rb
74
- - lib/bit-struct/text-field.rb
75
- - lib/bit-struct/unsigned-field.rb
76
- - lib/bit-struct/vector-field.rb
77
- - lib/bit-struct/vector.rb
78
- - lib/bit-struct/yaml.rb
79
- - tasks/ann.rake
80
- - tasks/bones.rake
81
- - tasks/gem.rake
82
- - tasks/git.rake
83
- - tasks/notes.rake
84
- - tasks/post_load.rake
85
- - tasks/rdoc.rake
86
- - tasks/rubyforge.rake
87
- - tasks/setup.rb
88
- - tasks/spec.rake
89
- - tasks/svn.rake
90
- - tasks/test.rake
91
- - tasks/zentest.rake
59
+ - examples/bignum.rb
60
+ - test/test.rb
92
61
  - test/test-endian.rb
93
62
  - test/test-vector.rb
94
- - test/test.rb
95
- has_rdoc: true
96
- homepage: http://rubyforge.org/projects/bit-struct/
63
+ homepage: https://github.com/vjoel/bit-struct
97
64
  licenses: []
98
-
65
+ metadata: {}
99
66
  post_install_message:
100
- rdoc_options:
67
+ rdoc_options:
68
+ - --quiet
69
+ - --line-numbers
70
+ - --inline-source
71
+ - --title
72
+ - BitStruct
101
73
  - --main
102
- - README.txt
103
- require_paths:
74
+ - README.md
75
+ require_paths:
104
76
  - lib
105
- required_ruby_version: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: "0"
110
- version:
111
- required_rubygems_version: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: "0"
116
- version:
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
117
87
  requirements: []
118
-
119
88
  rubyforge_project: bit-struct
120
- rubygems_version: 1.3.5
89
+ rubygems_version: 2.0.3
121
90
  signing_key:
122
- specification_version: 3
91
+ specification_version: 4
123
92
  summary: Library for packed binary data stored in ruby Strings
124
- test_files:
125
- - test/test-endian.rb
126
- - test/test.rb
127
- - test/test-vector.rb
93
+ test_files: []
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- *.bck
2
- pkg/*
3
- doc/*
data/Rakefile DELETED
@@ -1,38 +0,0 @@
1
- # Look in the tasks/setup.rb file for the various options that can be
2
- # configured in this Rakefile. The .rake files in the tasks directory
3
- # are where the options are used.
4
-
5
- begin
6
- require 'bones'
7
- Bones.setup
8
- rescue LoadError
9
- begin
10
- load 'tasks/setup.rb'
11
- rescue LoadError
12
- raise RuntimeError, '### please install the "bones" gem ###'
13
- end
14
- end
15
-
16
- ensure_in_path 'lib'
17
- require 'bit-struct/bit-struct'
18
-
19
- #task :default => 'spec:run'
20
-
21
- PROJ.name = 'bit-struct'
22
- PROJ.authors = 'Joel VanderWerf'
23
- PROJ.email = 'vjoel@users.sourceforge.net'
24
- PROJ.url = 'http://rubyforge.org/projects/bit-struct/'
25
- PROJ.version = BitStruct::VERSION
26
- PROJ.rubyforge.name = 'bit-struct'
27
- PROJ.summary = "Library for packed binary data stored in ruby Strings"
28
- PROJ.description = <<END
29
- Library for packed binary data stored in ruby Strings. Useful for accessing fields in network packets and binary files.
30
- END
31
- PROJ.changes = File.read(PROJ.history_file)[/^\w.*?(?=^\w)/m]
32
-
33
- PROJ.spec.opts << '--color'
34
- PROJ.test.files = Dir["test/*.rb"]
35
-
36
- task :release => ["gem:release", "doc:release"]
37
-
38
- # EOF
data/TODO DELETED
@@ -1,20 +0,0 @@
1
- rest :name, :terminator => ...
2
-
3
- easy way to define wrappers
4
-
5
- generate C code from bit-struct spec?
6
-
7
- write extension to extract and insert bit-fields, and use that instead
8
- of pack/unpack
9
-
10
- variable-length embedded fields, with referenced length field
11
-
12
- terminated arrays?
13
-
14
- use with mmap; in general: bit struct that references a position in another string or string-like object (e.g. a Mmap).
15
-
16
- use require 'ipaddr'?
17
-
18
- See ideas in
19
-
20
- http://www.notwork.org/~gotoken/ruby/p/as-is/pack.rb