class XenStore::Packet
Public Class Methods
check_op(op)
click to toggle source
Check if the provided operation is valid and raise a XenStore::Exceptions::InvalidOperation
exception if not.
@param op Should be either a symbol or a uint. If a symbol
then it will be used as a key to lookup the value in the +XenStore::OPERATIONS+ hash.
# File lib/xsrb/packet.rb, line 31 def check_op(op) if op.is_a? Symbol unless XenStore::OPERATIONS.key? op raise XenStore::Exceptions::InvalidOperation, op.to_s end XenStore::OPERATIONS[op] else unless XenStore::OPERATIONS.values.include? op raise XenStore::Exceptions::InvalidOperation, op.to_s end op end end
header_size()
click to toggle source
Get size of each packet header
@return [Integer] The size in bytes of each Packet
header.
# File lib/xsrb/packet.rb, line 50 def header_size 4 * (32 / 8) end
new(op, payload, rq_id, tx_id = 0)
click to toggle source
# File lib/xsrb/packet.rb, line 4 def initialize(op, payload, rq_id, tx_id = 0) if payload.length > 4096 raise XenStore::Exceptions::InvalidPayload, "Payload too large (#{l}): #{payload}" end @op = check_op op @rq_id = rq_id @tx_id = tx_id @payload = payload.to_s + XenStore::NUL end
Public Instance Methods
pack()
click to toggle source
Convert to a binary representation for transport to the xenstored
@return [String] A binary version of the Packet
.
# File lib/xsrb/packet.rb, line 19 def pack packdata = [@op, @rq_id, @tx_id, @payload.length] packdata.pack('IIII') + @payload end