Skip to content

Commit 648f8cc

Browse files
Drop Body postfix.
1 parent ec6a5fa commit 648f8cc

File tree

10 files changed

+73
-62
lines changed

10 files changed

+73
-62
lines changed

config/external.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
async-grpc:
2+
url: https://github.com/socketry/async-grpc.git
3+
command: bundle exec sus

context/getting-started.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ $ bundle add protocol-grpc
1515
`protocol-grpc` has several core concepts:
1616

1717
- A {ruby Protocol::GRPC::Interface} class which defines gRPC service contracts with RPC methods, request/response types, and streaming patterns.
18-
- A {ruby Protocol::GRPC::Body::ReadableBody} class which handles reading gRPC messages from HTTP request/response bodies with automatic framing and decoding.
19-
- A {ruby Protocol::GRPC::Body::WritableBody} class which handles writing gRPC messages to HTTP request/response bodies with automatic framing and encoding.
18+
- A {ruby Protocol::GRPC::Body::Readable} class which handles reading gRPC messages from HTTP request/response bodies with automatic framing and decoding.
19+
- A {ruby Protocol::GRPC::Body::Writable} class which handles writing gRPC messages to HTTP request/response bodies with automatic framing and encoding.
2020
- A {ruby Protocol::GRPC::Middleware} abstract base class for building gRPC server applications.
2121
- A {ruby Protocol::GRPC::Call} class which represents the context of a single gRPC RPC call, including deadline tracking.
2222
- A {ruby Protocol::GRPC::Status} module with gRPC status code constants.
@@ -47,15 +47,15 @@ end
4747

4848
### Building a Request
4949

50-
Build gRPC requests using `Protocol::GRPC::Methods` and `Protocol::GRPC::Body::WritableBody`:
50+
Build gRPC requests using `Protocol::GRPC::Methods` and `Protocol::GRPC::Body::Writable`:
5151

5252
``` ruby
5353
require "protocol/grpc"
5454
require "protocol/grpc/methods"
55-
require "protocol/grpc/body/writable_body"
55+
require "protocol/grpc/body/writable"
5656

5757
# Build request body
58-
body = Protocol::GRPC::Body::WritableBody.new(message_class: Hello::HelloRequest)
58+
body = Protocol::GRPC::Body::Writable.new(message_class: Hello::HelloRequest)
5959
body.write(Hello::HelloRequest.new(name: "World"))
6060
body.close_write
6161

@@ -69,13 +69,13 @@ request = Protocol::HTTP::Request["POST", path, headers, body]
6969

7070
### Reading a Response
7171

72-
Read gRPC responses using `Protocol::GRPC::Body::ReadableBody`:
72+
Read gRPC responses using `Protocol::GRPC::Body::Readable`:
7373

7474
``` ruby
75-
require "protocol/grpc/body/readable_body"
75+
require "protocol/grpc/body/readable"
7676

7777
# Read response body
78-
readable_body = Protocol::GRPC::Body::ReadableBody.new(
78+
readable_body = Protocol::GRPC::Body::Readable.new(
7979
response.body,
8080
message_class: Hello::HelloReply
8181
)

design.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,15 @@ module Protocol
299299
# @parameter status [Integer] gRPC status code
300300
# @parameter message [String | Nil] Optional status message
301301
# @parameter error [Exception | Nil] Optional error object (used to extract backtrace)
302-
def self.add_status!(headers, status: Status::OK, message: nil, error: nil)
303-
headers["grpc-status"] = Header::Status.new(status)
304-
headers["grpc-message"] = Header::Message.new(Header::Message.encode(message)) if message
305-
306-
# Add backtrace from error if available
307-
if error && error.backtrace && !error.backtrace.empty?
308-
headers["backtrace"] = error.backtrace
309-
end
310-
end
302+
def self.add_status!(headers, status: Status::OK, message: nil, error: nil)
303+
headers["grpc-status"] = Header::Status.new(status)
304+
headers["grpc-message"] = Header::Message.new(Header::Message.encode(message)) if message
305+
306+
# Add backtrace from error if available
307+
if error && error.backtrace && !error.backtrace.empty?
308+
headers["backtrace"] = error.backtrace
309+
end
310+
end
311311
end
312312
end
313313
end
@@ -741,13 +741,13 @@ module Protocol
741741
end
742742

743743
# Handle the RPC
744-
begin
745-
handle_rpc(request, handler, handler_method, request_class, response_class)
746-
rescue Error => error
747-
make_response(error.status_code, error.message, error: error)
748-
rescue => error
749-
make_response(Status::INTERNAL, error.message, error: error)
750-
end
744+
begin
745+
handle_rpc(request, handler, handler_method, request_class, response_class)
746+
rescue Error => error
747+
make_response(error.status_code, error.message, error: error)
748+
rescue => error
749+
make_response(Status::INTERNAL, error.message, error: error)
750+
end
751751
end
752752

753753
protected
@@ -776,21 +776,21 @@ module Protocol
776776
output.close_write unless output.closed?
777777

778778
# Mark trailers and add status
779-
response_headers.trailer!
780-
Metadata.add_status!(response_headers, status: Status::OK)
779+
response_headers.trailer!
780+
Metadata.add_status!(response_headers, status: Status::OK)
781+
782+
Protocol::HTTP::Response[200, response_headers, output]
783+
end
781784

782-
Protocol::HTTP::Response[200, response_headers, output]
783-
end
784-
785785
protected
786-
787-
def make_response(status_code, message, error: nil)
788-
headers = Protocol::HTTP::Headers.new([], nil, policy: HEADER_POLICY)
789-
headers["content-type"] = "application/grpc+proto"
790-
Metadata.add_status!(headers, status: status_code, message: message, error: error)
791786

792-
Protocol::HTTP::Response[200, headers, nil]
793-
end
787+
def make_response(status_code, message, error: nil)
788+
headers = Protocol::HTTP::Headers.new([], nil, policy: HEADER_POLICY)
789+
headers["content-type"] = "application/grpc+proto"
790+
Metadata.add_status!(headers, status: status_code, message: message, error: error)
791+
792+
Protocol::HTTP::Response[200, headers, nil]
793+
end
794794
end
795795
end
796796
end

fixtures/protocol/grpc/test_middleware.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
require "protocol/grpc/middleware"
77
require "protocol/grpc/methods"
88
require "protocol/grpc/call"
9-
require "protocol/grpc/body/readable_body"
10-
require "protocol/grpc/body/writable_body"
9+
require "protocol/grpc/body/readable"
10+
require "protocol/grpc/body/writable"
1111

1212
# Test implementation of Middleware with service routing
1313
class TestMiddleware < Protocol::GRPC::Middleware
@@ -39,8 +39,8 @@ def dispatch(request)
3939

4040
# Create protocol-level objects for gRPC handling
4141
encoding = request.headers["grpc-encoding"]
42-
input = Protocol::GRPC::Body::ReadableBody.new(request.body, encoding: encoding)
43-
output = Protocol::GRPC::Body::WritableBody.new(encoding: encoding)
42+
input = Protocol::GRPC::Body::Readable.new(request.body, encoding: encoding)
43+
output = Protocol::GRPC::Body::Writable.new(encoding: encoding)
4444

4545
# Create call context
4646
response_headers = Protocol::HTTP::Headers.new([], nil, policy: Protocol::GRPC::HEADER_POLICY)
@@ -61,7 +61,7 @@ def dispatch(request)
6161
result = wrapper.call(input, output, call)
6262

6363
# Handler may return a different output, or modify the existing one
64-
final_output = result.is_a?(Protocol::GRPC::Body::WritableBody) ? result : output
64+
final_output = result.is_a?(Protocol::GRPC::Body::Writable) ? result : output
6565
final_output.close_write unless final_output.closed?
6666

6767
# Mark trailers and add status
@@ -101,7 +101,7 @@ def call(input, output, call)
101101
underlying_body = input.body
102102
# Preserve any buffered data from the original input
103103
original_buffer = input.instance_variable_get(:@buffer)
104-
input = Protocol::GRPC::Body::ReadableBody.new(underlying_body, message_class: @request_class, encoding: encoding)
104+
input = Protocol::GRPC::Body::Readable.new(underlying_body, message_class: @request_class, encoding: encoding)
105105
# Copy buffered data if any exists
106106
if original_buffer && !original_buffer.empty?
107107
input.instance_variable_set(:@buffer, original_buffer.dup)
@@ -112,7 +112,7 @@ def call(input, output, call)
112112
encoding = output.encoding
113113
# Create new output with type information
114114
# The original output's data is lost, but that's okay since we haven't written to it yet
115-
output = Protocol::GRPC::Body::WritableBody.new(message_class: @response_class, encoding: encoding)
115+
output = Protocol::GRPC::Body::Writable.new(message_class: @response_class, encoding: encoding)
116116
end
117117

118118
# Call the actual handler method

guides/getting-started/readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ $ bundle add protocol-grpc
1515
`protocol-grpc` has several core concepts:
1616

1717
- A {ruby Protocol::GRPC::Interface} class which defines gRPC service contracts with RPC methods, request/response types, and streaming patterns.
18-
- A {ruby Protocol::GRPC::Body::ReadableBody} class which handles reading gRPC messages from HTTP request/response bodies with automatic framing and decoding.
19-
- A {ruby Protocol::GRPC::Body::WritableBody} class which handles writing gRPC messages to HTTP request/response bodies with automatic framing and encoding.
18+
- A {ruby Protocol::GRPC::Body::Readable} class which handles reading gRPC messages from HTTP request/response bodies with automatic framing and decoding.
19+
- A {ruby Protocol::GRPC::Body::Writable} class which handles writing gRPC messages to HTTP request/response bodies with automatic framing and encoding.
2020
- A {ruby Protocol::GRPC::Middleware} abstract base class for building gRPC server applications.
2121
- A {ruby Protocol::GRPC::Call} class which represents the context of a single gRPC RPC call, including deadline tracking.
2222
- A {ruby Protocol::GRPC::Status} module with gRPC status code constants.
@@ -47,15 +47,15 @@ end
4747

4848
### Building a Request
4949

50-
Build gRPC requests using `Protocol::GRPC::Methods` and `Protocol::GRPC::Body::WritableBody`:
50+
Build gRPC requests using `Protocol::GRPC::Methods` and `Protocol::GRPC::Body::Writable`:
5151

5252
``` ruby
5353
require "protocol/grpc"
5454
require "protocol/grpc/methods"
55-
require "protocol/grpc/body/writable_body"
55+
require "protocol/grpc/body/writable"
5656

5757
# Build request body
58-
body = Protocol::GRPC::Body::WritableBody.new(message_class: Hello::HelloRequest)
58+
body = Protocol::GRPC::Body::Writable.new(message_class: Hello::HelloRequest)
5959
body.write(Hello::HelloRequest.new(name: "World"))
6060
body.close_write
6161

@@ -69,13 +69,13 @@ request = Protocol::HTTP::Request["POST", path, headers, body]
6969

7070
### Reading a Response
7171

72-
Read gRPC responses using `Protocol::GRPC::Body::ReadableBody`:
72+
Read gRPC responses using `Protocol::GRPC::Body::Readable`:
7373

7474
``` ruby
75-
require "protocol/grpc/body/readable_body"
75+
require "protocol/grpc/body/readable"
7676

7777
# Read response body
78-
readable_body = Protocol::GRPC::Body::ReadableBody.new(
78+
readable_body = Protocol::GRPC::Body::Readable.new(
7979
response.body,
8080
message_class: Hello::HelloReply
8181
)

lib/protocol/grpc.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
require_relative "grpc/header"
1212
require_relative "grpc/metadata"
1313
require_relative "grpc/call"
14-
require_relative "grpc/body/readable_body"
15-
require_relative "grpc/body/writable_body"
14+
require_relative "grpc/body/readable"
15+
require_relative "grpc/body/writable"
1616
require_relative "grpc/interface"
1717
require_relative "grpc/middleware"
1818
require_relative "grpc/health_check"
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ module Body
1414
# Represents a readable body for gRPC messages with length-prefixed framing.
1515
# This is the standard readable body for gRPC - all gRPC responses use message framing.
1616
# Wraps the underlying HTTP body and transforms raw chunks into decoded gRPC messages.
17-
class ReadableBody < Protocol::HTTP::Body::Wrapper
17+
class Readable < Protocol::HTTP::Body::Wrapper
1818
# Wrap the body of a message.
1919
#
2020
# @parameter message [Request | Response] The message to wrap.
2121
# @parameter options [Hash] The options to pass to the initializer.
22-
# @returns [ReadableBody | Nil] The wrapped body or `nil` if the message has no body.
22+
# @returns [Readable | Nil] The wrapped body or `nil` if the message has no body.
2323
def self.wrap(message, **options)
2424
if body = message.body
2525
message.body = self.new(body, **options)
@@ -121,3 +121,5 @@ def decompress(data)
121121
end
122122
end
123123
end
124+
125+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module GRPC
1414
module Body
1515
# Represents a writable body for gRPC messages with length-prefixed framing.
1616
# This is the standard writable body for gRPC - all gRPC requests use message framing.
17-
class WritableBody < Protocol::HTTP::Body::Writable
17+
class Writable < Protocol::HTTP::Body::Writable
1818
# Initialize a new writable body for gRPC messages.
1919
# @parameter encoding [String | Nil] Compression encoding (gzip, deflate, identity)
2020
# @parameter level [Integer] Compression level if encoding is used
@@ -99,3 +99,5 @@ def compress(data)
9999
end
100100
end
101101
end
102+
103+
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Released under the MIT License.
44
# Copyright, 2025, by Samuel Williams.
55

6-
require "protocol/grpc/body/readable_body"
6+
require "protocol/grpc/body/readable"
77
require "protocol/http/body/buffered"
88
require_relative "../../../../fixtures/protocol/grpc/test_message"
99

10-
describe Protocol::GRPC::Body::ReadableBody do
10+
describe Protocol::GRPC::Body::Readable do
1111
let(:message_class) {Protocol::GRPC::Fixtures::TestMessage}
1212
let(:source_body) {Protocol::HTTP::Body::Buffered.new}
1313
let(:body) {subject.new(source_body, message_class: message_class)}
@@ -27,7 +27,7 @@ def write_message(message, compressed: false)
2727
it "reads single message" do
2828
message = message_class.new(value: "Hello")
2929
write_message(message)
30-
# Don't close the body - let ReadableBody handle it
30+
# Don't close the body - let Readable handle it
3131

3232
read_message = body.read
3333
expect(read_message).to be == message
@@ -38,7 +38,7 @@ def write_message(message, compressed: false)
3838
message2 = message_class.new(value: "World")
3939
write_message(message1)
4040
write_message(message2)
41-
# Don't close the body - let ReadableBody handle it
41+
# Don't close the body - let Readable handle it
4242

4343
expect(body.read).to be == message1
4444
expect(body.read).to be == message2
@@ -136,3 +136,5 @@ def write_message(message, compressed: false)
136136
end
137137
end
138138
end
139+
140+
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Released under the MIT License.
44
# Copyright, 2025, by Samuel Williams.
55

6-
require "protocol/grpc/body/writable_body"
6+
require "protocol/grpc/body/writable"
77
require "protocol/http/body/writable"
88
require_relative "../../../../fixtures/protocol/grpc/test_message"
99

10-
describe Protocol::GRPC::Body::WritableBody do
10+
describe Protocol::GRPC::Body::Writable do
1111
let(:body) {subject.new}
1212
let(:message_class) {Protocol::GRPC::Fixtures::TestMessage}
1313

@@ -296,3 +296,5 @@ def wrong_message.to_proto
296296
end
297297
end
298298
end
299+
300+

0 commit comments

Comments
 (0)