Class: TIPCName
- Inherits:
-
Object
- Object
- TIPCName
- Defined in:
- lib/tipcsocket.rb
Overview
Represents a TIPC name address of the form <type, instance>.
From the TIPC Programmer’s Guide:
The basic unit of functional addressing within TIPC is the "port name", which
is typically denoted as {type,instance}. A port name consists of a 32-bit
type field and a 32-bit instance field, both of which are chosen by the
application. Typically, the type field is used to indicate the class of
service provided by the port, while the instance field can be used as a sub-
class indicator.
Instance Attribute Summary collapse
-
#addrtype ⇒ Object
readonly
Returns the value of attribute addrtype.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#family ⇒ Object
readonly
Returns the value of attribute family.
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.unpack(bytes) ⇒ Object
Create a new TIPCName instance from an 8 byte binary string containing a TIPC name.
-
.unpack_addr(bytes) ⇒ Object
Create a new TIPCName instance from a 16 byte binary string containing a TIPC address.
Instance Method Summary collapse
-
#initialize(type, instance, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE, domain = 0) ⇒ TIPCName
constructor
Create a new TIPCName instance.
-
#pack ⇒ Object
Pack an instance of a TIPCName.
-
#pack_addr ⇒ Object
Pack an instance of a TIPCName as a 16 byte TIPC network address suitable for passing to one of the standard Socket methods (connect, send, etc.).
Constructor Details
#initialize(type, instance, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE, domain = 0) ⇒ TIPCName
Create a new TIPCName instance.
Parameters
* type - arbitrary 32 bit type value
* instance - arbitrary 32 bit instance value
* scope - the scope (zone, cluster, or node) to use when packing
this name as a TIPC address (optional)
* domain - indicates the search domain used during the name lookup
process (optional)
116 117 118 119 120 121 122 123 |
# File 'lib/tipcsocket.rb', line 116 def initialize(type, instance, scope = TIPCSocket::Constants::TIPC_NODE_SCOPE, domain = 0) @family = Socket::Constants::AF_TIPC @addrtype = TIPCSocket::Constants::TIPC_ADDR_NAME @type = type @instance = instance @scope = scope @domain = 0 end |
Instance Attribute Details
#addrtype ⇒ Object (readonly)
Returns the value of attribute addrtype.
104 105 106 |
# File 'lib/tipcsocket.rb', line 104 def addrtype @addrtype end |
#domain ⇒ Object
Returns the value of attribute domain.
105 106 107 |
# File 'lib/tipcsocket.rb', line 105 def domain @domain end |
#family ⇒ Object (readonly)
Returns the value of attribute family.
104 105 106 |
# File 'lib/tipcsocket.rb', line 104 def family @family end |
#instance ⇒ Object
Returns the value of attribute instance.
105 106 107 |
# File 'lib/tipcsocket.rb', line 105 def instance @instance end |
#scope ⇒ Object
Returns the value of attribute scope.
105 106 107 |
# File 'lib/tipcsocket.rb', line 105 def scope @scope end |
#type ⇒ Object
Returns the value of attribute type.
105 106 107 |
# File 'lib/tipcsocket.rb', line 105 def type @type end |
Class Method Details
.unpack(bytes) ⇒ Object
Create a new TIPCName instance from an 8 byte binary string containing a TIPC name.
Parameters
* bytes - 8 byte string containing TIPC name
173 174 175 176 |
# File 'lib/tipcsocket.rb', line 173 def self.unpack(bytes) data = bytes.unpack("L2") self.new(data[0], data[1]) end |
.unpack_addr(bytes) ⇒ Object
Create a new TIPCName instance from a 16 byte binary string containing a TIPC address.
Parameters
* bytes - 16 byte string containing TIPC address
163 164 165 166 |
# File 'lib/tipcsocket.rb', line 163 def self.unpack_addr(bytes) data = bytes.unpack("SCcL3") self.new(data[3], data[4], data[2], data[5]) end |
Instance Method Details
#pack ⇒ Object
Pack an instance of a TIPCName.
Produces an 8 byte string with the following format:
* type - uint32 (4 bytes)
* instance - uint32 (4 bytes)
151 152 153 154 155 156 |
# File 'lib/tipcsocket.rb', line 151 def pack [ self.type, self.instance ].pack("L2") end |
#pack_addr ⇒ Object
Pack an instance of a TIPCName 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)
* instance - uint32 (4 bytes)
* domain - uint32 (4 bytes)
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tipcsocket.rb', line 135 def pack_addr [ self.family, self.addrtype, self.scope, self.type, self.instance, self.domain ].pack("SCcL3") end |