-
Notifications
You must be signed in to change notification settings - Fork 43
grpc: Add gzip Compression Support #527
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
grpc/grpc-client/src/commonMain/kotlin/kotlinx/rpc/grpc/client/GrpcCallOptions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
| */ | ||
|
|
||
| package kotlinx.rpc.grpc.client | ||
|
|
||
| import kotlinx.rpc.grpc.GrpcCompression | ||
| import kotlin.time.Duration | ||
|
|
||
| /** | ||
| * The collection of runtime options for a new gRPC call. | ||
| * | ||
| * This class allows configuring per-call behavior such as timeouts. | ||
| */ | ||
| public class GrpcCallOptions { | ||
| /** | ||
| * The maximum duration to wait for the RPC to complete. | ||
| * | ||
| * If set, the RPC will be canceled (with `DEADLINE_EXCEEDED`) | ||
| * if it does not complete within the specified duration. | ||
| * The timeout is measured from the moment the call is initiated. | ||
| * If `null`, no timeout is applied, and the call may run indefinitely. | ||
| * | ||
| * The default value is `null`. | ||
| * | ||
| * @see kotlin.time.Duration | ||
| */ | ||
| public var timeout: Duration? = null | ||
|
|
||
| /** | ||
| * The compression algorithm to use for encoding outgoing messages in this call. | ||
| * | ||
| * When set to a value other than [GrpcCompression.None], the client will compress request messages | ||
| * using the specified algorithm before sending them to the server. The chosen compression algorithm | ||
| * is communicated to the server via the `grpc-encoding` header. | ||
| * | ||
| * ## Default Behavior | ||
| * Defaults to [GrpcCompression.None], meaning no compression is applied to messages. | ||
| * | ||
| * ## Server Compatibility | ||
| * **Important**: It is the caller's responsibility to ensure the server supports the chosen | ||
| * compression algorithm. There is no automatic negotiation performed. If the server does not | ||
| * support the requested compression, the call will fail. | ||
| * | ||
| * ## Available Algorithms | ||
| * - [GrpcCompression.None]: No compression (identity encoding) - **default** | ||
| * - [GrpcCompression.Gzip]: GZIP compression, widely supported | ||
| * | ||
| * @see GrpcCompression | ||
| */ | ||
| public var compression: GrpcCompression = GrpcCompression.None | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
grpc/grpc-client/src/commonMain/kotlin/kotlinx/rpc/grpc/client/internal/GrpcCallOptions.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcCompression.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
| */ | ||
|
|
||
| package kotlinx.rpc.grpc | ||
|
|
||
| /** | ||
| * Represents a compression algorithm for gRPC message encoding. | ||
| * | ||
| * Compression can be applied to gRPC messages to reduce bandwidth usage during transmission. | ||
| * | ||
| * ## Supported Algorithms | ||
| * - [None] (identity): No compression is applied. | ||
| * - [Gzip]: GZIP compression algorithm, widely supported and provides good compression ratios. | ||
| * | ||
| * This interface is not meant to be implemented by users. | ||
| * | ||
| * @property name The compression algorithm identifier sent in the `grpc-encoding` header. | ||
| * | ||
| * @see kotlinx.rpc.grpc.client.GrpcCallOptions.compression | ||
| * @see GrpcCompression.None | ||
| * @see GrpcCompression.Gzip | ||
| */ | ||
| @OptIn(ExperimentalSubclassOptIn::class) | ||
| @SubclassOptInRequired | ||
| public interface GrpcCompression { | ||
|
|
||
| /** | ||
| * The name of the compression algorithm as it appears in the `grpc-encoding` header. | ||
| */ | ||
| public val name: String | ||
|
|
||
| /** | ||
| * Represents no compression (identity encoding). | ||
| * | ||
| * This is the default compression setting. When used, messages are transmitted without | ||
| * any compression applied. | ||
| */ | ||
| public object None : GrpcCompression { | ||
| override val name: String = "identity" | ||
| } | ||
|
|
||
| /** | ||
| * Represents GZIP compression. | ||
| * | ||
| * GZIP is a widely supported compression algorithm that provides good compression ratios | ||
| * for most data types. | ||
| * | ||
| * **Note**: Ensure the server supports GZIP compression before using this option, | ||
| * as the call will fail if the server cannot handle the requested compression algorithm. | ||
| */ | ||
| public object Gzip : GrpcCompression { | ||
| override val name: String = "gzip" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.