Class: Trace::SpanId
- Inherits:
-
Object
- Object
- Trace::SpanId
- Defined in:
- lib/finagle-thrift/trace.rb
Constant Summary collapse
- HEX_REGEX =
/^[a-f0-9]{16,32}$/i
- MAX_SIGNED_I64 =
9223372036854775807
- MASK =
(2 ** 64) - 1
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ SpanId
constructor
A new instance of SpanId.
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ SpanId
Returns a new instance of SpanId.
118 119 120 121 122 123 124 125 |
# File 'lib/finagle-thrift/trace.rb', line 118 def initialize(value) @value = value @i64 = if @value > MAX_SIGNED_I64 -1 * ((@value ^ MASK) + 1) else @value end end |
Class Method Details
.from_value(v) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/finagle-thrift/trace.rb', line 107 def self.from_value(v) if v.is_a?(String) && v =~ HEX_REGEX # drops any bits higher than 64 by selecting right-most 16 characters new(v.length > 16 ? v[v.length - 16, 16].hex : v.hex) elsif v.is_a?(Numeric) new(v) elsif v.is_a?(SpanId) v end end |
Instance Method Details
#to_i ⇒ Object
128 |
# File 'lib/finagle-thrift/trace.rb', line 128 def to_i; @i64; end |
#to_s ⇒ Object
127 |
# File 'lib/finagle-thrift/trace.rb', line 127 def to_s; "%016x" % @value; end |