Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt new bag-of-bytes protocol #55

Merged
merged 10 commits into from
Jan 17, 2025
Merged

Adopt new bag-of-bytes protocol #55

merged 10 commits into from
Jan 17, 2025

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jan 14, 2025

Motivation:

The core package added a bag-of-bytes protocol which transports must be generic over. We need to adopt those changes here.

Modifications:

  • Add a GRPCNIOTransportBytes type which wraps ByteBuffer and implements the GRPCContiguousBytes protocol.
  • Use this as the bytes type for client/server transports.
  • Update the appropriate state machines to deal in terms of ByteBuffer
  • Update the compressor/decompressor to deal in terms of ByteBuffer
  • Update tests

Result:

Avoid unconditonal copying of messages to/from [UInt8]/ByteBuffer

Motivation:

The core package added a bag-of-bytes protocol which transports must be
generic over. We need to adopt those changes here.

Modifications:

- Add a `GRPCNIOTransportBytes` type which wraps `ByteBuffer` and
  implements the `GRPCContiguousBytes` protocol.
- Use this as the bytes type for client/server transports.
- Update the appropriate state machines to deal in terms of `ByteBuffer`
- Update the compressor/decompressor to deal in terms of `ByteBuffer`
- Update tests

Result:

Avoid unconditonal copying of messages to/from `[UInt8]`/`ByteBuffer`
@glbrntt
Copy link
Collaborator Author

glbrntt commented Jan 14, 2025

This depends on and won't compile until grpc/grpc-swift#2155 is merged.

@glbrntt glbrntt added the ⚠️ semver/major Breaks existing public API. label Jan 14, 2025
public import NIOCore

/// The contiguous bytes type used by the gRPC's NIO transport.
public struct GRPCNIOTransportBytes: GRPCContiguousBytes, Hashable, Sendable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to wrap the ByteBuffer? Can we not conform it to GRPCContiguousBytes directly? Are we afraid the couple of methods we'd need to declare would clash with some future API added to it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping it gives us flexibility to change it in the future without breaking API.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - I didn't consider this because this package is already so tied to NIO (and I find it hard to believe we'd replace ByteBuffer on NIO anytime soon 😄). But that's fair.

@@ -105,7 +107,7 @@ extension HTTP2ClientTransport {
self.channel.retryThrottle
}

public func connect() async {
public func connect() async throws {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a regular Swift convention to keep the throws from the protocol signature if we don't actually throw in the implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there is a convention. The protocol is throws so adding it back isn't an issue and leaves us scope in the future in case the implementation actually needs to become throwing.

@gjcairo gjcairo marked this pull request as ready for review January 17, 2025 08:37
@gjcairo gjcairo marked this pull request as draft January 17, 2025 08:56
@gjcairo
Copy link
Collaborator

gjcairo commented Jan 17, 2025

Sorry, mistakenly clicked the not a draft anymore button

@glbrntt glbrntt marked this pull request as ready for review January 17, 2025 12:05
@glbrntt glbrntt requested a review from gjcairo January 17, 2025 12:07
@glbrntt glbrntt mentioned this pull request Jan 17, 2025
@glbrntt glbrntt merged commit 56defe6 into grpc:main Jan 17, 2025
21 of 28 checks passed
@glbrntt glbrntt deleted the new-serializer branch January 17, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ semver/major Breaks existing public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants