Permalink
Browse files

added vector stuff

  • Loading branch information...
1 parent 0d7d906 commit a13cd735e380f84aed5ed7b5090e0c8171a5ac0d Joel VanderWerf committed Jul 5, 2009
Showing with 96 additions and 11 deletions.
  1. +17 −0 .bnsignore
  2. +2 −0 .gitignore
  3. 0 RELEASE-NOTES → History.txt
  4. 0 README
  5. +2 −2 intro.txt → README.txt
  6. +34 −0 Rakefile
  7. +5 −0 TODO
  8. +30 −0 examples/longlong.rb
  9. +6 −7 lib/bit-struct/vector-field.rb
  10. +0 −2 mkrdoc
View
@@ -0,0 +1,17 @@
+# The list of files that should be ignored by Mr Bones.
+# Lines that start with '#' are comments.
+#
+# A .gitignore file can be used instead by setting it as the ignore
+# file in your Rakefile:
+#
+# PROJ.ignore_file = '.gitignore'
+#
+# For a project with a C extension, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
+announcement.txt
+coverage
+doc
+pkg
+*.bck
View
@@ -0,0 +1,2 @@
+*.bck
+pkg/*
File renamed without changes.
View
0 README
No changes.
View
@@ -169,7 +169,7 @@ The output of this fragment is:
== Version
-bit-struct 0.10
+bit-struct 0.12
The current version of this software can be found at http://redshift.sourceforge.net/bit-struct.
@@ -180,4 +180,4 @@ This software is distributed under the Ruby license. See http://www.ruby-lang.or
== Author
Joel VanderWerf, mailto:vjoel@users.sourceforge.net
-Copyright (c) 2005-2007, Joel VanderWerf.
+Copyright (c) 2005-2009, Joel VanderWerf.
View
@@ -0,0 +1,34 @@
+# Look in the tasks/setup.rb file for the various options that can be
+# configured in this Rakefile. The .rake files in the tasks directory
+# are where the options are used.
+
+begin
+ require 'bones'
+ Bones.setup
+rescue LoadError
+ begin
+ load 'tasks/setup.rb'
+ rescue LoadError
+ raise RuntimeError, '### please install the "bones" gem ###'
+ end
+end
+
+ensure_in_path 'lib'
+###require 'bit-struct'
+
+task :default => 'spec:run'
+
+PROJ.name = 'bit-struct'
+PROJ.authors = 'Joel VanderWerf'
+PROJ.email = 'vjoel@users.sourceforge.net'
+PROJ.url = 'http://rubyforge.org/projects/bit-struct/'
+PROJ.version = "0.12" ###BitStruct::VERSION
+PROJ.rubyforge.name = 'bit-struct'
+PROJ.summary = "Library for packed binary data stored in ruby Strings"
+PROJ.description = <<END
+Library for packed binary data stored in ruby Strings. Useful for accessing fields in network packets and binary files.
+END
+
+PROJ.spec.opts << '--color'
+
+# EOF
View
5 TODO
@@ -1,3 +1,8 @@
+website:
+
+ scp doc/ vjoel@rubyforge.org:/var/www/gforge-projects/bit-struct/
+
+
easy way to define wrappers
View
@@ -0,0 +1,30 @@
+require 'bit-struct'
+
+class MyPacket < BitStruct
+ unsigned :x, 8*8, "The x field", :endian => :network
+ # :network is the default, and it's the same as :big
+ unsigned :y, 8*8, "The y field", :endian => :little
+end
+
+pkt = MyPacket.new
+pkt.x = 59843759843759843
+pkt.y = 59843759843759843
+
+p pkt.x # 59843759843759843
+p pkt.y # 59843759843759843
+
+p pkt
+# #<MyPacket x=59843759843759843, y=59843759843759843>
+p pkt.to_s
+# "\000\324\233\225\037\202\326\343\343\326\202\037\225\233\324\000"
+
+puts pkt.inspect_detailed
+# MyPacket:
+# The x field = 59843759843759843
+# The y field = 59843759843759843
+
+puts MyPacket.describe
+# byte: type name [size] description
+# ----------------------------------------------------------------------
+# @0: unsigned x [ 8B] The x field
+# @8: unsigned y [ 8B] The y field
@@ -4,24 +4,25 @@ class BitStruct
# Class for embedding a BitStruct::Vector as a field within a BitStruct.
# Declared with BitStruct.vector.
class VectorField < Field
- def initialize(*args)
- super
- end
-
# Used in describe.
def self.class_name
@class_name ||= "vector"
end
+ # Used in describe.
def class_name
@class_name ||= vector_class.name[/\w+$/]
end
+ # Returns the subclass of Vector that is used to manage the value of this
+ # field. If the class was specified in the BitStruct.vector declaration,
+ # #vector_class will return it, otherwise it will be an anonymous class
+ # (which you can assign to a constant to make nonymous ;).
def vector_class
@vector_class ||= options[:vector_class] || options["vector_class"]
end
- def describe opts
+ def describe opts # :nodoc:
if opts[:expand]
opts = opts.dup
opts[:byte_offset] = offset / 8
@@ -78,8 +79,6 @@ class << self
# Define a vector field in the current subclass of BitStruct,
# with the given _name_.
#
- # In _rest_:
- #
# If a class is provided, use it for the Vector class, otherwise
# the block must define the entry fields. The two forms looks like
# this:
View
2 mkrdoc
@@ -1,2 +0,0 @@
-rdoc $* -m intro.txt -o doc -t 'bit-struct' \
- intro.txt lib/**/*.rb README RELEASE-NOTES

0 comments on commit a13cd73

Please sign in to comment.