Class: RStyx::Message::Qid
- Inherits:
-
Object
- Object
- RStyx::Message::Qid
- Defined in:
- lib/rstyx/messages.rb
Overview
Class representing the server’s view of a file.
Constant Summary collapse
- QID_LENGTH =
size of a Qid
13
Instance Attribute Summary collapse
-
#path ⇒ Object
The file server’s unique identification for the file.
-
#qtype ⇒ Object
The type of the file (directory, etc.) represented as a bit vector corresponding to the high 8 bits of the file’s mode word.
-
#version ⇒ Object
Version number for given path.
Class Method Summary collapse
-
.from_bytes(msgbytes) ⇒ Object
Decode a serialized Qid from its byte string representation.
Instance Method Summary collapse
-
#==(x) ⇒ Object
Test if two qid’s are the same.
-
#initialize(type, version, path) ⇒ Qid
constructor
Create a new Qid object.
-
#to_bytes ⇒ Object
Get the byte string representation of the Qid.
-
#to_s ⇒ Object
Dump a Qid.
Constructor Details
#initialize(type, version, path) ⇒ Qid
Create a new Qid object.
- type
- Fixnum
-
the type of file (directory, append only file, etc.)
- version
- Fixnum
-
the version number of the file
- path
- Fixnum
-
a 64-bit integer that should be unique among all
files being served
57 58 59 60 61 |
# File 'lib/rstyx/messages.rb', line 57 def initialize(type, version, path) @qtype = type @version = version @path = path end |
Instance Attribute Details
#path ⇒ Object
The file server’s unique identification for the file
45 46 47 |
# File 'lib/rstyx/messages.rb', line 45 def path @path end |
#qtype ⇒ Object
The type of the file (directory, etc.) represented as a bit vector corresponding to the high 8 bits of the file’s mode word.
39 40 41 |
# File 'lib/rstyx/messages.rb', line 39 def qtype @qtype end |
#version ⇒ Object
Version number for given path
42 43 44 |
# File 'lib/rstyx/messages.rb', line 42 def version @version end |
Class Method Details
.from_bytes(msgbytes) ⇒ Object
Decode a serialized Qid from its byte string representation
- msgbytes
- String
-
the byte string representation of the qid
- return value
- Qid
-
the Qid represented by the byte string.
- raises
-
StyxException if the string cannot be decoded as a Qid
88 89 90 91 92 93 94 95 96 |
# File 'lib/rstyx/messages.rb', line 88 def self.from_bytes(msgbytes) qtype, version, pathlo, pathhi = msgbytes.unpack("CVVV") if qtype.nil? || version.nil? || pathlo.nil? || pathhi.nil? raise StyxException.new("QID failed decode") end # recombine in little-endian mode path = pathlo | (pathhi << 32) return(Qid.new(qtype, version, path)) end |
Instance Method Details
#==(x) ⇒ Object
Test if two qid’s are the same.
66 67 68 |
# File 'lib/rstyx/messages.rb', line 66 def ==(x) return(self.to_bytes == x.to_bytes) end |
#to_bytes ⇒ Object
Get the byte string representation of the Qid
- return value
- String
-
the byte string representation of the Qid
75 76 77 78 79 |
# File 'lib/rstyx/messages.rb', line 75 def to_bytes pathlo = @path & 0xffffffff pathhi = (@path >> 32) & 0xffffffff return([@qtype, @version, pathlo, pathhi].pack("CVVV")) end |
#to_s ⇒ Object
Dump a Qid
- return value
- String
-
a textual representation of the Qid
103 104 105 106 |
# File 'lib/rstyx/messages.rb', line 103 def to_s val = sprintf("(Qid 0x%02x %d 0x%02x)", @qtype, @version, @path) return(val) end |