Sha256: 40b83833ccc8f55a9de6847e121e0a3356ed88de796870aa8e9f284da36bf454

Contents?: true

Size: 477 Bytes

Versions: 7

Compression:

Stored size: 477 Bytes

Contents

require 'bit_struct/field'

module BitStruct

  class UnsignedField < Field

    def initialize( name, length, description = nil )
      super name, length, description
    end

    def read( slicer )
      slicer.get_bytes.inject( 0 ) { |r,b| ( r << 8 ) + b }
    end

    def write( slicer, new_value )
      bytes = []
      while new_value > 0
        bytes.insert 0, ( new_value & 0xFF )
        new_value >>= 8
      end
      slicer.set_bytes bytes
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
BitStructEx-0.0.54 src/ruby/bit_struct/unsigned.rb
BitStructEx-0.0.85 src/bit_struct/unsigned.rb
BitStructEx-0.0.86 src/bit_struct/unsigned.rb
BitStructEx-0.0.91 src/bit_struct/unsigned.rb
BitStructEx-0.0.64 src/ruby/bit_struct/unsigned.rb
BitStructEx-0.0.65 src/ruby/bit_struct/unsigned.rb
BitStructEx-0.0.74 src/bit_struct/unsigned.rb