Class: Protocol::GRPC::Header::Status
- Inherits:
-
Object
- Object
- Protocol::GRPC::Header::Status
- Defined in:
- lib/protocol/grpc/header/status.rb
Overview
The grpc-status header represents the gRPC status code.
The grpc-status header contains a numeric status code (0-16) indicating the result of the RPC call.
Status code 0 indicates success (OK), while other codes indicate various error conditions.
This header can appear both as an initial header (for trailers-only responses) and as a trailer.
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Coerce a value to a Status instance.
-
.parse(value) ⇒ Object
Parse a status code from a header value.
-
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Merge another status value (takes the new value, as status should only appear once).
-
#==(other) ⇒ Object
(also: #eql?)
Check equality with another status or integer value.
-
#hash ⇒ Object
Generate hash for use in Hash/Set collections.
-
#initialize(value) ⇒ Status
constructor
Initialize the status header with the given value.
-
#ok? ⇒ Boolean
Check if this status represents success (status code 0).
-
#to_i ⇒ Object
Get the status code as an integer.
-
#to_s ⇒ Object
Serialize the status code to a string.
Constructor Details
#initialize(value) ⇒ Status
Initialize the status header with the given value.
39 40 41 |
# File 'lib/protocol/grpc/header/status.rb', line 39 def initialize(value) @value = value.to_i end |
Class Method Details
.coerce(value) ⇒ Object
Coerce a value to a Status instance. Used by Protocol::HTTP::Headers when setting header values.
28 29 30 31 32 33 34 |
# File 'lib/protocol/grpc/header/status.rb', line 28 def self.coerce(value) if value.is_a?(self) value else new(value) end end |
.parse(value) ⇒ Object
Parse a status code from a header value.
19 20 21 |
# File 'lib/protocol/grpc/header/status.rb', line 19 def self.parse(value) new(value.to_i) end |
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
The grpc-status header can appear in trailers as per the gRPC specification.
92 93 94 |
# File 'lib/protocol/grpc/header/status.rb', line 92 def self.trailer? true end |
Instance Method Details
#<<(value) ⇒ Object
Merge another status value (takes the new value, as status should only appear once)
83 84 85 86 87 |
# File 'lib/protocol/grpc/header/status.rb', line 83 def <<(value) @value = value.to_i return self end |
#==(other) ⇒ Object Also known as: eql?
Check equality with another status or integer value.
61 62 63 |
# File 'lib/protocol/grpc/header/status.rb', line 61 def ==(other) @value == other.to_i end |
#hash ⇒ Object
Generate hash for use in Hash/Set collections.
70 71 72 |
# File 'lib/protocol/grpc/header/status.rb', line 70 def hash @value.hash end |
#ok? ⇒ Boolean
Check if this status represents success (status code 0).
77 78 79 |
# File 'lib/protocol/grpc/header/status.rb', line 77 def ok? @value == 0 end |
#to_i ⇒ Object
Get the status code as an integer.
46 47 48 |
# File 'lib/protocol/grpc/header/status.rb', line 46 def to_i @value end |
#to_s ⇒ Object
Serialize the status code to a string.
53 54 55 |
# File 'lib/protocol/grpc/header/status.rb', line 53 def to_s @value.to_s end |