Class: Cassandra::DynamicComposite

### Home Classes Methods

### In Files

- lib/cassandra/dynamic_composite.rb

### Parent

Cassandra::Composite

### Methods

- ::new
- #fast_unpack
- #pack

### Files

- CHANGELOG
- LICENSE
- Makefile

### Class/Module Index

Quicksearch

- Cassandra
- Cassandra::Batch
- Cassandra::ColumnFamily
- Cassandra::Comparable
- Cassandra::Composite
- Cassandra::Consistency
- Cassandra::Constants
- Cassandra::DynamicComposite
- Cassandra::Helpers
- Cassandra::Keyspace
- Cassandra::Long
- Cassandra::Mock
- CassandraThrift
- CassandraThrift::Cassandra
- CassandraThrift::Cassandra::Client
- SimpleUUID
- SimpleUUID::UUID
- Array
- Time

No matching classes.

# Cassandra::DynamicComposite

### Attributes

types[RW]

### Public Class Methods

new(*parts) click to toggle source

    # File lib/cassandra/dynamic_composite.rb, line 5
    def initialize(*parts)
      return if parts.empty?

      options = {}
      if parts.last.is_a?(Hash)
        options = parts.pop
      end
      @column_slice = options[:slice]
      raise ArgumentError if @column_slice != nil && ![:before, :after].include?(@column_slice)

      if parts.length == 1 && parts[0].instance_of?(self.class)
        @column_slice = parts[0].column_slice
        @parts = parts[0].parts
        @types = parts[0].types
      elsif parts.length == 1 && parts[0].instance_of?(String) && @column_slice.nil? && try_packed_composite(parts[0])
        @hash = parts[0].hash
      else
        @types, @parts = parts.transpose
      end
    end

### Public Instance Methods

fast_unpack(packed_string) click to toggle source

    # File lib/cassandra/dynamic_composite.rb, line 47
    def fast_unpack(packed_string)
      @hash = packed_string.hash

      @types = []
      @parts = []

      offset = 0
      length = nil
      while offset < packed_string.length
        if packed_string[offset].ord & 0x80 != 0
          @types << packed_string[offset+1]
          offset += 2
        else
          length = packed_string.slice(offset, 2).unpack('n')[0]
          offset += 2
          @types << packed_string.slice(offset, length)
          offset += length
        end
        length = packed_string.slice(offset, 2).unpack('n')[0]
        offset += 2
        @parts << packed_string.slice(offset, length)
        offset += length + 1
      end

      @column_slice = :after if packed_string[-1] == "\x01"
      @column_slice = :before if packed_string[-1] == "\xFF"
    end

pack() click to toggle source

    # File lib/cassandra/dynamic_composite.rb, line 26
    def pack
      packed_parts = @parts.map do |part|
        [part.length].pack('n') + part + "\x00"
      end

      if @column_slice
        part = @parts[-1]
        packed_parts[-1] = [part.length].pack('n') + part + slice_end_of_component
      end

      packed_types = @types.map do |type|
        if type.length == 1
          [0x8000 | type[0].ord].pack('n')
        else
          [type.length].pack('n') + type
        end
      end

      return packed_types.zip(packed_parts).flatten.join('')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.