Class: AMQ::Protocol::Table

### Home Classes Methods

### In Files

- lib/amq/protocol/table.rb

### Parent

Object

### Namespace

- CLASS AMQ::Protocol::Table::InvalidTableError

### Methods

- ::decode
- ::decode_table_key
- ::encode
- ::hash_size
- ::length

### Included Modules

- AMQ::Protocol::TypeConstants

### Class/Module Index

Quicksearch

- AMQ
- AMQ::BitSet
- AMQ::Endianness
- AMQ::Hacks
- AMQ::IntAllocator
- AMQ::Pack
- AMQ::Protocol
- AMQ::Protocol::AccessRefused
- AMQ::Protocol::BadResponseError
- AMQ::Protocol::Basic
- AMQ::Protocol::Basic::Ack
- AMQ::Protocol::Basic::Cancel
- AMQ::Protocol::Basic::CancelOk
- AMQ::Protocol::Basic::Consume
- AMQ::Protocol::Basic::ConsumeOk
- AMQ::Protocol::Basic::Deliver
- AMQ::Protocol::Basic::Get
- AMQ::Protocol::Basic::GetEmpty
- AMQ::Protocol::Basic::GetOk
- AMQ::Protocol::Basic::Nack
- AMQ::Protocol::Basic::Publish
- AMQ::Protocol::Basic::Qos
- AMQ::Protocol::Basic::QosOk
- AMQ::Protocol::Basic::Recover
- AMQ::Protocol::Basic::RecoverAsync
- AMQ::Protocol::Basic::RecoverOk
- AMQ::Protocol::Basic::Reject
- AMQ::Protocol::Basic::Return
- AMQ::Protocol::BodyFrame
- AMQ::Protocol::Channel
- AMQ::Protocol::Channel::Close
- AMQ::Protocol::Channel::CloseOk
- AMQ::Protocol::Channel::Flow
- AMQ::Protocol::Channel::FlowOk
- AMQ::Protocol::Channel::Open
- AMQ::Protocol::Channel::OpenOk
- AMQ::Protocol::ChannelError
- AMQ::Protocol::Class
- AMQ::Protocol::CommandInvalid
- AMQ::Protocol::Confirm
- AMQ::Protocol::Confirm::Select
- AMQ::Protocol::Confirm::SelectOk
- AMQ::Protocol::Connection
- AMQ::Protocol::Connection::Blocked
- AMQ::Protocol::Connection::Close
- AMQ::Protocol::Connection::CloseOk
- AMQ::Protocol::Connection::Open
- AMQ::Protocol::Connection::OpenOk
- AMQ::Protocol::Connection::Secure
- AMQ::Protocol::Connection::SecureOk
- AMQ::Protocol::Connection::Start
- AMQ::Protocol::Connection::StartOk
- AMQ::Protocol::Connection::Tune
- AMQ::Protocol::Connection::TuneOk
- AMQ::Protocol::Connection::Unblocked
- AMQ::Protocol::ConnectionForced
- AMQ::Protocol::ContentTooLarge
- AMQ::Protocol::EmptyResponseError
- AMQ::Protocol::Error
- AMQ::Protocol::Exchange
- AMQ::Protocol::Exchange::Bind
- AMQ::Protocol::Exchange::BindOk
- AMQ::Protocol::Exchange::Declare
- AMQ::Protocol::Exchange::DeclareOk
- AMQ::Protocol::Exchange::Delete
- AMQ::Protocol::Exchange::DeleteOk
- AMQ::Protocol::Exchange::Unbind
- AMQ::Protocol::Exchange::UnbindOk
- AMQ::Protocol::Float32Bit
- AMQ::Protocol::Frame
- AMQ::Protocol::FrameError
- AMQ::Protocol::FrameSubclass
- AMQ::Protocol::FrameTypeError
- AMQ::Protocol::HardError
- AMQ::Protocol::HeaderFrame
- AMQ::Protocol::HeartbeatFrame
- AMQ::Protocol::InternalError
- AMQ::Protocol::InvalidPath
- AMQ::Protocol::Method
- AMQ::Protocol::MethodFrame
- AMQ::Protocol::NoConsumers
- AMQ::Protocol::NoRoute
- AMQ::Protocol::NotAllowed
- AMQ::Protocol::NotFound
- AMQ::Protocol::NotImplemented
- AMQ::Protocol::PreconditionFailed
- AMQ::Protocol::Queue
- AMQ::Protocol::Queue::Bind
- AMQ::Protocol::Queue::BindOk
- AMQ::Protocol::Queue::Declare
- AMQ::Protocol::Queue::DeclareOk
- AMQ::Protocol::Queue::Delete
- AMQ::Protocol::Queue::DeleteOk
- AMQ::Protocol::Queue::Purge
- AMQ::Protocol::Queue::PurgeOk
- AMQ::Protocol::Queue::Unbind
- AMQ::Protocol::Queue::UnbindOk
- AMQ::Protocol::ResourceError
- AMQ::Protocol::ResourceLocked
- AMQ::Protocol::SoftError
- AMQ::Protocol::SyntaxError
- AMQ::Protocol::Table
- AMQ::Protocol::Table::InvalidTableError
- AMQ::Protocol::TableValueDecoder
- AMQ::Protocol::TableValueEncoder
- AMQ::Protocol::Tx
- AMQ::Protocol::Tx::Commit
- AMQ::Protocol::Tx::CommitOk
- AMQ::Protocol::Tx::Rollback
- AMQ::Protocol::Tx::RollbackOk
- AMQ::Protocol::Tx::Select
- AMQ::Protocol::Tx::SelectOk
- AMQ::Protocol::TypeConstants
- AMQ::Protocol::UnexpectedFrame
- AMQ::URI

No matching classes.

# AMQ::Protocol::Table

### Public Class Methods

decode(data) click to toggle source

    # File lib/amq/protocol/table.rb, line 53
    def self.decode(data)
      table        = Hash.new
      table_length = data.unpack(PACK_UINT32).first

      return table if table_length.zero?

      offset       = 4
      while offset <= table_length
        key, offset  = decode_table_key(data, offset)
        type, offset = TableValueDecoder.decode_value_type(data, offset)

        table[key] = case type
                     when TYPE_STRING
                       v, offset = TableValueDecoder.decode_string(data, offset)
                       v
                     when TYPE_INTEGER
                       v, offset = TableValueDecoder.decode_integer(data, offset)
                       v
                     when TYPE_DECIMAL
                       v, offset = TableValueDecoder.decode_big_decimal(data, offset)
                       v
                     when TYPE_TIME
                       v, offset = TableValueDecoder.decode_time(data, offset)
                       v
                     when TYPE_HASH
                       v, offset = TableValueDecoder.decode_hash(data, offset)
                       v
                     when TYPE_BOOLEAN
                       v, offset = TableValueDecoder.decode_boolean(data, offset)
                       v
                    when TYPE_BYTE  then
                       v, offset = TableValueDecoder.decode_byte(data, offset)
                       v
                     when TYPE_SIGNED_16BIT then
                       v, offset = TableValueDecoder.decode_short(data, offset)
                       v
                     when TYPE_SIGNED_64BIT then
                       v, offset = TableValueDecoder.decode_long(data, offset)
                       v
                     when TYPE_32BIT_FLOAT then
                       v, offset = TableValueDecoder.decode_32bit_float(data, offset)
                       v
                     when TYPE_64BIT_FLOAT then
                       v, offset = TableValueDecoder.decode_64bit_float(data, offset)
                       v
                     when TYPE_VOID
                       nil
                     when TYPE_ARRAY
                       v, offset = TableValueDecoder.decode_array(data, offset)
                       v
                     else
                       raise ArgumentError, "Not a valid type: #{type.inspect}\nData: #{data.inspect}\nUnprocessed data: #{data[offset..-1].inspect}\nOffset: #{offset}\nTotal size: #{table_length}\nProcessed data: #{table.inspect}"
                     end
      end

      table
    end

decode_table_key(data, offset) click to toggle source

    # File lib/amq/protocol/table.rb, line 128
    def self.decode_table_key(data, offset)
      key_length = data.slice(offset, 1).unpack(PACK_CHAR).first
      offset += 1
      key = data.slice(offset, key_length)
      offset += key_length

      [key, offset]
    end

encode(table) click to toggle source

    # File lib/amq/protocol/table.rb, line 29
    def self.encode(table)
      buffer = String.new

      table ||= {}

      table.each do |key, value|
        key = key.to_s # it can be a symbol as well
        buffer << key.bytesize.chr + key

        case value
        when Hash then
          buffer << TYPE_HASH
          buffer << self.encode(value)
        else
          buffer << TableValueEncoder.encode(value)
        end
      end

      [buffer.bytesize].pack(PACK_UINT32) + buffer
    end

hash_size(value) click to toggle source

    # File lib/amq/protocol/table.rb, line 117
    def self.hash_size(value)
      acc = 0
      value.each do |k, v|
        acc += (1 + k.to_s.bytesize)
        acc += TableValueEncoder.field_value_size(v)
      end

      acc
    end

length(data) click to toggle source

    # File lib/amq/protocol/table.rb, line 112
    def self.length(data)
      data.unpack(PACK_UINT32).first
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.