Class: AMQ::Protocol::TableValueDecoder

### Home Classes Methods

### In Files

- lib/amq/protocol/table_value_decoder.rb

### Parent

Object

### Methods

- ::decode_32bit_float
- ::decode_64bit_float
- ::decode_array
- ::decode_big_decimal
- ::decode_boolean
- ::decode_byte
- ::decode_hash
- ::decode_integer
- ::decode_long
- ::decode_short
- ::decode_string
- ::decode_time
- ::decode_value_type

### 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::TableValueDecoder

### Public Class Methods

decode_32bit_float(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 145
    def self.decode_32bit_float(data, offset)
      v = data.slice(offset, 4).unpack(PACK_32BIT_FLOAT).first
      offset += 4

      [v, offset]
    end

decode_64bit_float(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 153
    def self.decode_64bit_float(data, offset)
      v = data.slice(offset, 8).unpack(PACK_64BIT_FLOAT).first
      offset += 8

      [v, offset]
    end

decode_array(data, initial_offset) click to toggle source

API

    # File lib/amq/protocol/table_value_decoder.rb, line 24
    def self.decode_array(data, initial_offset)
      array_length = data.slice(initial_offset, 4).unpack(PACK_UINT32).first

      ary    = Array.new
      offset = initial_offset + 4

      while offset <= (initial_offset + array_length)
        type, offset = decode_value_type(data, offset)

        i = case type
            when TYPE_STRING
              v, offset = decode_string(data, offset)
              v
            when TYPE_INTEGER
              v, offset = decode_integer(data, offset)
              v
            when TYPE_DECIMAL
              v, offset = decode_big_decimal(data, offset)
              v
            when TYPE_TIME
              v, offset = decode_time(data, offset)
              v
            when TYPE_HASH
              v, offset = decode_hash(data, offset)
              v
            when TYPE_BOOLEAN
              v, offset = decode_boolean(data, offset)
              v
            when TYPE_BYTE then
              v, offset = decode_byte(data, offset)
              v
            when TYPE_SIGNED_16BIT then
              v, offset = decode_short(data, offset)
              v
            when TYPE_SIGNED_64BIT then
              v, offset = decode_long(data, offset)
              v
            when TYPE_32BIT_FLOAT then
              v, offset = decode_32bit_float(data, offset)
              v
            when TYPE_64BIT_FLOAT then
              v, offset = decode_64bit_float(data, offset)
              v
            when TYPE_VOID
              nil
            when TYPE_ARRAY
              v, offset = TableValueDecoder.decode_array(data, offset)
              v
            else
              raise ArgumentError.new("unsupported type in a table value: #{type.inspect}, do not know how to decode!")
            end

        ary << i
      end

      [ary, initial_offset + array_length + 4]
    end

decode_big_decimal(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 120
    def self.decode_big_decimal(data, offset)
      decimals, raw = data.slice(offset, 5).unpack(PACK_UCHAR_UINT32)
      offset += 5
      v = BigDecimal.new(raw.to_s) * (BigDecimal.new(TEN) ** -decimals)

      [v, offset]
    end

decode_boolean(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 138
    def self.decode_boolean(data, offset)
      integer = data.slice(offset, 2).unpack(PACK_CHAR).first # 0 or 1
      offset += 1
      [(integer == 1), offset]
    end

decode_byte(data, offset) click to toggle source

Decodes/Converts a byte value from the data at the provided offset.

@param [Array] data - A big-endian ordered array of bytes. @param [Fixnum] offset - The offset which bytes the byte is consumed. @return [Array] - The Fixnum value and new offset pair.

    # File lib/amq/protocol/table_value_decoder.rb, line 181
    def self.decode_byte(data, offset)
      [data.slice(offset, 1).unpack(PACK_CHAR).first, offset += 1]
    end

decode_hash(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 167
    def self.decode_hash(data, offset)
      length = data.slice(offset, 4).unpack(PACK_UINT32).first
      v = Table.decode(data.slice(offset, length + 4))
      offset += 4 + length

      [v, offset]
    end

decode_integer(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 94
    def self.decode_integer(data, offset)
      v = data.slice(offset, 4).unpack(PACK_UINT32).first
      offset += 4

      [v, offset]
    end

decode_long(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 103
    def self.decode_long(data, offset)
      v    = data.slice(offset, 8).unpack(PACK_INT64)

      offset += 8
      [v, offset]
    end

decode_short(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 186
    def self.decode_short(data, offset)
      v = AMQ::Hacks.unpack_int16_big_endian(data.slice(offset, 2)).first
      offset += 2
      [v, offset]
    end

decode_string(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 84
    def self.decode_string(data, offset)
      length = data.slice(offset, 4).unpack(PACK_UINT32).first
      offset += 4
      v = data.slice(offset, length)
      offset += length

      [v, offset]
    end

decode_time(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 129
    def self.decode_time(data, offset)
      timestamp = data.slice(offset, 8).unpack(PACK_UINT32_X2).last
      v = Time.at(timestamp)
      offset += 8

      [v, offset]
    end

decode_value_type(data, offset) click to toggle source

    # File lib/amq/protocol/table_value_decoder.rb, line 161
    def self.decode_value_type(data, offset)
      [data.slice(offset, 1), offset + 1]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.