├── .github └── workflows │ └── go.yml ├── .gitignore ├── LICENSE ├── README.md ├── compress.go ├── example_test.go ├── go.mod ├── go.sum └── internal └── gen └── connect └── ping └── v1 ├── ping.pb.go └── pingv1connect └── ping.connect.go /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a golang project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go 3 | 4 | name: Go 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | jobs: 13 | 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - name: Set up Go 20 | uses: actions/setup-go@v3 21 | with: 22 | go-version: 1.20.x 23 | 24 | - name: Build 25 | run: go build -v ./... 26 | 27 | - name: Test 28 | run: go test -v ./... 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # connect-compress 2 | 3 | [![GoDoc](https://pkg.go.dev/badge/github.com/klauspost/connect-compress.svg)](https://pkg.go.dev/github.com/klauspost/connect-compress) 4 | 5 | This package provides improved compression schemes for [Connect](https://github.com/connectrpc/connect-go). 6 | 7 | Compression is provided from the [github.com/klauspost/compress](https://github.com/klauspost/compress) package. 8 | 9 | # Usage 10 | 11 | Import `github.com/klauspost/connect-compress/v2`. 12 | 13 | The `compress.WithAll` function will return an option that allows both client and servers to compress and decompress all 14 | formats. 15 | 16 | ``` 17 | // Get the client and server option for all compressors... 18 | opts := compress.WithAll(compress.LevelBalanced) 19 | 20 | // enable on server 21 | _, h := pingv1connect.NewPingServiceHandler(&pingServer{}, opts) 22 | 23 | // enable on client 24 | client := pingv1connect.NewPingServiceClient(http.DefaultClient, url, opts) 25 | 26 | ``` 27 | 28 | By default, the order of preference by the clients is S2, Snappy, Zstandard, Gzip. 29 | 30 | To enable client compression and force a specific method use `connect.WithSendCompression(...)` 31 | with one of the 4 provided compression options. 32 | 33 | * `S2` can be selected for transparent compression, since its performance impact is small. 34 | * `Snappy` can be used as a more platform independent alternative, with overall less compression. 35 | * `Zstandard` can be used for efficient compression at good speeds. 36 | * `Gzip` is the safe fallback. 37 | 38 | For more details and options see the [documentation](https://pkg.go.dev/github.com/klauspost/connect-compress). 39 | 40 | Note than when `OptSmallWindow` is used, it must be used on both the client and server. 41 | 42 | # Supported Formats 43 | 44 | For deeper information about the specific implementations 45 | see [github.com/klauspost/compress](https://github.com/klauspost/compress) project. 46 | 47 | All implementations in this package provides very fast handling of *incompressible* data. That means that it will impose 48 | only a minor penalty when sending pre-compressed data. 49 | 50 | ## Compression levels 51 | 52 | We expose 3 predefined compression levels. 53 | 54 | * `LevelFastest` will use the fastest available compression level. 55 | * `LevelBalanced` will use a balanced compression level. Typically half as fast as `LevelFastest`. 56 | * `LevelSmallest` will use the strongest and most resource intensive compression method. This is generally not recommended. 57 | 58 | General selection criteria: 59 | 60 | * Select balanced as your default choice. 61 | * Select the fastest when you expect to transfer large amounts of data locally. 62 | * Select the smallest when transferring via WAN and you have limited bandwidth. 63 | 64 | ## S2 65 | 66 | [S2](https://github.com/klauspost/compress/tree/master/s2#s2-compression) provides better compression than Snappy at 67 | similar or better speeds. 68 | 69 | Expected performance is ~750MB/s on JSON streams. Size ~2% bigger than gzip on JSON stream. 70 | 71 | Approximate speeds on different data types. Compression only, single thread: 72 | 73 | | | JSON | Binary | Objects | Incompressible | 74 | |---------------------|---------|--------|---------|----------------| 75 | | Fastest, MB/s | 1145.57 | 902.15 | 1054.89 | 5520.22 | 76 | | Fastest, Reduction | 83.40% | 66.51% | 81.81% | 0.00% | 77 | | Balanced, MB/s | 773.94 | 509.71 | 721.64 | 4413.79 | 78 | | Balanced, Reduction | 84.79% | 69.74% | 83.85% | 0.00% | 79 | | Smallest, MB/s | 59.66 | 29.87 | 58.59 | 630.93 | 80 | | Smallest, Reduction | 86.75% | 70.24% | 86.30% | 0.00% | 81 | 82 | With `OptAllowMultithreadedCompression` all cores can used for a roughly linear speed improvement. 83 | 84 | ## Snappy 85 | 86 | [Snappy](https://github.com/google/snappy) uses Google snappy format. 87 | 88 | Expected performance is ~600MB/s on JSON streams. Size ~50% bigger than gzip on JSON stream. 89 | 90 | Approximate speeds on different data types. Compression only, single thread: 91 | 92 | | | JSON | Binary | Objects | Incompressible | 93 | |---------------------|---------|--------|---------|----------------| 94 | | Fastest, MB/s | 1004.25 | 959.14 | 1041.04 | 4511.01 | 95 | | Fastest, Reduction | 76.47% | 65.79% | 75.77% | -0.01% | 96 | | Balanced, MB/s | 599.05 | 536.50 | 595.51 | 2298.54 | 97 | | Balanced, Reduction | 77.68% | 68.81% | 77.46% | -0.01% | 98 | | Smallest, MB/s | 68.50 | 57.75 | 70.55 | 216.17 | 99 | | Smallest, Reduction | 78.93% | 69.09% | 78.58% | -0.01% | 100 | 101 | With `OptAllowMultithreadedCompression` all cores can used for a roughly linear speed improvement. 102 | 103 | Decompression will usually be limited at around 1000MB/s. 104 | 105 | `OptSmallWindow` has no effect on Snappy, since it is limited to 64KB window already. 106 | 107 | ## Zstandard 108 | 109 | [Zstandard](https://github.com/facebook/zstd) uses Zstandard compression, but with limited window sizes. Generally 110 | Zstandard compresses better and is faster than gzip. 111 | 112 | Expected performance is ~300MB/s on JSON streams. Size ~35% smaller than gzip on JSON stream. 113 | 114 | Approximate speeds on different data types. Compression only, single thread: 115 | 116 | | | JSON | Binary | Objects | Incompressible | 117 | |---------------------|--------|--------|---------|----------------| 118 | | Fastest, MB/s | 611.23 | 395.09 | 564.35 | 2836.57 | 119 | | Fastest, Reduction | 88.88% | 75.62% | 87.76% | 0.00% | 120 | | Balanced, MB/s | 322.50 | 155.23 | 364.79 | 2066.60 | 121 | | Balanced, Reduction | 90.26% | 77.56% | 89.33% | 0.00% | 122 | | Smallest, MB/s | 36.18 | 14.42 | 38.33 | 172.43 | 123 | | Smallest, Reduction | 92.59% | 79.40% | 91.51% | 0.00% | 124 | 125 | With `OptAllowMultithreadedCompression` typically 2 goroutines will be used. 126 | 127 | Generally decompression should be able to keep up with compression speed. 128 | 129 | ## Gzip 130 | 131 | Gzip provides faster compression and decompression methods than the standard library built-in to go-connect. 132 | 133 | Expected performance is ~200MB/s on JSON streams. Size reduction is ~85% on JSON stream. 134 | 135 | Approximate speeds on different data types. Compression only, single thread: 136 | 137 | | | JSON | Binary | Objects | Incompressible | 138 | |---------------------|--------|--------|---------|----------------| 139 | | Fastest, MB/s | 338.17 | 263.55 | 373.15 | 6460.57 | 140 | | Fastest, Reduction | 82.14% | 75.40% | 81.21% | -0.01% | 141 | | Balanced, MB/s | 206.04 | 148.05 | 215.19 | 5535.14 | 142 | | Balanced, Reduction | 84.97% | 76.64% | 83.96% | -0.01% | 143 | | Smallest, MB/s | 59.09 | 18.21 | 46.44 | 119.81 | 144 | | Smallest, Reduction | 85.70% | 76.60% | 85.47% | -0.02% | 145 | 146 | Note that Gzip decompression speed can often be below 200MB/s, so this will impose the practical limit. 147 | 148 | Gzip, stdlib as available in `go-connect` for reference: 149 | 150 | | | JSON | Binary | Objects | Incompressible | 151 | |--------------------|--------|--------|---------|----------------| 152 | | MB/s | 96.05 | 45.61 | 89.93 | 62.74 | 153 | | Reduction | 85.61% | 76.62% | 85.01% | -0.03% | 154 | 155 | `OptSmallWindow` has no effect on gzip, since it is limited to a 32KB window already. 156 | 157 | 158 | # License 159 | 160 | This package is made available with the Apache License Version 2.0 161 | 162 | See LICENSE for more information. 163 | -------------------------------------------------------------------------------- /compress.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Klaus Post. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package compress 16 | 17 | import ( 18 | "fmt" 19 | "io" 20 | 21 | "connectrpc.com/connect" 22 | "github.com/klauspost/compress/gzip" 23 | "github.com/klauspost/compress/s2" 24 | "github.com/klauspost/compress/zstd" 25 | ) 26 | 27 | // Level provides 3 predefined compression levels. 28 | type Level int 29 | 30 | const ( 31 | // LevelFastest will choose the least cpu intensive cpu method. 32 | LevelFastest Level = iota 33 | 34 | // LevelBalanced provides balanced compression. 35 | // Typical cpu usage will be around 200% of the fastest setting. 36 | LevelBalanced 37 | 38 | // LevelSmallest will use the strongest and most resource intensive 39 | // compression method. 40 | // This is generally not recommended. 41 | LevelSmallest 42 | ) 43 | 44 | const ( 45 | // Gzip provides faster compression methods than the standard library 46 | // built-in to go-connect. 47 | // Expected performance is ~200MB/s on JSON streams. 48 | // Size reduction is ~85% on JSON stream. 49 | Gzip = "gzip" 50 | 51 | // Zstandard uses Zstandard compression, 52 | // but with limited window sizes. 53 | // Generally Zstandard compresses better and is faster than gzip. 54 | // Expected performance is ~300MB/s on JSON streams. 55 | // Size ~35% smaller than gzip on JSON stream. 56 | Zstandard = "zstd" 57 | 58 | // Snappy uses Google snappy format. 59 | // Expected performance is ~550MB/s on JSON streams. 60 | // Size ~50% bigger than gzip on JSON stream. 61 | Snappy = "snappy" 62 | 63 | // S2 provides better compression than Snappy at similar or better speeds. 64 | // Expected performance is ~750MB/s on JSON streams. 65 | // Size ~2% bigger than gzip on JSON stream. 66 | S2 = "s2" 67 | ) 68 | 69 | // Opts provides options 70 | type Opts uint32 71 | 72 | func (o Opts) contains(x Opts) bool { 73 | return o&x == x 74 | } 75 | 76 | // maxLimitedWindow is the window limit. 77 | const maxLimitedWindow = 64 << 10 78 | 79 | const ( 80 | // OptStatelessGzip will force gzip compression to be stateless. 81 | // Since each Write call will compress input this will affect compression ratio 82 | // and should only be used when Write calls are controlled. 83 | // Typically, this means a buffer should be inserted on the writer. 84 | // See https://github.com/klauspost/compress#stateless-compression 85 | // Compression level will be ignored. 86 | OptStatelessGzip Opts = 1 << iota 87 | 88 | // OptAllowMultithreadedCompression will allow some compression modes to use multiple goroutines. 89 | OptAllowMultithreadedCompression 90 | 91 | // OptSmallWindow will limit the compression window to 64KB. 92 | // This will reduce memory usage of running operations, 93 | // but also make compression worse. 94 | OptSmallWindow 95 | 96 | // internal snappy option 97 | optSnappy 98 | ) 99 | 100 | type compressorOption struct { 101 | connect.ClientOption 102 | connect.HandlerOption 103 | } 104 | 105 | // WithAll returns the client and handler option for all compression methods. 106 | // Order of preference is S2, Snappy, Zstandard, Gzip. 107 | func WithAll(level Level, options ...Opts) connect.Option { 108 | var opts []connect.Option 109 | 110 | for _, name := range []string{Gzip, Zstandard, Snappy, S2} { 111 | opts = append(opts, WithNew(name, level, options...)) 112 | } 113 | return connect.WithOptions(opts...) 114 | } 115 | 116 | // WithNew returns client and handler options for a single compression method. 117 | // Name must be one of the predefined in this package. 118 | func WithNew(name string, level Level, options ...Opts) connect.Option { 119 | var o Opts 120 | for _, opt := range options { 121 | o = o | opt 122 | } 123 | var d func() connect.Decompressor 124 | var c func() connect.Compressor 125 | switch name { 126 | case Gzip: 127 | d, c = gzComp(level, o) 128 | case Zstandard: 129 | d, c = zstdComp(level, o) 130 | case Snappy: 131 | o |= optSnappy 132 | d, c = s2Comp(level, o) 133 | case S2: 134 | d, c = s2Comp(level, o) 135 | default: 136 | panic(fmt.Errorf("unknown compression name: %s", name)) 137 | } 138 | return &compressorOption{ 139 | ClientOption: connect.WithAcceptCompression(name, d, c), 140 | HandlerOption: connect.WithCompression(name, d, c), 141 | } 142 | } 143 | 144 | func gzComp(level Level, o Opts) (d func() connect.Decompressor, c func() connect.Compressor) { 145 | return func() connect.Decompressor { 146 | return &gzip.Reader{} 147 | }, func() connect.Compressor { 148 | if o.contains(OptStatelessGzip) { 149 | gz, _ := gzip.NewWriterLevel(io.Discard, gzip.StatelessCompression) 150 | return gz 151 | } 152 | switch level { 153 | case LevelFastest: 154 | gz, _ := gzip.NewWriterLevel(io.Discard, 1) 155 | return gz 156 | case LevelBalanced: 157 | gz, _ := gzip.NewWriterLevel(io.Discard, 5) 158 | return gz 159 | case LevelSmallest: 160 | gz, _ := gzip.NewWriterLevel(io.Discard, 9) 161 | return gz 162 | } 163 | return gzip.NewWriter(io.Discard) 164 | } 165 | } 166 | 167 | func zstdComp(level Level, o Opts) (d func() connect.Decompressor, c func() connect.Compressor) { 168 | copts := []zstd.EOption{zstd.WithLowerEncoderMem(true)} 169 | dopts := []zstd.DOption{zstd.WithDecoderLowmem(true), zstd.WithDecoderConcurrency(1)} 170 | if o.contains(OptSmallWindow) { 171 | dopts = append(dopts, zstd.WithDecoderMaxWindow(64<<10)) 172 | } 173 | 174 | if o.contains(OptAllowMultithreadedCompression) { 175 | // No need to go over board here. 176 | copts = append(copts, zstd.WithEncoderConcurrency(4)) 177 | } else { 178 | copts = append(copts, zstd.WithEncoderConcurrency(1)) 179 | } 180 | 181 | switch level { 182 | case LevelFastest: 183 | copts = append(copts, zstd.WithEncoderLevel(zstd.SpeedFastest)) 184 | if o.contains(OptSmallWindow) { 185 | copts = append(copts, zstd.WithWindowSize(64<<10)) 186 | } else { 187 | copts = append(copts, zstd.WithWindowSize(1<<20)) 188 | } 189 | case LevelBalanced: 190 | copts = append(copts, zstd.WithEncoderLevel(zstd.SpeedDefault)) 191 | if o.contains(OptSmallWindow) { 192 | copts = append(copts, zstd.WithWindowSize(64<<10)) 193 | } else { 194 | copts = append(copts, zstd.WithWindowSize(1<<20)) 195 | } 196 | case LevelSmallest: 197 | copts = append(copts, zstd.WithEncoderLevel(zstd.SpeedBestCompression)) 198 | if o.contains(OptSmallWindow) { 199 | copts = append(copts, zstd.WithWindowSize(64<<10)) 200 | } else { 201 | copts = append(copts, zstd.WithWindowSize(4<<20)) 202 | } 203 | } 204 | return func() connect.Decompressor { 205 | zs, _ := zstd.NewReader(nil, dopts...) 206 | return &zstdWrapper{ReadCloser: zs.IOReadCloser(), dec: zs} 207 | }, func() connect.Compressor { 208 | zs, _ := zstd.NewWriter(nil, copts...) 209 | return zs 210 | } 211 | } 212 | 213 | type zstdWrapper struct { 214 | io.ReadCloser 215 | dec *zstd.Decoder 216 | } 217 | 218 | func (z *zstdWrapper) Reset(reader io.Reader) error { 219 | return z.dec.Reset(reader) 220 | } 221 | 222 | func s2Comp(level Level, o Opts) (d func() connect.Decompressor, c func() connect.Compressor) { 223 | var wopts []s2.WriterOption 224 | var ropts []s2.ReaderOption 225 | if o.contains(optSnappy) { 226 | wopts = append(wopts, s2.WriterSnappyCompat()) 227 | ropts = append(ropts, s2.ReaderMaxBlockSize(maxLimitedWindow), s2.ReaderAllocBlock(maxLimitedWindow)) 228 | } else if o.contains(OptSmallWindow) { 229 | wopts = append(wopts, s2.WriterBlockSize(maxLimitedWindow)) 230 | ropts = append(ropts, s2.ReaderMaxBlockSize(maxLimitedWindow), s2.ReaderAllocBlock(maxLimitedWindow)) 231 | } 232 | 233 | if !o.contains(OptAllowMultithreadedCompression) { 234 | wopts = append(wopts, s2.WriterConcurrency(1)) 235 | } 236 | 237 | switch level { 238 | case LevelFastest: 239 | case LevelBalanced: 240 | wopts = append(wopts, s2.WriterBetterCompression()) 241 | case LevelSmallest: 242 | wopts = append(wopts, s2.WriterBestCompression()) 243 | if !o.contains(OptSmallWindow) && !o.contains(optSnappy) { 244 | wopts = append(wopts, s2.WriterBlockSize(4<<20)) 245 | } 246 | } 247 | 248 | return func() connect.Decompressor { 249 | dec := s2.NewReader(nil, ropts...) 250 | return &s2rWrapper{dec: dec} 251 | }, func() connect.Compressor { 252 | return s2.NewWriter(nil, wopts...) 253 | } 254 | } 255 | 256 | type s2rWrapper struct { 257 | dec *s2.Reader 258 | } 259 | 260 | func (s *s2rWrapper) Read(p []byte) (n int, err error) { 261 | return s.dec.Read(p) 262 | } 263 | 264 | func (s *s2rWrapper) Close() error { 265 | s.dec.Reset(nil) 266 | return nil 267 | } 268 | 269 | func (s *s2rWrapper) Reset(reader io.Reader) error { 270 | s.dec.Reset(reader) 271 | return nil 272 | } 273 | -------------------------------------------------------------------------------- /example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Klaus Post. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package compress_test 16 | 17 | import ( 18 | "context" 19 | "fmt" 20 | "log" 21 | "net/http" 22 | "net/http/httptest" 23 | 24 | "connectrpc.com/connect" 25 | "github.com/klauspost/connect-compress/v2" 26 | pingv1 "github.com/klauspost/connect-compress/v2/internal/gen/connect/ping/v1" 27 | "github.com/klauspost/connect-compress/v2/internal/gen/connect/ping/v1/pingv1connect" 28 | ) 29 | 30 | func ExampleWithAll() { 31 | // Get the client and server option for all compressors... 32 | opts := compress.WithAll(compress.LevelBalanced) 33 | 34 | // Create a server. 35 | _, h := pingv1connect.NewPingServiceHandler(&pingServer{}, opts) 36 | srv := httptest.NewServer(h) 37 | client := pingv1connect.NewPingServiceClient( 38 | http.DefaultClient, 39 | srv.URL, 40 | opts, 41 | // Compress requests with S2. 42 | connect.WithSendCompression(compress.S2), 43 | ) 44 | req := connect.NewRequest(&pingv1.PingRequest{ 45 | Number: 42, 46 | }) 47 | req.Header().Set("Some-Header", "hello from connect") 48 | res, err := client.Ping(context.Background(), req) 49 | if err != nil { 50 | log.Fatalln(err) 51 | } 52 | fmt.Println("The answer is", res.Msg) 53 | fmt.Println(res.Header().Get("Some-Other-Header")) 54 | //OUTPUT: 55 | //hello from connect 56 | //The answer is number:42 57 | //hello! 58 | } 59 | 60 | func ExampleSelect() { 61 | // Add Zstandard. 62 | opt := compress.WithNew(compress.Zstandard, compress.LevelBalanced) 63 | _, h := pingv1connect.NewPingServiceHandler(&pingServer{}, opt) 64 | srv := httptest.NewServer(h) 65 | client := pingv1connect.NewPingServiceClient( 66 | http.DefaultClient, 67 | srv.URL, 68 | opt, 69 | // Enable request compression 70 | connect.WithSendCompression(compress.Zstandard), 71 | ) 72 | req := connect.NewRequest(&pingv1.PingRequest{ 73 | Number: 42, 74 | }) 75 | req.Header().Set("Some-Header", "hello from connect") 76 | res, err := client.Ping(context.Background(), req) 77 | if err != nil { 78 | log.Fatalln(err) 79 | } 80 | fmt.Println("The answer is", res.Msg) 81 | fmt.Println(res.Header().Get("Some-Other-Header")) 82 | //OUTPUT: 83 | //hello from connect 84 | //The answer is number:42 85 | //hello! 86 | } 87 | 88 | func ExampleSelect2() { 89 | // Add Zstandard. 90 | opt := compress.WithNew(compress.Snappy, compress.LevelBalanced) 91 | _, h := pingv1connect.NewPingServiceHandler(&pingServer{}, opt) 92 | srv := httptest.NewServer(h) 93 | client := pingv1connect.NewPingServiceClient( 94 | http.DefaultClient, 95 | srv.URL, 96 | opt, 97 | // Enable request compression 98 | connect.WithSendCompression(compress.Snappy), 99 | ) 100 | req := connect.NewRequest(&pingv1.PingRequest{ 101 | Number: 42, 102 | }) 103 | req.Header().Set("Some-Header", "hello from connect") 104 | res, err := client.Ping(context.Background(), req) 105 | if err != nil { 106 | log.Fatalln(err) 107 | } 108 | fmt.Println("The answer is", res.Msg) 109 | fmt.Println(res.Header().Get("Some-Other-Header")) 110 | //OUTPUT: 111 | //hello from connect 112 | //The answer is number:42 113 | //hello! 114 | } 115 | 116 | func ExampleSelect3() { 117 | // Add Zstandard. 118 | opt := compress.WithNew(compress.S2, compress.LevelBalanced) 119 | _, h := pingv1connect.NewPingServiceHandler(&pingServer{}, opt) 120 | srv := httptest.NewServer(h) 121 | client := pingv1connect.NewPingServiceClient( 122 | http.DefaultClient, 123 | srv.URL, 124 | opt, 125 | // Enable request compression 126 | connect.WithSendCompression(compress.S2), 127 | ) 128 | req := connect.NewRequest(&pingv1.PingRequest{ 129 | Number: 42, 130 | }) 131 | req.Header().Set("Some-Header", "hello from connect") 132 | res, err := client.Ping(context.Background(), req) 133 | if err != nil { 134 | log.Fatalln(err) 135 | } 136 | fmt.Println("The answer is", res.Msg) 137 | fmt.Println(res.Header().Get("Some-Other-Header")) 138 | //OUTPUT: 139 | //hello from connect 140 | //The answer is number:42 141 | //hello! 142 | } 143 | 144 | func ExampleSelect4() { 145 | // Add Zstandard. 146 | opt := compress.WithNew(compress.Gzip, compress.LevelBalanced) 147 | _, h := pingv1connect.NewPingServiceHandler(&pingServer{}, opt) 148 | srv := httptest.NewServer(h) 149 | client := pingv1connect.NewPingServiceClient( 150 | http.DefaultClient, 151 | srv.URL, 152 | opt, 153 | // Enable request compression 154 | connect.WithSendCompression(compress.Gzip), 155 | ) 156 | req := connect.NewRequest(&pingv1.PingRequest{ 157 | Number: 42, 158 | }) 159 | req.Header().Set("Some-Header", "hello from connect") 160 | res, err := client.Ping(context.Background(), req) 161 | if err != nil { 162 | log.Fatalln(err) 163 | } 164 | fmt.Println("The answer is", res.Msg) 165 | fmt.Println(res.Header().Get("Some-Other-Header")) 166 | //OUTPUT: 167 | //hello from connect 168 | //The answer is number:42 169 | //hello! 170 | } 171 | 172 | type pingServer struct { 173 | pingv1connect.UnimplementedPingServiceHandler // returns errors from all methods 174 | } 175 | 176 | func (ps *pingServer) Ping( 177 | ctx context.Context, 178 | req *connect.Request[pingv1.PingRequest], 179 | ) (*connect.Response[pingv1.PingResponse], error) { 180 | // connect.Request and connect.Response give you direct access to headers and 181 | // trailers. No context-based nonsense! 182 | fmt.Println(req.Header().Get("Some-Header")) 183 | res := connect.NewResponse(&pingv1.PingResponse{ 184 | // req.Msg is a strongly-typed *pingv1.PingRequest, so we can access its 185 | // fields without type assertions. 186 | Number: req.Msg.Number, 187 | }) 188 | res.Header().Set("Some-Other-Header", "hello!") 189 | return res, nil 190 | } 191 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/klauspost/connect-compress/v2 2 | 3 | go 1.18 4 | 5 | require ( 6 | connectrpc.com/connect v1.11.0 7 | github.com/klauspost/compress v1.16.7 8 | google.golang.org/protobuf v1.31.0 9 | ) 10 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | connectrpc.com/connect v1.11.0 h1:Av2KQXxSaX4vjqhf5Cl01SX4dqYADQ38eBtr84JSUBk= 2 | connectrpc.com/connect v1.11.0/go.mod h1:3AGaO6RRGMx5IKFfqbe3hvK1NqLosFNP2BxDYTPmNPo= 3 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 4 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 5 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 6 | github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= 7 | github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= 8 | github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= 9 | github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= 10 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 11 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 12 | google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= 13 | google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 14 | -------------------------------------------------------------------------------- /internal/gen/connect/ping/v1/ping.pb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2022 Buf Technologies, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Code generated by protoc-gen-go. DO NOT EDIT. 16 | // versions: 17 | // protoc-gen-go v1.28.0 18 | // protoc (unknown) 19 | // source: connect/ping/v1/ping.proto 20 | 21 | package pingv1 22 | 23 | import ( 24 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 25 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 26 | reflect "reflect" 27 | sync "sync" 28 | ) 29 | 30 | const ( 31 | // Verify that this generated code is sufficiently up-to-date. 32 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 33 | // Verify that runtime/protoimpl is sufficiently up-to-date. 34 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 35 | ) 36 | 37 | type PingRequest struct { 38 | state protoimpl.MessageState 39 | sizeCache protoimpl.SizeCache 40 | unknownFields protoimpl.UnknownFields 41 | 42 | Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` 43 | Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"` 44 | } 45 | 46 | func (x *PingRequest) Reset() { 47 | *x = PingRequest{} 48 | if protoimpl.UnsafeEnabled { 49 | mi := &file_connect_ping_v1_ping_proto_msgTypes[0] 50 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 51 | ms.StoreMessageInfo(mi) 52 | } 53 | } 54 | 55 | func (x *PingRequest) String() string { 56 | return protoimpl.X.MessageStringOf(x) 57 | } 58 | 59 | func (*PingRequest) ProtoMessage() {} 60 | 61 | func (x *PingRequest) ProtoReflect() protoreflect.Message { 62 | mi := &file_connect_ping_v1_ping_proto_msgTypes[0] 63 | if protoimpl.UnsafeEnabled && x != nil { 64 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 65 | if ms.LoadMessageInfo() == nil { 66 | ms.StoreMessageInfo(mi) 67 | } 68 | return ms 69 | } 70 | return mi.MessageOf(x) 71 | } 72 | 73 | // Deprecated: Use PingRequest.ProtoReflect.Descriptor instead. 74 | func (*PingRequest) Descriptor() ([]byte, []int) { 75 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{0} 76 | } 77 | 78 | func (x *PingRequest) GetNumber() int64 { 79 | if x != nil { 80 | return x.Number 81 | } 82 | return 0 83 | } 84 | 85 | func (x *PingRequest) GetText() string { 86 | if x != nil { 87 | return x.Text 88 | } 89 | return "" 90 | } 91 | 92 | type PingResponse struct { 93 | state protoimpl.MessageState 94 | sizeCache protoimpl.SizeCache 95 | unknownFields protoimpl.UnknownFields 96 | 97 | Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` 98 | Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"` 99 | } 100 | 101 | func (x *PingResponse) Reset() { 102 | *x = PingResponse{} 103 | if protoimpl.UnsafeEnabled { 104 | mi := &file_connect_ping_v1_ping_proto_msgTypes[1] 105 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 106 | ms.StoreMessageInfo(mi) 107 | } 108 | } 109 | 110 | func (x *PingResponse) String() string { 111 | return protoimpl.X.MessageStringOf(x) 112 | } 113 | 114 | func (*PingResponse) ProtoMessage() {} 115 | 116 | func (x *PingResponse) ProtoReflect() protoreflect.Message { 117 | mi := &file_connect_ping_v1_ping_proto_msgTypes[1] 118 | if protoimpl.UnsafeEnabled && x != nil { 119 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 120 | if ms.LoadMessageInfo() == nil { 121 | ms.StoreMessageInfo(mi) 122 | } 123 | return ms 124 | } 125 | return mi.MessageOf(x) 126 | } 127 | 128 | // Deprecated: Use PingResponse.ProtoReflect.Descriptor instead. 129 | func (*PingResponse) Descriptor() ([]byte, []int) { 130 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{1} 131 | } 132 | 133 | func (x *PingResponse) GetNumber() int64 { 134 | if x != nil { 135 | return x.Number 136 | } 137 | return 0 138 | } 139 | 140 | func (x *PingResponse) GetText() string { 141 | if x != nil { 142 | return x.Text 143 | } 144 | return "" 145 | } 146 | 147 | type FailRequest struct { 148 | state protoimpl.MessageState 149 | sizeCache protoimpl.SizeCache 150 | unknownFields protoimpl.UnknownFields 151 | 152 | Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` 153 | } 154 | 155 | func (x *FailRequest) Reset() { 156 | *x = FailRequest{} 157 | if protoimpl.UnsafeEnabled { 158 | mi := &file_connect_ping_v1_ping_proto_msgTypes[2] 159 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 160 | ms.StoreMessageInfo(mi) 161 | } 162 | } 163 | 164 | func (x *FailRequest) String() string { 165 | return protoimpl.X.MessageStringOf(x) 166 | } 167 | 168 | func (*FailRequest) ProtoMessage() {} 169 | 170 | func (x *FailRequest) ProtoReflect() protoreflect.Message { 171 | mi := &file_connect_ping_v1_ping_proto_msgTypes[2] 172 | if protoimpl.UnsafeEnabled && x != nil { 173 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 174 | if ms.LoadMessageInfo() == nil { 175 | ms.StoreMessageInfo(mi) 176 | } 177 | return ms 178 | } 179 | return mi.MessageOf(x) 180 | } 181 | 182 | // Deprecated: Use FailRequest.ProtoReflect.Descriptor instead. 183 | func (*FailRequest) Descriptor() ([]byte, []int) { 184 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{2} 185 | } 186 | 187 | func (x *FailRequest) GetCode() int32 { 188 | if x != nil { 189 | return x.Code 190 | } 191 | return 0 192 | } 193 | 194 | type FailResponse struct { 195 | state protoimpl.MessageState 196 | sizeCache protoimpl.SizeCache 197 | unknownFields protoimpl.UnknownFields 198 | } 199 | 200 | func (x *FailResponse) Reset() { 201 | *x = FailResponse{} 202 | if protoimpl.UnsafeEnabled { 203 | mi := &file_connect_ping_v1_ping_proto_msgTypes[3] 204 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 205 | ms.StoreMessageInfo(mi) 206 | } 207 | } 208 | 209 | func (x *FailResponse) String() string { 210 | return protoimpl.X.MessageStringOf(x) 211 | } 212 | 213 | func (*FailResponse) ProtoMessage() {} 214 | 215 | func (x *FailResponse) ProtoReflect() protoreflect.Message { 216 | mi := &file_connect_ping_v1_ping_proto_msgTypes[3] 217 | if protoimpl.UnsafeEnabled && x != nil { 218 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 219 | if ms.LoadMessageInfo() == nil { 220 | ms.StoreMessageInfo(mi) 221 | } 222 | return ms 223 | } 224 | return mi.MessageOf(x) 225 | } 226 | 227 | // Deprecated: Use FailResponse.ProtoReflect.Descriptor instead. 228 | func (*FailResponse) Descriptor() ([]byte, []int) { 229 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{3} 230 | } 231 | 232 | type SumRequest struct { 233 | state protoimpl.MessageState 234 | sizeCache protoimpl.SizeCache 235 | unknownFields protoimpl.UnknownFields 236 | 237 | Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` 238 | } 239 | 240 | func (x *SumRequest) Reset() { 241 | *x = SumRequest{} 242 | if protoimpl.UnsafeEnabled { 243 | mi := &file_connect_ping_v1_ping_proto_msgTypes[4] 244 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 245 | ms.StoreMessageInfo(mi) 246 | } 247 | } 248 | 249 | func (x *SumRequest) String() string { 250 | return protoimpl.X.MessageStringOf(x) 251 | } 252 | 253 | func (*SumRequest) ProtoMessage() {} 254 | 255 | func (x *SumRequest) ProtoReflect() protoreflect.Message { 256 | mi := &file_connect_ping_v1_ping_proto_msgTypes[4] 257 | if protoimpl.UnsafeEnabled && x != nil { 258 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 259 | if ms.LoadMessageInfo() == nil { 260 | ms.StoreMessageInfo(mi) 261 | } 262 | return ms 263 | } 264 | return mi.MessageOf(x) 265 | } 266 | 267 | // Deprecated: Use SumRequest.ProtoReflect.Descriptor instead. 268 | func (*SumRequest) Descriptor() ([]byte, []int) { 269 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{4} 270 | } 271 | 272 | func (x *SumRequest) GetNumber() int64 { 273 | if x != nil { 274 | return x.Number 275 | } 276 | return 0 277 | } 278 | 279 | type SumResponse struct { 280 | state protoimpl.MessageState 281 | sizeCache protoimpl.SizeCache 282 | unknownFields protoimpl.UnknownFields 283 | 284 | Sum int64 `protobuf:"varint,1,opt,name=sum,proto3" json:"sum,omitempty"` 285 | } 286 | 287 | func (x *SumResponse) Reset() { 288 | *x = SumResponse{} 289 | if protoimpl.UnsafeEnabled { 290 | mi := &file_connect_ping_v1_ping_proto_msgTypes[5] 291 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 292 | ms.StoreMessageInfo(mi) 293 | } 294 | } 295 | 296 | func (x *SumResponse) String() string { 297 | return protoimpl.X.MessageStringOf(x) 298 | } 299 | 300 | func (*SumResponse) ProtoMessage() {} 301 | 302 | func (x *SumResponse) ProtoReflect() protoreflect.Message { 303 | mi := &file_connect_ping_v1_ping_proto_msgTypes[5] 304 | if protoimpl.UnsafeEnabled && x != nil { 305 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 306 | if ms.LoadMessageInfo() == nil { 307 | ms.StoreMessageInfo(mi) 308 | } 309 | return ms 310 | } 311 | return mi.MessageOf(x) 312 | } 313 | 314 | // Deprecated: Use SumResponse.ProtoReflect.Descriptor instead. 315 | func (*SumResponse) Descriptor() ([]byte, []int) { 316 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{5} 317 | } 318 | 319 | func (x *SumResponse) GetSum() int64 { 320 | if x != nil { 321 | return x.Sum 322 | } 323 | return 0 324 | } 325 | 326 | type CountUpRequest struct { 327 | state protoimpl.MessageState 328 | sizeCache protoimpl.SizeCache 329 | unknownFields protoimpl.UnknownFields 330 | 331 | Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` 332 | } 333 | 334 | func (x *CountUpRequest) Reset() { 335 | *x = CountUpRequest{} 336 | if protoimpl.UnsafeEnabled { 337 | mi := &file_connect_ping_v1_ping_proto_msgTypes[6] 338 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 339 | ms.StoreMessageInfo(mi) 340 | } 341 | } 342 | 343 | func (x *CountUpRequest) String() string { 344 | return protoimpl.X.MessageStringOf(x) 345 | } 346 | 347 | func (*CountUpRequest) ProtoMessage() {} 348 | 349 | func (x *CountUpRequest) ProtoReflect() protoreflect.Message { 350 | mi := &file_connect_ping_v1_ping_proto_msgTypes[6] 351 | if protoimpl.UnsafeEnabled && x != nil { 352 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 353 | if ms.LoadMessageInfo() == nil { 354 | ms.StoreMessageInfo(mi) 355 | } 356 | return ms 357 | } 358 | return mi.MessageOf(x) 359 | } 360 | 361 | // Deprecated: Use CountUpRequest.ProtoReflect.Descriptor instead. 362 | func (*CountUpRequest) Descriptor() ([]byte, []int) { 363 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{6} 364 | } 365 | 366 | func (x *CountUpRequest) GetNumber() int64 { 367 | if x != nil { 368 | return x.Number 369 | } 370 | return 0 371 | } 372 | 373 | type CountUpResponse struct { 374 | state protoimpl.MessageState 375 | sizeCache protoimpl.SizeCache 376 | unknownFields protoimpl.UnknownFields 377 | 378 | Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` 379 | } 380 | 381 | func (x *CountUpResponse) Reset() { 382 | *x = CountUpResponse{} 383 | if protoimpl.UnsafeEnabled { 384 | mi := &file_connect_ping_v1_ping_proto_msgTypes[7] 385 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 386 | ms.StoreMessageInfo(mi) 387 | } 388 | } 389 | 390 | func (x *CountUpResponse) String() string { 391 | return protoimpl.X.MessageStringOf(x) 392 | } 393 | 394 | func (*CountUpResponse) ProtoMessage() {} 395 | 396 | func (x *CountUpResponse) ProtoReflect() protoreflect.Message { 397 | mi := &file_connect_ping_v1_ping_proto_msgTypes[7] 398 | if protoimpl.UnsafeEnabled && x != nil { 399 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 400 | if ms.LoadMessageInfo() == nil { 401 | ms.StoreMessageInfo(mi) 402 | } 403 | return ms 404 | } 405 | return mi.MessageOf(x) 406 | } 407 | 408 | // Deprecated: Use CountUpResponse.ProtoReflect.Descriptor instead. 409 | func (*CountUpResponse) Descriptor() ([]byte, []int) { 410 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{7} 411 | } 412 | 413 | func (x *CountUpResponse) GetNumber() int64 { 414 | if x != nil { 415 | return x.Number 416 | } 417 | return 0 418 | } 419 | 420 | type CumSumRequest struct { 421 | state protoimpl.MessageState 422 | sizeCache protoimpl.SizeCache 423 | unknownFields protoimpl.UnknownFields 424 | 425 | Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"` 426 | } 427 | 428 | func (x *CumSumRequest) Reset() { 429 | *x = CumSumRequest{} 430 | if protoimpl.UnsafeEnabled { 431 | mi := &file_connect_ping_v1_ping_proto_msgTypes[8] 432 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 433 | ms.StoreMessageInfo(mi) 434 | } 435 | } 436 | 437 | func (x *CumSumRequest) String() string { 438 | return protoimpl.X.MessageStringOf(x) 439 | } 440 | 441 | func (*CumSumRequest) ProtoMessage() {} 442 | 443 | func (x *CumSumRequest) ProtoReflect() protoreflect.Message { 444 | mi := &file_connect_ping_v1_ping_proto_msgTypes[8] 445 | if protoimpl.UnsafeEnabled && x != nil { 446 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 447 | if ms.LoadMessageInfo() == nil { 448 | ms.StoreMessageInfo(mi) 449 | } 450 | return ms 451 | } 452 | return mi.MessageOf(x) 453 | } 454 | 455 | // Deprecated: Use CumSumRequest.ProtoReflect.Descriptor instead. 456 | func (*CumSumRequest) Descriptor() ([]byte, []int) { 457 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{8} 458 | } 459 | 460 | func (x *CumSumRequest) GetNumber() int64 { 461 | if x != nil { 462 | return x.Number 463 | } 464 | return 0 465 | } 466 | 467 | type CumSumResponse struct { 468 | state protoimpl.MessageState 469 | sizeCache protoimpl.SizeCache 470 | unknownFields protoimpl.UnknownFields 471 | 472 | Sum int64 `protobuf:"varint,1,opt,name=sum,proto3" json:"sum,omitempty"` 473 | } 474 | 475 | func (x *CumSumResponse) Reset() { 476 | *x = CumSumResponse{} 477 | if protoimpl.UnsafeEnabled { 478 | mi := &file_connect_ping_v1_ping_proto_msgTypes[9] 479 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 480 | ms.StoreMessageInfo(mi) 481 | } 482 | } 483 | 484 | func (x *CumSumResponse) String() string { 485 | return protoimpl.X.MessageStringOf(x) 486 | } 487 | 488 | func (*CumSumResponse) ProtoMessage() {} 489 | 490 | func (x *CumSumResponse) ProtoReflect() protoreflect.Message { 491 | mi := &file_connect_ping_v1_ping_proto_msgTypes[9] 492 | if protoimpl.UnsafeEnabled && x != nil { 493 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 494 | if ms.LoadMessageInfo() == nil { 495 | ms.StoreMessageInfo(mi) 496 | } 497 | return ms 498 | } 499 | return mi.MessageOf(x) 500 | } 501 | 502 | // Deprecated: Use CumSumResponse.ProtoReflect.Descriptor instead. 503 | func (*CumSumResponse) Descriptor() ([]byte, []int) { 504 | return file_connect_ping_v1_ping_proto_rawDescGZIP(), []int{9} 505 | } 506 | 507 | func (x *CumSumResponse) GetSum() int64 { 508 | if x != nil { 509 | return x.Sum 510 | } 511 | return 0 512 | } 513 | 514 | var File_connect_ping_v1_ping_proto protoreflect.FileDescriptor 515 | 516 | var file_connect_ping_v1_ping_proto_rawDesc = []byte{ 517 | 0x0a, 0x1a, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 518 | 0x31, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x63, 0x6f, 519 | 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x22, 0x39, 0x0a, 520 | 0x0b, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 521 | 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 522 | 0x6d, 0x62, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 523 | 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3a, 0x0a, 0x0c, 0x50, 0x69, 0x6e, 0x67, 524 | 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 525 | 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 526 | 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 527 | 0x74, 0x65, 0x78, 0x74, 0x22, 0x21, 0x0a, 0x0b, 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 528 | 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 529 | 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x0e, 0x0a, 0x0c, 0x46, 0x61, 0x69, 0x6c, 0x52, 530 | 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x24, 0x0a, 0x0a, 0x53, 0x75, 0x6d, 0x52, 0x65, 531 | 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 532 | 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x1f, 0x0a, 533 | 0x0b, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 534 | 0x73, 0x75, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x22, 0x28, 535 | 0x0a, 0x0e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 536 | 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 537 | 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x29, 0x0a, 0x0f, 0x43, 0x6f, 0x75, 0x6e, 538 | 0x74, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e, 539 | 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 540 | 0x62, 0x65, 0x72, 0x22, 0x27, 0x0a, 0x0d, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 541 | 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 542 | 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x22, 0x0a, 0x0e, 543 | 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 544 | 0x0a, 0x03, 0x73, 0x75, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x73, 0x75, 0x6d, 545 | 0x32, 0x84, 0x03, 0x0a, 0x0b, 0x50, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 546 | 0x12, 0x45, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x1c, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 547 | 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 548 | 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 549 | 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 550 | 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x04, 0x46, 0x61, 0x69, 0x6c, 0x12, 551 | 0x1c, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 552 | 0x31, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 553 | 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 554 | 0x46, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, 555 | 0x0a, 0x03, 0x53, 0x75, 0x6d, 0x12, 0x1b, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 556 | 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 557 | 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 558 | 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 559 | 0x22, 0x00, 0x28, 0x01, 0x12, 0x50, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x12, 560 | 0x1f, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 561 | 0x31, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 562 | 0x1a, 0x20, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 563 | 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x55, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 564 | 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x4f, 0x0a, 0x06, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 565 | 0x12, 0x1e, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 566 | 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 567 | 0x1a, 0x1f, 0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 568 | 0x76, 0x31, 0x2e, 0x43, 0x75, 0x6d, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 569 | 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0xc2, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 570 | 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 571 | 0x09, 0x50, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x42, 0x67, 0x69, 572 | 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x75, 0x66, 0x62, 0x75, 0x69, 0x6c, 573 | 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2d, 0x67, 0x6f, 0x2f, 0x69, 0x6e, 0x74, 574 | 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 575 | 0x74, 0x2f, 0x70, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x70, 0x69, 0x6e, 0x67, 0x76, 0x31, 576 | 0xa2, 0x02, 0x03, 0x43, 0x50, 0x58, 0xaa, 0x02, 0x0f, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 577 | 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0f, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 578 | 0x63, 0x74, 0x5c, 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1b, 0x43, 0x6f, 0x6e, 579 | 0x6e, 0x65, 0x63, 0x74, 0x5c, 0x50, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 580 | 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 581 | 0x63, 0x74, 0x3a, 0x3a, 0x50, 0x69, 0x6e, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 582 | 0x6f, 0x74, 0x6f, 0x33, 583 | } 584 | 585 | var ( 586 | file_connect_ping_v1_ping_proto_rawDescOnce sync.Once 587 | file_connect_ping_v1_ping_proto_rawDescData = file_connect_ping_v1_ping_proto_rawDesc 588 | ) 589 | 590 | func file_connect_ping_v1_ping_proto_rawDescGZIP() []byte { 591 | file_connect_ping_v1_ping_proto_rawDescOnce.Do(func() { 592 | file_connect_ping_v1_ping_proto_rawDescData = protoimpl.X.CompressGZIP(file_connect_ping_v1_ping_proto_rawDescData) 593 | }) 594 | return file_connect_ping_v1_ping_proto_rawDescData 595 | } 596 | 597 | var file_connect_ping_v1_ping_proto_msgTypes = make([]protoimpl.MessageInfo, 10) 598 | var file_connect_ping_v1_ping_proto_goTypes = []interface{}{ 599 | (*PingRequest)(nil), // 0: connect.ping.v1.PingRequest 600 | (*PingResponse)(nil), // 1: connect.ping.v1.PingResponse 601 | (*FailRequest)(nil), // 2: connect.ping.v1.FailRequest 602 | (*FailResponse)(nil), // 3: connect.ping.v1.FailResponse 603 | (*SumRequest)(nil), // 4: connect.ping.v1.SumRequest 604 | (*SumResponse)(nil), // 5: connect.ping.v1.SumResponse 605 | (*CountUpRequest)(nil), // 6: connect.ping.v1.CountUpRequest 606 | (*CountUpResponse)(nil), // 7: connect.ping.v1.CountUpResponse 607 | (*CumSumRequest)(nil), // 8: connect.ping.v1.CumSumRequest 608 | (*CumSumResponse)(nil), // 9: connect.ping.v1.CumSumResponse 609 | } 610 | var file_connect_ping_v1_ping_proto_depIdxs = []int32{ 611 | 0, // 0: connect.ping.v1.PingService.Ping:input_type -> connect.ping.v1.PingRequest 612 | 2, // 1: connect.ping.v1.PingService.Fail:input_type -> connect.ping.v1.FailRequest 613 | 4, // 2: connect.ping.v1.PingService.Sum:input_type -> connect.ping.v1.SumRequest 614 | 6, // 3: connect.ping.v1.PingService.CountUp:input_type -> connect.ping.v1.CountUpRequest 615 | 8, // 4: connect.ping.v1.PingService.CumSum:input_type -> connect.ping.v1.CumSumRequest 616 | 1, // 5: connect.ping.v1.PingService.Ping:output_type -> connect.ping.v1.PingResponse 617 | 3, // 6: connect.ping.v1.PingService.Fail:output_type -> connect.ping.v1.FailResponse 618 | 5, // 7: connect.ping.v1.PingService.Sum:output_type -> connect.ping.v1.SumResponse 619 | 7, // 8: connect.ping.v1.PingService.CountUp:output_type -> connect.ping.v1.CountUpResponse 620 | 9, // 9: connect.ping.v1.PingService.CumSum:output_type -> connect.ping.v1.CumSumResponse 621 | 5, // [5:10] is the sub-list for method output_type 622 | 0, // [0:5] is the sub-list for method input_type 623 | 0, // [0:0] is the sub-list for extension type_name 624 | 0, // [0:0] is the sub-list for extension extendee 625 | 0, // [0:0] is the sub-list for field type_name 626 | } 627 | 628 | func init() { file_connect_ping_v1_ping_proto_init() } 629 | func file_connect_ping_v1_ping_proto_init() { 630 | if File_connect_ping_v1_ping_proto != nil { 631 | return 632 | } 633 | if !protoimpl.UnsafeEnabled { 634 | file_connect_ping_v1_ping_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 635 | switch v := v.(*PingRequest); i { 636 | case 0: 637 | return &v.state 638 | case 1: 639 | return &v.sizeCache 640 | case 2: 641 | return &v.unknownFields 642 | default: 643 | return nil 644 | } 645 | } 646 | file_connect_ping_v1_ping_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 647 | switch v := v.(*PingResponse); i { 648 | case 0: 649 | return &v.state 650 | case 1: 651 | return &v.sizeCache 652 | case 2: 653 | return &v.unknownFields 654 | default: 655 | return nil 656 | } 657 | } 658 | file_connect_ping_v1_ping_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 659 | switch v := v.(*FailRequest); i { 660 | case 0: 661 | return &v.state 662 | case 1: 663 | return &v.sizeCache 664 | case 2: 665 | return &v.unknownFields 666 | default: 667 | return nil 668 | } 669 | } 670 | file_connect_ping_v1_ping_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 671 | switch v := v.(*FailResponse); i { 672 | case 0: 673 | return &v.state 674 | case 1: 675 | return &v.sizeCache 676 | case 2: 677 | return &v.unknownFields 678 | default: 679 | return nil 680 | } 681 | } 682 | file_connect_ping_v1_ping_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { 683 | switch v := v.(*SumRequest); i { 684 | case 0: 685 | return &v.state 686 | case 1: 687 | return &v.sizeCache 688 | case 2: 689 | return &v.unknownFields 690 | default: 691 | return nil 692 | } 693 | } 694 | file_connect_ping_v1_ping_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { 695 | switch v := v.(*SumResponse); i { 696 | case 0: 697 | return &v.state 698 | case 1: 699 | return &v.sizeCache 700 | case 2: 701 | return &v.unknownFields 702 | default: 703 | return nil 704 | } 705 | } 706 | file_connect_ping_v1_ping_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { 707 | switch v := v.(*CountUpRequest); i { 708 | case 0: 709 | return &v.state 710 | case 1: 711 | return &v.sizeCache 712 | case 2: 713 | return &v.unknownFields 714 | default: 715 | return nil 716 | } 717 | } 718 | file_connect_ping_v1_ping_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { 719 | switch v := v.(*CountUpResponse); i { 720 | case 0: 721 | return &v.state 722 | case 1: 723 | return &v.sizeCache 724 | case 2: 725 | return &v.unknownFields 726 | default: 727 | return nil 728 | } 729 | } 730 | file_connect_ping_v1_ping_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { 731 | switch v := v.(*CumSumRequest); i { 732 | case 0: 733 | return &v.state 734 | case 1: 735 | return &v.sizeCache 736 | case 2: 737 | return &v.unknownFields 738 | default: 739 | return nil 740 | } 741 | } 742 | file_connect_ping_v1_ping_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { 743 | switch v := v.(*CumSumResponse); i { 744 | case 0: 745 | return &v.state 746 | case 1: 747 | return &v.sizeCache 748 | case 2: 749 | return &v.unknownFields 750 | default: 751 | return nil 752 | } 753 | } 754 | } 755 | type x struct{} 756 | out := protoimpl.TypeBuilder{ 757 | File: protoimpl.DescBuilder{ 758 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 759 | RawDescriptor: file_connect_ping_v1_ping_proto_rawDesc, 760 | NumEnums: 0, 761 | NumMessages: 10, 762 | NumExtensions: 0, 763 | NumServices: 1, 764 | }, 765 | GoTypes: file_connect_ping_v1_ping_proto_goTypes, 766 | DependencyIndexes: file_connect_ping_v1_ping_proto_depIdxs, 767 | MessageInfos: file_connect_ping_v1_ping_proto_msgTypes, 768 | }.Build() 769 | File_connect_ping_v1_ping_proto = out.File 770 | file_connect_ping_v1_ping_proto_rawDesc = nil 771 | file_connect_ping_v1_ping_proto_goTypes = nil 772 | file_connect_ping_v1_ping_proto_depIdxs = nil 773 | } 774 | -------------------------------------------------------------------------------- /internal/gen/connect/ping/v1/pingv1connect/ping.connect.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021-2022 Buf Technologies, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Code generated by protoc-gen-connect-go. DO NOT EDIT. 16 | // 17 | // Source: connect/ping/v1/ping.proto 18 | 19 | package pingv1connect 20 | 21 | import ( 22 | "context" 23 | "errors" 24 | "net/http" 25 | "strings" 26 | 27 | "connectrpc.com/connect" 28 | v1 "github.com/klauspost/connect-compress/v2/internal/gen/connect/ping/v1" 29 | ) 30 | 31 | // This is a compile-time assertion to ensure that this generated file and the connect package are 32 | // compatible. If you get a compiler error that this constant is not defined, this code was 33 | // generated with a version of connect newer than the one compiled into your binary. You can fix the 34 | // problem by either regenerating this code with an older version of connect or updating the connect 35 | // version compiled into your binary. 36 | const _ = connect.IsAtLeastVersion0_1_0 37 | 38 | const ( 39 | // PingServiceName is the fully-qualified name of the PingService service. 40 | PingServiceName = "connect.ping.v1.PingService" 41 | ) 42 | 43 | // PingServiceClient is a client for the connect.ping.v1.PingService service. 44 | type PingServiceClient interface { 45 | // Ping sends a ping to the server to determine if it's reachable. 46 | Ping(context.Context, *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error) 47 | // Fail always fails. 48 | Fail(context.Context, *connect.Request[v1.FailRequest]) (*connect.Response[v1.FailResponse], error) 49 | // Sum calculates the sum of the numbers sent on the stream. 50 | Sum(context.Context) *connect.ClientStreamForClient[v1.SumRequest, v1.SumResponse] 51 | // CountUp returns a stream of the numbers up to the given request. 52 | CountUp(context.Context, *connect.Request[v1.CountUpRequest]) (*connect.ServerStreamForClient[v1.CountUpResponse], error) 53 | // CumSum determines the cumulative sum of all the numbers sent on the stream. 54 | CumSum(context.Context) *connect.BidiStreamForClient[v1.CumSumRequest, v1.CumSumResponse] 55 | } 56 | 57 | // NewPingServiceClient constructs a client for the connect.ping.v1.PingService service. By default, 58 | // it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses, and 59 | // sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the connect.WithGRPC() 60 | // or connect.WithGRPCWeb() options. 61 | // 62 | // The URL supplied here should be the base URL for the Connect or gRPC server (for example, 63 | // http://api.acme.com or https://acme.com/grpc). 64 | func NewPingServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) PingServiceClient { 65 | baseURL = strings.TrimRight(baseURL, "/") 66 | return &pingServiceClient{ 67 | ping: connect.NewClient[v1.PingRequest, v1.PingResponse]( 68 | httpClient, 69 | baseURL+"/connect.ping.v1.PingService/Ping", 70 | opts..., 71 | ), 72 | fail: connect.NewClient[v1.FailRequest, v1.FailResponse]( 73 | httpClient, 74 | baseURL+"/connect.ping.v1.PingService/Fail", 75 | opts..., 76 | ), 77 | sum: connect.NewClient[v1.SumRequest, v1.SumResponse]( 78 | httpClient, 79 | baseURL+"/connect.ping.v1.PingService/Sum", 80 | opts..., 81 | ), 82 | countUp: connect.NewClient[v1.CountUpRequest, v1.CountUpResponse]( 83 | httpClient, 84 | baseURL+"/connect.ping.v1.PingService/CountUp", 85 | opts..., 86 | ), 87 | cumSum: connect.NewClient[v1.CumSumRequest, v1.CumSumResponse]( 88 | httpClient, 89 | baseURL+"/connect.ping.v1.PingService/CumSum", 90 | opts..., 91 | ), 92 | } 93 | } 94 | 95 | // pingServiceClient implements PingServiceClient. 96 | type pingServiceClient struct { 97 | ping *connect.Client[v1.PingRequest, v1.PingResponse] 98 | fail *connect.Client[v1.FailRequest, v1.FailResponse] 99 | sum *connect.Client[v1.SumRequest, v1.SumResponse] 100 | countUp *connect.Client[v1.CountUpRequest, v1.CountUpResponse] 101 | cumSum *connect.Client[v1.CumSumRequest, v1.CumSumResponse] 102 | } 103 | 104 | // Ping calls connect.ping.v1.PingService.Ping. 105 | func (c *pingServiceClient) Ping(ctx context.Context, req *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error) { 106 | return c.ping.CallUnary(ctx, req) 107 | } 108 | 109 | // Fail calls connect.ping.v1.PingService.Fail. 110 | func (c *pingServiceClient) Fail(ctx context.Context, req *connect.Request[v1.FailRequest]) (*connect.Response[v1.FailResponse], error) { 111 | return c.fail.CallUnary(ctx, req) 112 | } 113 | 114 | // Sum calls connect.ping.v1.PingService.Sum. 115 | func (c *pingServiceClient) Sum(ctx context.Context) *connect.ClientStreamForClient[v1.SumRequest, v1.SumResponse] { 116 | return c.sum.CallClientStream(ctx) 117 | } 118 | 119 | // CountUp calls connect.ping.v1.PingService.CountUp. 120 | func (c *pingServiceClient) CountUp(ctx context.Context, req *connect.Request[v1.CountUpRequest]) (*connect.ServerStreamForClient[v1.CountUpResponse], error) { 121 | return c.countUp.CallServerStream(ctx, req) 122 | } 123 | 124 | // CumSum calls connect.ping.v1.PingService.CumSum. 125 | func (c *pingServiceClient) CumSum(ctx context.Context) *connect.BidiStreamForClient[v1.CumSumRequest, v1.CumSumResponse] { 126 | return c.cumSum.CallBidiStream(ctx) 127 | } 128 | 129 | // PingServiceHandler is an implementation of the connect.ping.v1.PingService service. 130 | type PingServiceHandler interface { 131 | // Ping sends a ping to the server to determine if it's reachable. 132 | Ping(context.Context, *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error) 133 | // Fail always fails. 134 | Fail(context.Context, *connect.Request[v1.FailRequest]) (*connect.Response[v1.FailResponse], error) 135 | // Sum calculates the sum of the numbers sent on the stream. 136 | Sum(context.Context, *connect.ClientStream[v1.SumRequest]) (*connect.Response[v1.SumResponse], error) 137 | // CountUp returns a stream of the numbers up to the given request. 138 | CountUp(context.Context, *connect.Request[v1.CountUpRequest], *connect.ServerStream[v1.CountUpResponse]) error 139 | // CumSum determines the cumulative sum of all the numbers sent on the stream. 140 | CumSum(context.Context, *connect.BidiStream[v1.CumSumRequest, v1.CumSumResponse]) error 141 | } 142 | 143 | // NewPingServiceHandler builds an HTTP handler from the service implementation. It returns the path 144 | // on which to mount the handler and the handler itself. 145 | // 146 | // By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf 147 | // and JSON codecs. They also support gzip compression. 148 | func NewPingServiceHandler(svc PingServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { 149 | mux := http.NewServeMux() 150 | mux.Handle("/connect.ping.v1.PingService/Ping", connect.NewUnaryHandler( 151 | "/connect.ping.v1.PingService/Ping", 152 | svc.Ping, 153 | opts..., 154 | )) 155 | mux.Handle("/connect.ping.v1.PingService/Fail", connect.NewUnaryHandler( 156 | "/connect.ping.v1.PingService/Fail", 157 | svc.Fail, 158 | opts..., 159 | )) 160 | mux.Handle("/connect.ping.v1.PingService/Sum", connect.NewClientStreamHandler( 161 | "/connect.ping.v1.PingService/Sum", 162 | svc.Sum, 163 | opts..., 164 | )) 165 | mux.Handle("/connect.ping.v1.PingService/CountUp", connect.NewServerStreamHandler( 166 | "/connect.ping.v1.PingService/CountUp", 167 | svc.CountUp, 168 | opts..., 169 | )) 170 | mux.Handle("/connect.ping.v1.PingService/CumSum", connect.NewBidiStreamHandler( 171 | "/connect.ping.v1.PingService/CumSum", 172 | svc.CumSum, 173 | opts..., 174 | )) 175 | return "/connect.ping.v1.PingService/", mux 176 | } 177 | 178 | // UnimplementedPingServiceHandler returns CodeUnimplemented from all methods. 179 | type UnimplementedPingServiceHandler struct{} 180 | 181 | func (UnimplementedPingServiceHandler) Ping(context.Context, *connect.Request[v1.PingRequest]) (*connect.Response[v1.PingResponse], error) { 182 | return nil, connect.NewError(connect.CodeUnimplemented, errors.New("connect.ping.v1.PingService.Ping is not implemented")) 183 | } 184 | 185 | func (UnimplementedPingServiceHandler) Fail(context.Context, *connect.Request[v1.FailRequest]) (*connect.Response[v1.FailResponse], error) { 186 | return nil, connect.NewError(connect.CodeUnimplemented, errors.New("connect.ping.v1.PingService.Fail is not implemented")) 187 | } 188 | 189 | func (UnimplementedPingServiceHandler) Sum(context.Context, *connect.ClientStream[v1.SumRequest]) (*connect.Response[v1.SumResponse], error) { 190 | return nil, connect.NewError(connect.CodeUnimplemented, errors.New("connect.ping.v1.PingService.Sum is not implemented")) 191 | } 192 | 193 | func (UnimplementedPingServiceHandler) CountUp(context.Context, *connect.Request[v1.CountUpRequest], *connect.ServerStream[v1.CountUpResponse]) error { 194 | return connect.NewError(connect.CodeUnimplemented, errors.New("connect.ping.v1.PingService.CountUp is not implemented")) 195 | } 196 | 197 | func (UnimplementedPingServiceHandler) CumSum(context.Context, *connect.BidiStream[v1.CumSumRequest, v1.CumSumResponse]) error { 198 | return connect.NewError(connect.CodeUnimplemented, errors.New("connect.ping.v1.PingService.CumSum is not implemented")) 199 | } 200 | --------------------------------------------------------------------------------