Skip to content

Commit

Permalink
added vector stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel VanderWerf committed Jul 5, 2009
1 parent 0d7d906 commit a13cd73
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 11 deletions.
17 changes: 17 additions & 0 deletions .bnsignore
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*.bck
pkg/*
File renamed without changes.
Empty file removed README
Empty file.
4 changes: 2 additions & 2 deletions intro.txt → README.txt
Expand Up @@ -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.

Expand All @@ -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.
34 changes: 34 additions & 0 deletions Rakefile
@@ -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
5 changes: 5 additions & 0 deletions TODO
@@ -1,3 +1,8 @@
website:

scp doc/ vjoel@rubyforge.org:/var/www/gforge-projects/bit-struct/


easy way to define wrappers


Expand Down
30 changes: 30 additions & 0 deletions examples/longlong.rb
@@ -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
13 changes: 6 additions & 7 deletions lib/bit-struct/vector-field.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions mkrdoc

This file was deleted.

0 comments on commit a13cd73

Please sign in to comment.