Sha256: 6489ea7af4c4f8b0b68bf68885e172d15a959bb3ea1c7cdabcd26edf39186911

Contents?: true

Size: 1003 Bytes

Versions: 2

Compression:

Stored size: 1003 Bytes

Contents

require 'bindata'

module Pio
  # Actions not yet implemented.
  class UnsupportedAction < BinData::Record
    endian :big

    uint16 :action_type
    uint16 :action_length
    string :body, length: -> { action_length - 4 }

    def to_binary
      to_binary_s
    end
  end

  # Actions list of actions-apply instruction.
  class Actions < BinData::Primitive
    mandatory_parameter :length

    endian :big

    string :binary, read_length: :length

    def set(actions)
      self.binary = Array(actions).map(&:to_binary).join
    end

    # rubocop:disable MethodLength
    def get
      actions = []
      tmp = binary
      while tmp.length > 0
        action = case BinData::Uint16be.read(tmp)
                 when 0
                   SendOutPort.read(tmp)
                 else
                   UnsupportedAction.read(tmp)
                 end
        tmp = tmp[action.action_length..-1]
        actions << action
      end
      actions
    end
    # rubocop:enable MethodLength
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pio-0.30.0 lib/pio/open_flow13/actions.rb
pio-0.29.0 lib/pio/open_flow13/actions.rb