Class: XDR::Reader
- Inherits:
-
Object
- Object
- XDR::Reader
- Defined in:
- lib/logstash/inputs/ganglia/xdr.rb
Instance Method Summary collapse
- #_int16(typename) ⇒ Object
- #_uint16(typename) ⇒ Object
-
#bool ⇒ Object
A boolean value, encoded as a signed integer.
-
#bytes(n) ⇒ Object
Opaque data of length n, padded to a multiple of 4 bytes.
-
#float128 ⇒ Object
a 128-bit float, big-endian.
-
#float32 ⇒ Object
A 32-bit float, big-endian.
-
#float64 ⇒ Object
a 64-bit float, big-endian.
-
#initialize(io) ⇒ Reader
constructor
A new instance of Reader.
- #int16 ⇒ Object
-
#int32 ⇒ Object
A signed 32-bit integer, big-endian.
-
#int64 ⇒ Object
A signed 64-bit integer, big-endian.
- #read(type) ⇒ Object
-
#string ⇒ Object
A string, preceeded by its length.
-
#uint16 ⇒ Object
ADDED HERE -> need to return patch Short.
-
#uint32 ⇒ Object
An unsigned 32-bit integer, big-endian.
-
#uint64 ⇒ Object
An unsigned 64-bit integer, big-endian.
-
#var_bytes ⇒ Object
Opaque data, preceeded by its length.
-
#void ⇒ Object
Void doesn’t require a representation.
Constructor Details
#initialize(io) ⇒ Reader
Returns a new instance of Reader.
25 26 27 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 25 def initialize(io) @io = io end |
Instance Method Details
#_int16(typename) ⇒ Object
40 41 42 43 44 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 40 def _int16(typename) # Ruby's unpack doesn't give us a big-endian signed integer, so we # decode a native signed integer and conditionally swap it _read_type(4, typename).unpack("n").pack("L").unpack("l").first end |
#_uint16(typename) ⇒ Object
46 47 48 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 46 def _uint16(typename) _read_type(2, typename).unpack("n").first end |
#bool ⇒ Object
A boolean value, encoded as a signed integer
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 63 def bool() val = _int32("bool") case val when 0 false when 1 true else raise ArgumentError, "Invalid value for bool: #{val}" end end |
#bytes(n) ⇒ Object
Opaque data of length n, padded to a multiple of 4 bytes
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 106 def bytes(n) # Data length is n padded to a multiple of 4 align = n % 4 if align == 0 then len = n else len = n + (4-align) end bytes = _read_type(len, "opaque of length #{n}") # Remove padding if required (1..(4-align)).each { bytes.chop! } if align != 0 bytes end |
#float128 ⇒ Object
a 128-bit float, big-endian
100 101 102 103 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 100 def float128() # Maybe some day raise NotImplementedError end |
#float32 ⇒ Object
A 32-bit float, big-endian
90 91 92 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 90 def float32() _read_type(4, "float32").unpack("g").first end |
#float64 ⇒ Object
a 64-bit float, big-endian
95 96 97 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 95 def float64() _read_type(8, "float64").unpack("G").first end |
#int16 ⇒ Object
36 37 38 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 36 def int16() _int16("int16") end |
#int32 ⇒ Object
A signed 32-bit integer, big-endian
53 54 55 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 53 def int32() _int32("int32") end |
#int64 ⇒ Object
A signed 64-bit integer, big-endian
77 78 79 80 81 82 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 77 def int64() # Read an unsigned value, then convert it to signed val = _uint64("int64") val >= 2**63 ? -(2**64 - val): val end |
#read(type) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 140 def read(type) # For syntactic niceness, instantiate a new object of class 'type' # if type is a class type = type.new() if type.is_a?(Class) type.read(self) type end |
#string ⇒ Object
A string, preceeded by its length
130 131 132 133 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 130 def string() len = self.uint32() self.bytes(len) end |
#uint16 ⇒ Object
ADDED HERE -> need to return patch Short
32 33 34 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 32 def uint16() _uint16("uint16") end |
#uint32 ⇒ Object
An unsigned 32-bit integer, big-endian
58 59 60 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 58 def uint32() _uint32("uint32") end |
#uint64 ⇒ Object
An unsigned 64-bit integer, big-endian
85 86 87 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 85 def uint64() _uint64("uint64") end |
#var_bytes ⇒ Object
Opaque data, preceeded by its length
124 125 126 127 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 124 def var_bytes() len = self.uint32() self.bytes(len) end |
#void ⇒ Object
Void doesn’t require a representation. Included only for completeness.
136 137 138 |
# File 'lib/logstash/inputs/ganglia/xdr.rb', line 136 def void() nil end |