Class: StrokeDB::DistributedPointer
- Defined in:
- lib/strokedb/volumes/distributed_pointer.rb
Overview
DP is for pointing to DataVolume item. It can address zillions of DataVolumes, 4 GB each.
DP is stored as a 160 bit bytestring. First 128 bits is a volume UUID. Next 32 bits is an offset in a volume (unsigned long). Hence, the limit for DataVolume size: max 4 Gb. Actually, real-world applications would have relatively small datavolumes (about 64 Mb).
Instance Attribute Summary collapse
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#volume_uuid ⇒ Object
Returns the value of attribute volume_uuid.
Class Method Summary collapse
- .pack(uuid, offset) ⇒ Object
-
.unpack(string160bit) ⇒ Object
Creates a pointer object using binary string.
Instance Method Summary collapse
-
#initialize(uuid, offset) ⇒ DistributedPointer
constructor
Initialize pointer with given components.
-
#inspect ⇒ Object
(also: #to_s)
:nodoc:.
-
#pack ⇒ Object
Converts pointer object to it’s string representation.
Constructor Details
#initialize(uuid, offset) ⇒ DistributedPointer
Initialize pointer with given components.
-
uuid UUID (either raw or formatted)
-
offset is a positive integer
16 17 18 19 |
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 16 def initialize(uuid, offset) @volume_uuid = uuid.to_raw_uuid @offset = offset end |
Instance Attribute Details
#offset ⇒ Object
Returns the value of attribute offset.
10 11 12 |
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 10 def offset @offset end |
#volume_uuid ⇒ Object
Returns the value of attribute volume_uuid.
10 11 12 |
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 10 def volume_uuid @volume_uuid end |
Class Method Details
.pack(uuid, offset) ⇒ Object
33 34 35 |
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 33 def self.pack(uuid,offset) uuid.to_raw_uuid + [offset].pack("L") end |
.unpack(string160bit) ⇒ Object
Creates a pointer object using binary string.
23 24 25 |
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 23 def self.unpack(string160bit) new(string160bit[0, 16], string160bit[16, 4].unpack("L")[0]) end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
:nodoc:
37 38 39 |
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 37 def inspect #:nodoc: "#<DistributedPointer #{@volume_uuid.to_formatted_uuid}:#{@offset}>" end |
#pack ⇒ Object
Converts pointer object to it’s string representation.
29 30 31 |
# File 'lib/strokedb/volumes/distributed_pointer.rb', line 29 def pack @volume_uuid + [@offset].pack("L") end |