class CZTop::Message::FramesAccessor

Used to access a {Message}‘s {Frame}s.

Public Class Methods

new(message) click to toggle source

@param message [Message]

# File lib/cztop/message/frames.rb, line 26
def initialize(message)
  @message = message
end

Public Instance Methods

[](*args) click to toggle source

Index access to a frame/frames of this message, just like with an array. @overload [](index)

@param index [Integer] index of {Frame} within {Message}

@overload [](*args)

@note See Array#[] for details.

@return [Frame] frame Message @return [nil] if there are no corresponding frames

# File lib/cztop/message/frames.rb, line 61
def [](*args)
  case args
  when [0] then first # speed up
  when [-1] then last # speed up
  else to_a[*args]
  end
end
each() { |first| ... } click to toggle source

Yields all frames for this message to the given block. @note Not thread safe. @yieldparam frame [Frame] @return [self]

# File lib/cztop/message/frames.rb, line 74
def each
  first = first()
  return unless first

  yield first
  while (frame = @message.ffi_delegate.next) && !frame.null?
    yield Frame.from_ffi_delegate(frame)
  end
  self
end
first() click to toggle source

Returns the last frame of this message. @return [Frame] first frame of Message @return [nil] if there are no frames

# File lib/cztop/message/frames.rb, line 34
def first
  first = @message.ffi_delegate.first
  return nil if first.null?

  Frame.from_ffi_delegate(first)
end
last() click to toggle source

Returns the last frame of this message. @return [Frame] last {Frame} of {Message} @return [nil] if there are no frames

# File lib/cztop/message/frames.rb, line 45
def last
  last = @message.ffi_delegate.last
  return nil if last.null?

  Frame.from_ffi_delegate(last)
end