bit-struct 0.13.2 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +2 -0
 - data/Rakefile +2 -0
 - data/TODO +2 -0
 - data/examples/vector.rb +2 -2
 - data/lib/bit-struct/bit-struct.rb +1 -1
 - data/lib/bit-struct/fields.rb +6 -2
 - metadata +1 -2
 - data/TODO-ALSO +0 -54
 
    
        data/History.txt
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    
    
        data/TODO
    CHANGED
    
    
    
        data/examples/vector.rb
    CHANGED
    
    | 
         @@ -74,10 +74,10 @@ class Packet < BitStruct 
     | 
|
| 
       74 
74 
     | 
    
         
             
              unsigned :stuff, 32, "whatever"
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
       76 
76 
     | 
    
         
             
              # Using the Vec class defined above
         
     | 
| 
       77 
     | 
    
         
            -
              vector  :v, Vec, "a vector",  
     | 
| 
      
 77 
     | 
    
         
            +
              vector  :v, Vec, "a vector", 5
         
     | 
| 
       78 
78 
     | 
    
         | 
| 
       79 
79 
     | 
    
         
             
              # equivalently, using an anonymous subclass of BitStruct::Vector
         
     | 
| 
       80 
     | 
    
         
            -
              vector :v2, "a vector 2",  
     | 
| 
      
 80 
     | 
    
         
            +
              vector :v2, "a vector 2", 5 do
         
     | 
| 
       81 
81 
     | 
    
         
             
                unsigned :x,  16
         
     | 
| 
       82 
82 
     | 
    
         
             
                signed   :y,  32
         
     | 
| 
       83 
83 
     | 
    
         
             
              end
         
     | 
    
        data/lib/bit-struct/fields.rb
    CHANGED
    
    | 
         @@ -233,6 +233,8 @@ class BitStruct 
     | 
|
| 
       233 
233 
     | 
    
         
             
                #
         
     | 
| 
       234 
234 
     | 
    
         
             
                # If a string is provided, use it for the display_name.
         
     | 
| 
       235 
235 
     | 
    
         
             
                # If a hash is provided, use it for options.
         
     | 
| 
      
 236 
     | 
    
         
            +
                # If a number is provided, use it for length (equivalent to using the
         
     | 
| 
      
 237 
     | 
    
         
            +
                # :length option).
         
     | 
| 
       236 
238 
     | 
    
         
             
                #
         
     | 
| 
       237 
239 
     | 
    
         
             
                # WARNING: the accessors have COPY semantics, not reference. When you call a
         
     | 
| 
       238 
240 
     | 
    
         
             
                # reader method to get the vector structure, you get a *copy* of that data.
         
     | 
| 
         @@ -274,9 +276,11 @@ class BitStruct 
     | 
|
| 
       274 
276 
     | 
    
         | 
| 
       275 
277 
     | 
    
         
             
                  vector_class.default_options default_options
         
     | 
| 
       276 
278 
     | 
    
         | 
| 
       277 
     | 
    
         
            -
                  length = opts[:length]  
     | 
| 
      
 279 
     | 
    
         
            +
                  length = opts[:length] || rest.grep(Integer).first
         
     | 
| 
      
 280 
     | 
    
         
            +
                    ## what about :length => :lenfield
         
     | 
| 
       278 
281 
     | 
    
         
             
                  unless length
         
     | 
| 
       279 
     | 
    
         
            -
                    raise ArgumentError, 
     | 
| 
      
 282 
     | 
    
         
            +
                    raise ArgumentError,
         
     | 
| 
      
 283 
     | 
    
         
            +
                      "Must provide length as argument N or as option :length => N"
         
     | 
| 
       280 
284 
     | 
    
         
             
                  end
         
     | 
| 
       281 
285 
     | 
    
         | 
| 
       282 
286 
     | 
    
         
             
                  opts[:default] ||= vector_class.new(length) ## nil if variable length
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bit-struct
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.13. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.13.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Joel VanderWerf
         
     | 
| 
         @@ -41,7 +41,6 @@ files: 
     | 
|
| 
       41 
41 
     | 
    
         
             
            - README.txt
         
     | 
| 
       42 
42 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       43 
43 
     | 
    
         
             
            - TODO
         
     | 
| 
       44 
     | 
    
         
            -
            - TODO-ALSO
         
     | 
| 
       45 
44 
     | 
    
         
             
            - examples/ara-player-data.rb
         
     | 
| 
       46 
45 
     | 
    
         
             
            - examples/bignum.rb
         
     | 
| 
       47 
46 
     | 
    
         
             
            - examples/bits.rb
         
     | 
    
        data/TODO-ALSO
    DELETED
    
    | 
         @@ -1,54 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            rest :name, :terminator => ...
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            > * Is explicit :length for vector necessary?
         
     | 
| 
       4 
     | 
    
         
            -
            > 
         
     | 
| 
       5 
     | 
    
         
            -
            >   class Tag < BitStruct
         
     | 
| 
       6 
     | 
    
         
            -
            >     signed  :flags, 32
         
     | 
| 
       7 
     | 
    
         
            -
            >     vector  :axis, Vec, :length => 3
         
     | 
| 
       8 
     | 
    
         
            -
            >   end
         
     | 
| 
       9 
     | 
    
         
            -
            > 
         
     | 
| 
       10 
     | 
    
         
            -
            > compared to
         
     | 
| 
       11 
     | 
    
         
            -
            > 
         
     | 
| 
       12 
     | 
    
         
            -
            >   class Tag < BitStruct
         
     | 
| 
       13 
     | 
    
         
            -
            >     signed  :flags, 32
         
     | 
| 
       14 
     | 
    
         
            -
            >     vector  :axis, Vec, 3
         
     | 
| 
       15 
     | 
    
         
            -
            >   end
         
     | 
| 
       16 
     | 
    
         
            -
            > 
         
     | 
| 
       17 
     | 
    
         
            -
            > Or am I missing any ambiguities because of the simple cases?
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            Nothing ambiguous, I just get giddy when there are too many positional args. But since length is required, it does make sense to pass it as a positional arg. I'll change that...
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            > * Allow length not only in bits, but also bytes?
         
     | 
| 
       22 
     | 
    
         
            -
            > 
         
     | 
| 
       23 
     | 
    
         
            -
            > In my cases I've never encountered a situation where I needed a member
         
     | 
| 
       24 
     | 
    
         
            -
            > of a structure to represent anything which is not on a byte boundary.
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            Sigh, if only life we always like that. There's a reason I call the library _bit_-struct :)
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            > All my signed and unsigned int have to read "32" (32bit, 4bytes) all
         
     | 
| 
       29 
     | 
    
         
            -
            > over the place. For strings I'm writing "64*8" for string with 64
         
     | 
| 
       30 
     | 
    
         
            -
            > characters.
         
     | 
| 
       31 
     | 
    
         
            -
            > 
         
     | 
| 
       32 
     | 
    
         
            -
            > How about a new default_option :granularity which is "1" by default.
         
     | 
| 
       33 
     | 
    
         
            -
            > When set to "8", every specified length (except for vector ...) is
         
     | 
| 
       34 
     | 
    
         
            -
            > multiplied by that factor before used?
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
            Hm, will think about that. I wish I could define Fixnum#bytes, but only in the context of field declarations in a BitStruct subclass.
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
            I don't like granularity because it's really only meaningful if the value is 1 or 8. Perhaps :granularity => :bit, or :granularity => :byte. But I still don't like an option that you have to keep in mind to understand whether
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              char :x, 80
         
     | 
| 
       41 
     | 
    
         
            -
              
         
     | 
| 
       42 
     | 
    
         
            -
            is 8 or 80 chars. It's too much context sensitivity.
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
            What about
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              signed :x, bytes(4)
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
            Is that too clunky? It would be trivial to implement...
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
            > * Why "vector" and not just "array"?
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
            For consistency with things like NArray, which has Vector, Matrix, and Array classes, where vectors are essentially one-dim arrays.
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
            Also, "array" might lead to confusion with ruby arrays.
         
     |