Class: XenStore::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/xsrb/packet.rb

Overview

An individual Packet of data sent to XenStore.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(op, payload, rq_id, tx_id = 0) ⇒ Packet



4
5
6
7
8
9
10
11
12
13
14
# 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

Class Method Details

.check_op(op) ⇒ Object

Check if the provided operation is valid and raise a XenStore::Exceptions::InvalidOperation exception if not.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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_sizeInteger

Get size of each packet header



50
51
52
# File 'lib/xsrb/packet.rb', line 50

def header_size
  4 * (32 / 8)
end

Instance Method Details

#packString

Convert to a binary representation for transport to the xenstored



19
20
21
22
# File 'lib/xsrb/packet.rb', line 19

def pack
  packdata = [@op, @rq_id, @tx_id, @payload.length]
  packdata.pack('IIII') + @payload
end