Class: TIPCNameSeq

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

Overview

Represents a TIPC port name sequence address of the form <type, lower bound, upper bound>.

From the TIPC Programmer’s Guide:

A port name sequence consists of a 32-bit type field and a pair of 32-bit
instance fields, and represents the set of port names from {type,lower bound}
through {type,upper bound}, inclusive.  The lower bound of a name sequence
cannot be larger than the upper bound.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, lower, upper, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE) ⇒ TIPCNameSeq

Create a new TIPCNameSeq instance.

Parameters

* type  - arbitrary 32 bit type value
* lower - 32-bit lower bound of the name sequence
* upper - 32-bit upper bound of the name sequence
* scope - the scope (zone, cluster, or node) to use when packing
             this name as a TIPC address (optional)


200
201
202
203
204
205
206
207
# File 'lib/tipcsocket.rb', line 200

def initialize(type, lower, upper, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE)
  @family   = Socket::Constants::AF_TIPC
  @addrtype = TIPCSocket::Constants::TIPC_ADDR_NAMESEQ
  @type     = type
  @lower    = lower
  @upper    = upper
  @scope    = scope
end

Instance Attribute Details

#addrtypeObject (readonly)

Returns the value of attribute addrtype.



189
190
191
# File 'lib/tipcsocket.rb', line 189

def addrtype
  @addrtype
end

#familyObject (readonly)

Returns the value of attribute family.



189
190
191
# File 'lib/tipcsocket.rb', line 189

def family
  @family
end

#lowerObject

Returns the value of attribute lower.



190
191
192
# File 'lib/tipcsocket.rb', line 190

def lower
  @lower
end

#scopeObject

Returns the value of attribute scope.



190
191
192
# File 'lib/tipcsocket.rb', line 190

def scope
  @scope
end

#typeObject

Returns the value of attribute type.



190
191
192
# File 'lib/tipcsocket.rb', line 190

def type
  @type
end

#upperObject

Returns the value of attribute upper.



190
191
192
# File 'lib/tipcsocket.rb', line 190

def upper
  @upper
end

Class Method Details

.unpack(bytes) ⇒ Object

Create a new TIPCNameSeq instance from a 12 byte binary string containing a TIPC name sequence.

Parameters

* bytes - 12 byte string containing TIPC name sequence


259
260
261
262
# File 'lib/tipcsocket.rb', line 259

def self.unpack(bytes)
  data = bytes.unpack("L3")
  self.new(data[0], data[1], data[2])
end

.unpack_addr(bytes) ⇒ Object

Create a new TIPCNameSeq instance from a 16 byte binary string containing a TIPC address.

Parameters

* bytes - 16 byte string containing TIPC address


249
250
251
252
# File 'lib/tipcsocket.rb', line 249

def self.unpack_addr(bytes)
  data = bytes.unpack("SCcL3")
  self.new(data[3], data[4], data[5], data[2])
end

Instance Method Details

#packObject

Pack an instance of a TIPCNameSeq.

Produces an 12 byte string with the following format:

* type  - uint32 (4 bytes)
* lower - uint32 (4 bytes)
* upper - uint32 (4 bytes)


236
237
238
239
240
241
242
# File 'lib/tipcsocket.rb', line 236

def pack
  [
    self.type,
    self.lower,
    self.upper
  ].pack("L3")
end

#pack_addrObject

Pack an instance of a TIPCNameSeq as a 16 byte TIPC network address suitable for passing to one of the standard Socket methods (connect, send, etc.).

Produces a 16 byte binary string with the following format:

* family   - unsigned short (2 bytes)
* addrtype - unsigned char  (1 byte)
* scope    - signed char    (1 byte)
* type     - uint32         (4 bytes)
* lower    - uint32         (4 bytes)
* upper    - uint32         (4 bytes)


219
220
221
222
223
224
225
226
227
228
# File 'lib/tipcsocket.rb', line 219

def pack_addr
  [
    self.family,
    self.addrtype,
    self.scope,
    self.type,
    self.lower,
    self.upper
  ].pack("SCcL3")
end