pax_global_header00006660000000000000000000000064146303262470014521gustar00rootroot0000000000000052 comment=52f5bb70001473c7615782361c1873a64a475b72 go-grpc-compression-1.2.3/000077500000000000000000000000001463032624700154215ustar00rootroot00000000000000go-grpc-compression-1.2.3/.github/000077500000000000000000000000001463032624700167615ustar00rootroot00000000000000go-grpc-compression-1.2.3/.github/workflows/000077500000000000000000000000001463032624700210165ustar00rootroot00000000000000go-grpc-compression-1.2.3/.github/workflows/golangci-lint.yml000066400000000000000000000005051463032624700242700ustar00rootroot00000000000000name: golangci-lint on: push: tags: - v* branches: - main pull_request: jobs: golangci: name: golangci-lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: version: latest go-grpc-compression-1.2.3/.github/workflows/test.yml000066400000000000000000000005241463032624700225210ustar00rootroot00000000000000name: go test on: push: tags: - v* branches: - main pull_request: jobs: linux: name: go test runs-on: ubuntu-20.04 steps: - name: checkout code uses: actions/checkout@v3 - name: test run: | set -euo pipefail go test ./... go test -race ./... go-grpc-compression-1.2.3/.gitignore000066400000000000000000000007441463032624700174160ustar00rootroot00000000000000# If you prefer the allow list template instead of the deny list, see community template: # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # # Binaries for programs and plugins *.exe *.exe~ *.dll *.so *.dylib # Test binary, built with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out # Dependency directories (remove the comment below to include it) # vendor/ # Go workspace file go.work .ideago-grpc-compression-1.2.3/LICENSE000066400000000000000000000261361463032624700164360ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. go-grpc-compression-1.2.3/Makefile000066400000000000000000000004071463032624700170620ustar00rootroot00000000000000OTEL_DOCKER_PROTOBUF ?= otel/build-protobuf:0.4.0 PROTOC := docker run --rm -u ${shell id -u} -v${PWD}:${PWD} -w${PWD} ${OTEL_DOCKER_PROTOBUF} --proto_path=${PWD} .PHONY: genproto genproto: $(PROTOC) --go_out=plugins=grpc:. internal/testserver/testserver.proto go-grpc-compression-1.2.3/README.md000066400000000000000000000030331463032624700166770ustar00rootroot00000000000000# go-grpc-compression This respository contains go gRPC encoding wrappers for some useful compression algorithms that are not available in google.golang.org/grpc. * github.com/mostynb/go-grpc-compression/lz4 - using https://github.com/pierrec/lz4 * github.com/mostynb/go-grpc-compression/snappy - using https://github.com/golang/snappy * github.com/mostynb/go-grpc-compression/zstd - using https://github.com/klauspost/compress/tree/master/zstd The following algorithms also have experimental implementations, which have not been tested as much as those above. These may be changed significantly, or even removed from this library at a future point. * github.com/mostynb/go-grpc-compression/experimental/klauspost_snappy - using https://github.com/klauspost/compress/tree/master/s2 in snappy compatibility mode * github.com/mostynb/go-grpc-compression/experimental/s2 - using https://github.com/klauspost/compress/tree/master/s2 Importing any of the packages above will override any previously registered encoders with the same name. If you would prefer imports to only register the encoder if there is no previously registered encoder with the same name, then you should instead import one of the following packages: * github.com/mostynb/go-grpc-compression/nonclobbering/lz4 * github.com/mostynb/go-grpc-compression/nonclobbering/snappy * github.com/mostynb/go-grpc-compression/nonclobbering/zstd * github.com/mostynb/go-grpc-compression/nonclobbering/experimental/klauspost_snappy * github.com/mostynb/go-grpc-compression/nonclobbering/experimental/s2 go-grpc-compression-1.2.3/experimental/000077500000000000000000000000001463032624700201165ustar00rootroot00000000000000go-grpc-compression-1.2.3/experimental/klauspost_snappy/000077500000000000000000000000001463032624700235355ustar00rootroot00000000000000go-grpc-compression-1.2.3/experimental/klauspost_snappy/klauspost_snappy.go000066400000000000000000000032661463032624700275120ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/experimental/klauspost_snappy // is a wrapper for using github.com/klauspost/compress/s2 in snappy // compatibility mode with gRPC. It might be more efficient than // github.com/mostynb/go-grpc-compression/snappy and // github.com/mostynb/go-grpc-compression/nonclobbering/snappy // packages which make use of github.com/golang/snappy. // // Note that this is registered under the name "snappy" with gRPC, so only // one of these packages should be used at a time. // // If you import this package, it will register itself as the encoder for // the "snappy" compressor, overriding any previously registered compressors // with this name. // // If you don't want to override previously registered "snappy" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/nonclobbering/experimental/klauspost_snappy package klauspost_snappy import ( internalsnappy "github.com/mostynb/go-grpc-compression/internal/klauspost_snappy" ) const Name = internalsnappy.Name func init() { clobbering := true internalsnappy.PretendInit(clobbering) } go-grpc-compression-1.2.3/experimental/s2/000077500000000000000000000000001463032624700204425ustar00rootroot00000000000000go-grpc-compression-1.2.3/experimental/s2/s2.go000066400000000000000000000025751463032624700213260ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package s2 is an experimental wrapper for using // github.com/klauspost/compress/s2 stream compression with gRPC. // Package github.com/mostynb/go-grpc-compression/s2 is an experimental // wrapper for using github.com/klauspost/compress/s2 stream compression // with gRPC. // // If you import this package, it will register itself as the encoder for // the "s2" compressor, overriding any previously registered compressors // with this name. // // If you don't want to override previously registered "s2" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/nonclobbering/s2 package s2 import ( internals2 "github.com/mostynb/go-grpc-compression/internal/s2" ) const Name = internals2.Name func init() { clobbering := true internals2.PretendInit(clobbering) } go-grpc-compression-1.2.3/go.mod000066400000000000000000000013421463032624700165270ustar00rootroot00000000000000module github.com/mostynb/go-grpc-compression go 1.17 require ( github.com/golang/snappy v0.0.4 github.com/klauspost/compress v1.17.8 github.com/pierrec/lz4/v4 v4.1.21 github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.64.0 google.golang.org/protobuf v1.34.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/kr/pretty v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/net v0.22.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) go-grpc-compression-1.2.3/go.sum000066400000000000000000000067311463032624700165630ustar00rootroot00000000000000github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= go-grpc-compression-1.2.3/internal/000077500000000000000000000000001463032624700172355ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/deptest/000077500000000000000000000000001463032624700207055ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/deptest/deptest_test.go000066400000000000000000000031731463032624700237470ustar00rootroot00000000000000// Copyright 2020 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // package deptest ensures that the go-grpc-compression sub-packages will // not clobber an existing registration. package deptest import ( "testing" // This import happens first for the test, keep it ahead of // the three unnamed imports below. "github.com/mostynb/go-grpc-compression/internal/deptest/testlib" // If these were moved above, the test would fail because // testlib has the same no-clobber logic as the main packages. _ "github.com/mostynb/go-grpc-compression/nonclobbering/lz4" _ "github.com/mostynb/go-grpc-compression/nonclobbering/snappy" _ "github.com/mostynb/go-grpc-compression/nonclobbering/zstd" "github.com/stretchr/testify/require" "google.golang.org/grpc/encoding" ) func TestCompressorNotClobbered(t *testing.T) { // Because the deptest/lib imports first, it's init() function // registers dummy compressors. The following libraries do not // clobber, so we should find Dummy compressors. for _, name := range testlib.AllNames { _, ok := encoding.GetCompressor(name).(testlib.Dummy) require.True(t, ok) } } go-grpc-compression-1.2.3/internal/deptest/testlib/000077500000000000000000000000001463032624700223535ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/deptest/testlib/testlib.go000066400000000000000000000026141463032624700243530ustar00rootroot00000000000000// Copyright 2020 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package testlib import ( "fmt" "io" "google.golang.org/grpc/encoding" ) type Dummy string var _ encoding.Compressor = Dummy("") // AllNames lists every compressor in this repo, for testing. var AllNames = []string{"zstd", "snappy", "lz4"} func (d Dummy) Compress(io.Writer) (io.WriteCloser, error) { return nil, fmt.Errorf("not implemented") } func (d Dummy) Decompress(r io.Reader) (io.Reader, error) { return nil, fmt.Errorf("not implemented") } func (d Dummy) Name() string { return string(d) } func init() { for _, name := range AllNames { // This test will not register the dummies in case // of existing registrations, this ensures the import // order of the deptest actually tests no-clobbering. if encoding.GetCompressor(name) == nil { encoding.RegisterCompressor(Dummy(name)) } } } go-grpc-compression-1.2.3/internal/klauspost_snappy/000077500000000000000000000000001463032624700226545ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/klauspost_snappy/klauspost_snappy.go000066400000000000000000000050011463032624700266160ustar00rootroot00000000000000/* * * Copyright 2017 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ // Package experimental/klauspost_snappy is a wrapper for using // github.com/klauspost/compress/s2 in snappy compatibility mode with gRPC. // It might be more efficient than the top-level snappy package which makes // use of github.com/golang/snappy. // // Note that this is registered under the same "snappy" name with gRPC, so // only one of the two packages should be used at a time. package klauspost_snappy // This code is based upon the gzip wrapper in github.com/grpc/grpc-go: // https://github.com/grpc/grpc-go/blob/master/encoding/gzip/gzip.go import ( "io" "io/ioutil" "sync" snappylib "github.com/klauspost/compress/s2" "google.golang.org/grpc/encoding" ) const Name = "snappy" type compressor struct { poolCompressor sync.Pool poolDecompressor sync.Pool } type writer struct { *snappylib.Writer pool *sync.Pool } type reader struct { *snappylib.Reader pool *sync.Pool } func PretendInit(clobbering bool) { if !clobbering && encoding.GetCompressor(Name) != nil { return } c := &compressor{} c.poolCompressor.New = func() interface{} { w := snappylib.NewWriter(ioutil.Discard, snappylib.WriterSnappyCompat()) return &writer{Writer: w, pool: &c.poolCompressor} } encoding.RegisterCompressor(c) } func (c *compressor) Compress(w io.Writer) (io.WriteCloser, error) { z := c.poolCompressor.Get().(*writer) z.Writer.Reset(w) return z, nil } func (c *compressor) Decompress(r io.Reader) (io.Reader, error) { z, inPool := c.poolDecompressor.Get().(*reader) if !inPool { newR := snappylib.NewReader(r, snappylib.ReaderAllocBlock(64<<10)) return &reader{Reader: newR, pool: &c.poolDecompressor}, nil } z.Reset(r) return z, nil } func (c *compressor) Name() string { return Name } func (z *writer) Close() error { err := z.Writer.Close() z.pool.Put(z) return err } func (z *reader) Read(p []byte) (n int, err error) { n, err = z.Reader.Read(p) if err == io.EOF { z.pool.Put(z) } return n, err } go-grpc-compression-1.2.3/internal/klauspost_snappy/klauspost_snappy_test.go000066400000000000000000000051761463032624700276720ustar00rootroot00000000000000/* * * Copyright 2021 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package klauspost_snappy import ( "bytes" "context" "io/ioutil" "net" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/encoding" "google.golang.org/grpc/test/bufconn" "github.com/mostynb/go-grpc-compression/internal/testserver" ) const ( bufSize = 1024 message = "Message Request snappy" ) func TestRegisteredCompression(t *testing.T) { clobbering := true PretendInit(clobbering) comp := encoding.GetCompressor(Name) require.NotNil(t, comp) assert.Equal(t, Name, comp.Name()) buf := bytes.NewBuffer(make([]byte, 0, bufSize)) wc, err := comp.Compress(buf) require.NoError(t, err) _, err = wc.Write([]byte(message)) require.NoError(t, err) assert.NoError(t, wc.Close()) r, err := comp.Decompress(buf) require.NoError(t, err) expected, err := ioutil.ReadAll(r) require.NoError(t, err) assert.Equal(t, message, string(expected)) } func TestRoundTrip(t *testing.T) { clobbering := true PretendInit(clobbering) lis := bufconn.Listen(bufSize) t.Cleanup(func() { assert.NoError(t, lis.Close()) }) done := make(chan struct{}, 1) s := grpc.NewServer() defer func() { s.GracefulStop() <-done }() testserver.RegisterTestServerServer(s, &testserver.EchoTestServer{}) go func() { if err := s.Serve(lis); err != nil && err != grpc.ErrServerStopped { t.Errorf("Server exited with error: %v", err) } done <- struct{}{} }() conn, err := grpc.NewClient("passthrough://bufnet", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return lis.Dial() }), grpc.WithDefaultCallOptions(grpc.UseCompressor(Name)), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) t.Cleanup(func() { assert.NoError(t, conn.Close()) }) client := testserver.NewTestServerClient(conn) resp, err := client.SendMessage(context.Background(), &testserver.MessageRequest{Request: message}) require.NoError(t, err) assert.Equal(t, message, resp.Response) } go-grpc-compression-1.2.3/internal/lz4/000077500000000000000000000000001463032624700177465ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/lz4/lz4.go000066400000000000000000000041331463032624700210070ustar00rootroot00000000000000/* * * Copyright 2017 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ // Package lz4 is a wrapper for using github.com/pierrec/lz4 with gRPC. package lz4 // This code is based upon the gzip wrapper in github.com/grpc/grpc-go: // https://github.com/grpc/grpc-go/blob/master/encoding/gzip/gzip.go import ( "io" "io/ioutil" "sync" lz4lib "github.com/pierrec/lz4/v4" "google.golang.org/grpc/encoding" ) const Name = "lz4" type compressor struct { poolCompressor sync.Pool poolDecompressor sync.Pool } type writer struct { *lz4lib.Writer pool *sync.Pool } type reader struct { *lz4lib.Reader pool *sync.Pool } func PretendInit(clobbering bool) { if !clobbering && encoding.GetCompressor(Name) != nil { return } c := &compressor{} c.poolCompressor.New = func() interface{} { w := lz4lib.NewWriter(ioutil.Discard) return &writer{Writer: w, pool: &c.poolCompressor} } encoding.RegisterCompressor(c) } func (c *compressor) Compress(w io.Writer) (io.WriteCloser, error) { z := c.poolCompressor.Get().(*writer) z.Writer.Reset(w) return z, nil } func (c *compressor) Decompress(r io.Reader) (io.Reader, error) { z, inPool := c.poolDecompressor.Get().(*reader) if !inPool { newR := lz4lib.NewReader(r) return &reader{Reader: newR, pool: &c.poolDecompressor}, nil } z.Reset(r) return z, nil } func (c *compressor) Name() string { return Name } func (z *writer) Close() error { err := z.Writer.Close() z.pool.Put(z) return err } func (z *reader) Read(p []byte) (n int, err error) { n, err = z.Reader.Read(p) if err == io.EOF { z.pool.Put(z) } return n, err } go-grpc-compression-1.2.3/internal/lz4/lz4_test.go000066400000000000000000000051561463032624700220540ustar00rootroot00000000000000/* * * Copyright 2021 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package lz4 import ( "bytes" "context" "io/ioutil" "net" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/encoding" "google.golang.org/grpc/test/bufconn" "github.com/mostynb/go-grpc-compression/internal/testserver" ) const ( bufSize = 1024 message = "Message Request LZ4" ) func TestRegisteredCompression(t *testing.T) { clobbering := true PretendInit(clobbering) comp := encoding.GetCompressor(Name) require.NotNil(t, comp) assert.Equal(t, Name, comp.Name()) buf := bytes.NewBuffer(make([]byte, 0, bufSize)) wc, err := comp.Compress(buf) require.NoError(t, err) _, err = wc.Write([]byte(message)) require.NoError(t, err) assert.NoError(t, wc.Close()) r, err := comp.Decompress(buf) require.NoError(t, err) expected, err := ioutil.ReadAll(r) require.NoError(t, err) assert.Equal(t, message, string(expected)) } func TestRoundTrip(t *testing.T) { clobbering := true PretendInit(clobbering) lis := bufconn.Listen(bufSize) t.Cleanup(func() { assert.NoError(t, lis.Close()) }) done := make(chan struct{}, 1) s := grpc.NewServer() defer func() { s.GracefulStop() <-done }() testserver.RegisterTestServerServer(s, &testserver.EchoTestServer{}) go func() { if err := s.Serve(lis); err != nil && err != grpc.ErrServerStopped { t.Errorf("Server exited with error: %v", err) } done <- struct{}{} }() conn, err := grpc.NewClient("passthrough://bufnet", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return lis.Dial() }), grpc.WithDefaultCallOptions(grpc.UseCompressor(Name)), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) t.Cleanup(func() { assert.NoError(t, conn.Close()) }) client := testserver.NewTestServerClient(conn) resp, err := client.SendMessage(context.Background(), &testserver.MessageRequest{Request: message}) require.NoError(t, err) assert.Equal(t, message, resp.Response) } go-grpc-compression-1.2.3/internal/s2/000077500000000000000000000000001463032624700175615ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/s2/s2.go000066400000000000000000000037741463032624700204470ustar00rootroot00000000000000// Copyright 2022 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package s2 is an experimental wrapper for using // github.com/klauspost/compress/s2 stream compression with gRPC. package s2 import ( "io" "io/ioutil" "sync" "github.com/klauspost/compress/s2" "google.golang.org/grpc/encoding" ) const Name = "s2" type compressor struct { poolCompressor sync.Pool poolDecompressor sync.Pool } type writer struct { *s2.Writer pool *sync.Pool } type reader struct { *s2.Reader pool *sync.Pool } func PretendInit(clobbering bool) { if !clobbering && encoding.GetCompressor(Name) != nil { return } c := &compressor{} c.poolCompressor.New = func() interface{} { w := s2.NewWriter(ioutil.Discard, s2.WriterConcurrency(1)) return &writer{Writer: w, pool: &c.poolCompressor} } encoding.RegisterCompressor(c) } func (c *compressor) Compress(w io.Writer) (io.WriteCloser, error) { s := c.poolCompressor.Get().(*writer) s.Writer.Reset(w) return s, nil } func (c *compressor) Decompress(r io.Reader) (io.Reader, error) { s, inPool := c.poolDecompressor.Get().(*reader) if !inPool { newR := s2.NewReader(r) return &reader{Reader: newR, pool: &c.poolDecompressor}, nil } s.Reset(r) return s, nil } func (c *compressor) Name() string { return Name } func (s *writer) Close() error { err := s.Writer.Close() s.pool.Put(s) return err } func (s *reader) Read(p []byte) (n int, err error) { n, err = s.Reader.Read(p) if err == io.EOF { s.pool.Put(s) } return n, err } go-grpc-compression-1.2.3/internal/s2/s2_test.go000066400000000000000000000051471463032624700215020ustar00rootroot00000000000000// Copyright 2022 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package s2 import ( "bytes" "context" "io/ioutil" "net" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/encoding" "google.golang.org/grpc/test/bufconn" "github.com/mostynb/go-grpc-compression/internal/testserver" ) const ( bufSize = 1024 message = "Message Request s2" ) func TestRegisteredCompression(t *testing.T) { clobbering := true PretendInit(clobbering) comp := encoding.GetCompressor(Name) require.NotNil(t, comp) assert.Equal(t, Name, comp.Name()) buf := bytes.NewBuffer(make([]byte, 0, bufSize)) wc, err := comp.Compress(buf) require.NoError(t, err) _, err = wc.Write([]byte(message)) require.NoError(t, err) assert.NoError(t, wc.Close()) r, err := comp.Decompress(buf) require.NoError(t, err) expected, err := ioutil.ReadAll(r) require.NoError(t, err) assert.Equal(t, message, string(expected)) } func TestRoundTrip(t *testing.T) { clobbering := true PretendInit(clobbering) lis := bufconn.Listen(bufSize) t.Cleanup(func() { assert.NoError(t, lis.Close()) }) done := make(chan struct{}, 1) s := grpc.NewServer() defer func() { s.GracefulStop() <-done }() testserver.RegisterTestServerServer(s, &testserver.EchoTestServer{}) go func() { if err := s.Serve(lis); err != nil && err != grpc.ErrServerStopped { t.Errorf("Server exited with error: %v", err) } done <- struct{}{} }() conn, err := grpc.NewClient("passthrough://bufnet", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return lis.Dial() }), grpc.WithDefaultCallOptions(grpc.UseCompressor(Name)), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) t.Cleanup(func() { assert.NoError(t, conn.Close()) }) client := testserver.NewTestServerClient(conn) resp, err := client.SendMessage(context.Background(), &testserver.MessageRequest{Request: message}) require.NoError(t, err) assert.Equal(t, message, resp.Response) } go-grpc-compression-1.2.3/internal/snappy/000077500000000000000000000000001463032624700205475ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/snappy/snappy.go000066400000000000000000000041741463032624700224160ustar00rootroot00000000000000/* * * Copyright 2017 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ // Package snappy is a wrapper for using github.com/golang/snappy with gRPC. package snappy // This code is based upon the gzip wrapper in github.com/grpc/grpc-go: // https://github.com/grpc/grpc-go/blob/master/encoding/gzip/gzip.go import ( "io" "io/ioutil" "sync" snappylib "github.com/golang/snappy" "google.golang.org/grpc/encoding" ) const Name = "snappy" type compressor struct { poolCompressor sync.Pool poolDecompressor sync.Pool } type writer struct { *snappylib.Writer pool *sync.Pool } type reader struct { *snappylib.Reader pool *sync.Pool } func PretendInit(clobbering bool) { if !clobbering && encoding.GetCompressor(Name) != nil { return } c := &compressor{} c.poolCompressor.New = func() interface{} { w := snappylib.NewBufferedWriter(ioutil.Discard) return &writer{Writer: w, pool: &c.poolCompressor} } encoding.RegisterCompressor(c) } func (c *compressor) Compress(w io.Writer) (io.WriteCloser, error) { z := c.poolCompressor.Get().(*writer) z.Writer.Reset(w) return z, nil } func (c *compressor) Decompress(r io.Reader) (io.Reader, error) { z, inPool := c.poolDecompressor.Get().(*reader) if !inPool { newR := snappylib.NewReader(r) return &reader{Reader: newR, pool: &c.poolDecompressor}, nil } z.Reset(r) return z, nil } func (c *compressor) Name() string { return Name } func (z *writer) Close() error { err := z.Writer.Close() z.pool.Put(z) return err } func (z *reader) Read(p []byte) (n int, err error) { n, err = z.Reader.Read(p) if err == io.EOF { z.pool.Put(z) } return n, err } go-grpc-compression-1.2.3/internal/snappy/snappy_test.go000066400000000000000000000051611463032624700234520ustar00rootroot00000000000000/* * * Copyright 2021 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package snappy import ( "bytes" "context" "io/ioutil" "net" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/encoding" "google.golang.org/grpc/test/bufconn" "github.com/mostynb/go-grpc-compression/internal/testserver" ) const ( bufSize = 1024 message = "Message Request LZ4" ) func TestRegisteredCompression(t *testing.T) { clobbering := true PretendInit(clobbering) comp := encoding.GetCompressor(Name) require.NotNil(t, comp) assert.Equal(t, Name, comp.Name()) buf := bytes.NewBuffer(make([]byte, 0, bufSize)) wc, err := comp.Compress(buf) require.NoError(t, err) _, err = wc.Write([]byte(message)) require.NoError(t, err) assert.NoError(t, wc.Close()) r, err := comp.Decompress(buf) require.NoError(t, err) expected, err := ioutil.ReadAll(r) require.NoError(t, err) assert.Equal(t, message, string(expected)) } func TestRoundTrip(t *testing.T) { clobbering := true PretendInit(clobbering) lis := bufconn.Listen(bufSize) t.Cleanup(func() { assert.NoError(t, lis.Close()) }) done := make(chan struct{}, 1) s := grpc.NewServer() defer func() { s.GracefulStop() <-done }() testserver.RegisterTestServerServer(s, &testserver.EchoTestServer{}) go func() { if err := s.Serve(lis); err != nil && err != grpc.ErrServerStopped { t.Errorf("Server exited with error: %v", err) } done <- struct{}{} }() conn, err := grpc.NewClient("passthrough://bufnet", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return lis.Dial() }), grpc.WithDefaultCallOptions(grpc.UseCompressor(Name)), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) t.Cleanup(func() { assert.NoError(t, conn.Close()) }) client := testserver.NewTestServerClient(conn) resp, err := client.SendMessage(context.Background(), &testserver.MessageRequest{Request: message}) require.NoError(t, err) assert.Equal(t, message, resp.Response) } go-grpc-compression-1.2.3/internal/testserver/000077500000000000000000000000001463032624700214435ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/testserver/testserver.go000066400000000000000000000004351463032624700242020ustar00rootroot00000000000000package testserver import ( "context" ) var _ TestServerServer = (*EchoTestServer)(nil) type EchoTestServer struct{} func (f EchoTestServer) SendMessage(ctx context.Context, request *MessageRequest) (*MessageReply, error) { return &MessageReply{Response: request.Request}, nil } go-grpc-compression-1.2.3/internal/testserver/testserver.pb.go000066400000000000000000000256061463032624700246110ustar00rootroot00000000000000// // // Copyright 2021 gRPC authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0 // protoc v3.14.0 // source: internal/testserver/testserver.proto package testserver import ( context "context" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // The request message containing the user's name. type MessageRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Request string `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` } func (x *MessageRequest) Reset() { *x = MessageRequest{} if protoimpl.UnsafeEnabled { mi := &file_internal_testserver_testserver_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *MessageRequest) String() string { return protoimpl.X.MessageStringOf(x) } func (*MessageRequest) ProtoMessage() {} func (x *MessageRequest) ProtoReflect() protoreflect.Message { mi := &file_internal_testserver_testserver_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use MessageRequest.ProtoReflect.Descriptor instead. func (*MessageRequest) Descriptor() ([]byte, []int) { return file_internal_testserver_testserver_proto_rawDescGZIP(), []int{0} } func (x *MessageRequest) GetRequest() string { if x != nil { return x.Request } return "" } // The response message containing the greetings type MessageReply struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Response string `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` } func (x *MessageReply) Reset() { *x = MessageReply{} if protoimpl.UnsafeEnabled { mi := &file_internal_testserver_testserver_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *MessageReply) String() string { return protoimpl.X.MessageStringOf(x) } func (*MessageReply) ProtoMessage() {} func (x *MessageReply) ProtoReflect() protoreflect.Message { mi := &file_internal_testserver_testserver_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use MessageReply.ProtoReflect.Descriptor instead. func (*MessageReply) Descriptor() ([]byte, []int) { return file_internal_testserver_testserver_proto_rawDescGZIP(), []int{1} } func (x *MessageReply) GetResponse() string { if x != nil { return x.Response } return "" } var File_internal_testserver_testserver_proto protoreflect.FileDescriptor var file_internal_testserver_testserver_proto_rawDesc = []byte{ 0x0a, 0x24, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x22, 0x2a, 0x0a, 0x0e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x2a, 0x0a, 0x0c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x53, 0x0a, 0x0a, 0x54, 0x65, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x45, 0x0a, 0x0b, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x15, 0x5a, 0x13, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_internal_testserver_testserver_proto_rawDescOnce sync.Once file_internal_testserver_testserver_proto_rawDescData = file_internal_testserver_testserver_proto_rawDesc ) func file_internal_testserver_testserver_proto_rawDescGZIP() []byte { file_internal_testserver_testserver_proto_rawDescOnce.Do(func() { file_internal_testserver_testserver_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_testserver_testserver_proto_rawDescData) }) return file_internal_testserver_testserver_proto_rawDescData } var file_internal_testserver_testserver_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_internal_testserver_testserver_proto_goTypes = []interface{}{ (*MessageRequest)(nil), // 0: helloworld.MessageRequest (*MessageReply)(nil), // 1: helloworld.MessageReply } var file_internal_testserver_testserver_proto_depIdxs = []int32{ 0, // 0: helloworld.TestServer.SendMessage:input_type -> helloworld.MessageRequest 1, // 1: helloworld.TestServer.SendMessage:output_type -> helloworld.MessageReply 1, // [1:2] is the sub-list for method output_type 0, // [0:1] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_internal_testserver_testserver_proto_init() } func file_internal_testserver_testserver_proto_init() { if File_internal_testserver_testserver_proto != nil { return } if !protoimpl.UnsafeEnabled { file_internal_testserver_testserver_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*MessageRequest); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_internal_testserver_testserver_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*MessageReply); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_internal_testserver_testserver_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 1, }, GoTypes: file_internal_testserver_testserver_proto_goTypes, DependencyIndexes: file_internal_testserver_testserver_proto_depIdxs, MessageInfos: file_internal_testserver_testserver_proto_msgTypes, }.Build() File_internal_testserver_testserver_proto = out.File file_internal_testserver_testserver_proto_rawDesc = nil file_internal_testserver_testserver_proto_goTypes = nil file_internal_testserver_testserver_proto_depIdxs = nil } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context var _ grpc.ClientConnInterface // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion6 // TestServerClient is the client API for TestServer service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type TestServerClient interface { // Sends a greeting SendMessage(ctx context.Context, in *MessageRequest, opts ...grpc.CallOption) (*MessageReply, error) } type testServerClient struct { cc grpc.ClientConnInterface } func NewTestServerClient(cc grpc.ClientConnInterface) TestServerClient { return &testServerClient{cc} } func (c *testServerClient) SendMessage(ctx context.Context, in *MessageRequest, opts ...grpc.CallOption) (*MessageReply, error) { out := new(MessageReply) err := c.cc.Invoke(ctx, "/helloworld.TestServer/SendMessage", in, out, opts...) if err != nil { return nil, err } return out, nil } // TestServerServer is the server API for TestServer service. type TestServerServer interface { // Sends a greeting SendMessage(context.Context, *MessageRequest) (*MessageReply, error) } // UnimplementedTestServerServer can be embedded to have forward compatible implementations. type UnimplementedTestServerServer struct { } func (*UnimplementedTestServerServer) SendMessage(context.Context, *MessageRequest) (*MessageReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SendMessage not implemented") } func RegisterTestServerServer(s *grpc.Server, srv TestServerServer) { s.RegisterService(&_TestServer_serviceDesc, srv) } func _TestServer_SendMessage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MessageRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { return srv.(TestServerServer).SendMessage(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, FullMethod: "/helloworld.TestServer/SendMessage", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(TestServerServer).SendMessage(ctx, req.(*MessageRequest)) } return interceptor(ctx, in, info, handler) } var _TestServer_serviceDesc = grpc.ServiceDesc{ ServiceName: "helloworld.TestServer", HandlerType: (*TestServerServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "SendMessage", Handler: _TestServer_SendMessage_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "internal/testserver/testserver.proto", } go-grpc-compression-1.2.3/internal/testserver/testserver.proto000066400000000000000000000020061463032624700247340ustar00rootroot00000000000000/* * * Copyright 2021 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ syntax = "proto3"; option go_package = "internal/testserver"; package helloworld; // The greeting service definition. service TestServer { // Sends a greeting rpc SendMessage (MessageRequest) returns (MessageReply) {} } // The request message containing the user's name. message MessageRequest { string request = 1; } // The response message containing the greetings message MessageReply { string response = 1; } go-grpc-compression-1.2.3/internal/zstd/000077500000000000000000000000001463032624700202215ustar00rootroot00000000000000go-grpc-compression-1.2.3/internal/zstd/zstd.go000066400000000000000000000072271463032624700215440ustar00rootroot00000000000000// Copyright 2020 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package zstd is a wrapper for using github.com/klauspost/compress/zstd // with gRPC. package zstd import ( "bytes" "errors" "io" "runtime" "sync" "github.com/klauspost/compress/zstd" "google.golang.org/grpc/encoding" ) const Name = "zstd" var encoderOptions = []zstd.EOption{ // The default zstd window size is 8MB, which is much larger than the // typical RPC message and wastes a bunch of memory. zstd.WithWindowSize(512 * 1024), } var decoderOptions = []zstd.DOption{ // If the decoder concurrency level is not 1, we would need to call // Close() to avoid leaking resources when the object is released // from compressor.decoderPool. zstd.WithDecoderConcurrency(1), } // We will set a finalizer on these objects, so when the go-grpc code is // finished with them, they will be added back to compressor.decoderPool. type decoderWrapper struct { *zstd.Decoder } type compressor struct { encoder *zstd.Encoder decoderPool sync.Pool // To hold *zstd.Decoder's. } func PretendInit(clobbering bool) { if !clobbering && encoding.GetCompressor(Name) != nil { return } enc, _ := zstd.NewWriter(nil, encoderOptions...) c := &compressor{ encoder: enc, } encoding.RegisterCompressor(c) } var ErrNotInUse = errors.New("SetLevel ineffective because another zstd compressor has been registered") // SetLevel updates the registered compressor to use a particular compression // level. NOTE: this function must only be called from an init function, and // is not threadsafe. func SetLevel(level zstd.EncoderLevel) error { c, ok := encoding.GetCompressor(Name).(*compressor) if !ok { return ErrNotInUse } enc, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(level)) if err != nil { return err } c.encoder = enc return nil } func (c *compressor) Compress(w io.Writer) (io.WriteCloser, error) { return &zstdWriteCloser{ enc: c.encoder, writer: w, }, nil } type zstdWriteCloser struct { enc *zstd.Encoder writer io.Writer // Compressed data will be written here. buf bytes.Buffer // Buffer uncompressed data here, compress on Close. } func (z *zstdWriteCloser) Write(p []byte) (int, error) { return z.buf.Write(p) } func (z *zstdWriteCloser) Close() error { compressed := z.enc.EncodeAll(z.buf.Bytes(), nil) _, err := io.Copy(z.writer, bytes.NewReader(compressed)) return err } func (c *compressor) Decompress(r io.Reader) (io.Reader, error) { var err error var found bool var decoder *zstd.Decoder // Note: avoid the use of zstd.Decoder.DecodeAll here, since // malicious payloads could DoS us with a decompression bomb. decoder, found = c.decoderPool.Get().(*zstd.Decoder) if !found { decoder, err = zstd.NewReader(r, decoderOptions...) if err != nil { return nil, err } } else { err = decoder.Reset(r) if err != nil { c.decoderPool.Put(decoder) return nil, err } } wrapper := &decoderWrapper{Decoder: decoder} runtime.SetFinalizer(wrapper, func(dw *decoderWrapper) { err := dw.Reset(nil) if err == nil { c.decoderPool.Put(dw.Decoder) } }) return wrapper, nil } func (c *compressor) Name() string { return Name } go-grpc-compression-1.2.3/internal/zstd/zstd_test.go000066400000000000000000000055261463032624700226030ustar00rootroot00000000000000/* * * Copyright 2021 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package zstd import ( "bytes" "context" "io/ioutil" "net" "testing" "github.com/klauspost/compress/zstd" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/encoding" "google.golang.org/grpc/test/bufconn" "github.com/mostynb/go-grpc-compression/internal/testserver" ) const ( bufSize = 1024 message = "Message Request zSTD" ) func TestRegisteredCompression(t *testing.T) { clobbering := true PretendInit(clobbering) for _, lvl := range []zstd.EncoderLevel{zstd.SpeedFastest, zstd.SpeedDefault, zstd.SpeedBetterCompression, zstd.SpeedBestCompression} { require.NoError(t, SetLevel(lvl)) comp := encoding.GetCompressor(Name) require.NotNil(t, comp) assert.Equal(t, Name, comp.Name()) buf := bytes.NewBuffer(make([]byte, 0, bufSize)) wc, err := comp.Compress(buf) require.NoError(t, err) _, err = wc.Write([]byte(message)) require.NoError(t, err) assert.NoError(t, wc.Close()) r, err := comp.Decompress(buf) require.NoError(t, err) expected, err := ioutil.ReadAll(r) require.NoError(t, err) assert.Equal(t, message, string(expected)) } } func TestRoundTrip(t *testing.T) { clobbering := true PretendInit(clobbering) lis := bufconn.Listen(bufSize) t.Cleanup(func() { assert.NoError(t, lis.Close()) }) done := make(chan struct{}, 1) s := grpc.NewServer() defer func() { s.GracefulStop() <-done }() testserver.RegisterTestServerServer(s, &testserver.EchoTestServer{}) go func() { if err := s.Serve(lis); err != nil && err != grpc.ErrServerStopped { t.Errorf("Server exited with error: %v", err) } done <- struct{}{} }() conn, err := grpc.NewClient("passthrough://bufnet", grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return lis.Dial() }), grpc.WithDefaultCallOptions(grpc.UseCompressor(Name)), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) t.Cleanup(func() { assert.NoError(t, conn.Close()) }) client := testserver.NewTestServerClient(conn) resp, err := client.SendMessage(context.Background(), &testserver.MessageRequest{Request: message}) require.NoError(t, err) assert.Equal(t, message, resp.Response) } go-grpc-compression-1.2.3/lz4/000077500000000000000000000000001463032624700161325ustar00rootroot00000000000000go-grpc-compression-1.2.3/lz4/lz4.go000066400000000000000000000023421463032624700171730ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/lz4 is a wrapper for // using github.com/pierrec/lz4 with gRPC. // // If you import this package, it will register itself as the encoder for // the "lz4" compressor, overriding any previously registered compressors // with this name. // // If you don't want to override previously registered "lz4" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/nonclobbering/lz4 package lz4 import ( internallz4 "github.com/mostynb/go-grpc-compression/internal/lz4" ) const Name = internallz4.Name func init() { clobbering := true internallz4.PretendInit(clobbering) } go-grpc-compression-1.2.3/nonclobbering/000077500000000000000000000000001463032624700202425ustar00rootroot00000000000000go-grpc-compression-1.2.3/nonclobbering/experimental/000077500000000000000000000000001463032624700227375ustar00rootroot00000000000000go-grpc-compression-1.2.3/nonclobbering/experimental/klauspost_snappy/000077500000000000000000000000001463032624700263565ustar00rootroot00000000000000go-grpc-compression-1.2.3/nonclobbering/experimental/klauspost_snappy/klauspost_snappy.go000066400000000000000000000032421463032624700323250ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/nonclobbering/klauspost_snappy // is a wrapper for using github.com/klauspost/compress/s2 in snappy // compatibility mode with gRPC. It might be more efficient than // github.com/mostynb/go-grpc-compression/snappy and // github.com/mostynb/go-grpc-compression/nonclobbering/snappy // packages which make use of github.com/golang/snappy. // // Note that this is registered under the name "snappy" with gRPC, so only // one of these packages should be used at a time. // // If you import this package, it will only register itself as the encoder // for the "snappy" compressor if no other compressors have already been // registered with that name. // // If you do want to override previously registered "snappy" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/klauspost_snappy package klauspost_snappy import ( internalsnappy "github.com/mostynb/go-grpc-compression/internal/klauspost_snappy" ) const Name = internalsnappy.Name func init() { clobbering := false internalsnappy.PretendInit(clobbering) } go-grpc-compression-1.2.3/nonclobbering/experimental/s2/000077500000000000000000000000001463032624700232635ustar00rootroot00000000000000go-grpc-compression-1.2.3/nonclobbering/experimental/s2/s2.go000066400000000000000000000024311463032624700241360ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/nonclobbering/experimental/s2 // is a wrapper for using github.com/klauspost/compress/s2 stream compression // with gRPC. // // If you import this package, it will only register itself as the encoder // for the "s2" compressor if no other compressors have already been // registered with that name. // // If you do want to override previously registered "s2" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/experimental/s2 package s2 import ( internals2 "github.com/mostynb/go-grpc-compression/internal/s2" ) const Name = internals2.Name func init() { clobbering := false internals2.PretendInit(clobbering) } go-grpc-compression-1.2.3/nonclobbering/lz4/000077500000000000000000000000001463032624700207535ustar00rootroot00000000000000go-grpc-compression-1.2.3/nonclobbering/lz4/lz4.go000066400000000000000000000023501463032624700220130ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/nonclobbering/lz4 is a // wrapper for using github.com/pierrec/lz4 with gRPC. // // If you import this package, it will only register itself as the encoder // for the "lz4" compressor if no other compressors have already been // registered with that name. // // If you do want to override previously registered "lz4" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/lz4 package lz4 import ( internallz4 "github.com/mostynb/go-grpc-compression/internal/lz4" ) const Name = internallz4.Name func init() { clobbering := false internallz4.PretendInit(clobbering) } go-grpc-compression-1.2.3/nonclobbering/snappy/000077500000000000000000000000001463032624700215545ustar00rootroot00000000000000go-grpc-compression-1.2.3/nonclobbering/snappy/snappy.go000066400000000000000000000024051463032624700234160ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/nonclobbering/snappy is // a wrapper for using github.com/golang/snappy with gRPC. // // If you import this package, it will only register itself as the encoder // for the "snappy" compressor if no other compressors have already been // registered with that name. // // If you do want to override previously registered "snappy" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/snappy package snappy import ( internalsnappy "github.com/mostynb/go-grpc-compression/internal/snappy" ) const Name = internalsnappy.Name func init() { clobbering := false internalsnappy.PretendInit(clobbering) } go-grpc-compression-1.2.3/nonclobbering/zstd/000077500000000000000000000000001463032624700212265ustar00rootroot00000000000000go-grpc-compression-1.2.3/nonclobbering/zstd/zstd.go000066400000000000000000000035661463032624700225530ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/nonclobbering/zstd is a // wrapper for using github.com/klauspost/compress/zstd with gRPC. // // If you import this package, it will only register itself as the encoder // for the "zstd" compressor if no other compressors have already been // registered with that name. // // If you do want to override previously registered "zstd" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/zstd package zstd import ( internalzstd "github.com/mostynb/go-grpc-compression/internal/zstd" "github.com/klauspost/compress/zstd" ) const Name = internalzstd.Name func init() { clobbering := false internalzstd.PretendInit(clobbering) } var ErrNotInUse = internalzstd.ErrNotInUse // SetLevel updates the registered compressor to use a particular compression // level. Returns ErrNotInUse if this module isn't registered (because it has // been overridden by another encoder with the same name), or any error // returned by zstd.NewWriter(nil, zstd.WithEncoderLevel(level). // // NOTE: this function is not threadsafe and must only be called from an init // function or from the main goroutine before any other goroutines have been // created. func SetLevel(level zstd.EncoderLevel) error { return internalzstd.SetLevel(level) } go-grpc-compression-1.2.3/snappy/000077500000000000000000000000001463032624700167335ustar00rootroot00000000000000go-grpc-compression-1.2.3/snappy/snappy.go000066400000000000000000000023771463032624700206050ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/snappy is a wrapper for // using github.com/golang/snappy with gRPC. // // If you import this package, it will register itself as the encoder for // the "snappy" compressor, overriding any previously registered compressors // with this name. // // If you don't want to override previously registered "snappy" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/nonclobbering/snappy package snappy import ( internalsnappy "github.com/mostynb/go-grpc-compression/internal/snappy" ) const Name = internalsnappy.Name func init() { clobbering := true internalsnappy.PretendInit(clobbering) } go-grpc-compression-1.2.3/zstd/000077500000000000000000000000001463032624700164055ustar00rootroot00000000000000go-grpc-compression-1.2.3/zstd/zstd.go000066400000000000000000000035601463032624700177240ustar00rootroot00000000000000// Copyright 2023 Mostyn Bramley-Moore. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package github.com/mostynb/go-grpc-compression/zstd is a wrapper for // using github.com/klauspost/compress/zstd with gRPC. // // If you import this package, it will register itself as the encoder for // the "zstd" compressor, overriding any previously registered compressors // with this name. // // If you don't want to override previously registered "zstd" compressors, // then you should instead import // github.com/mostynb/go-grpc-compression/nonclobbering/zstd package zstd import ( internalzstd "github.com/mostynb/go-grpc-compression/internal/zstd" "github.com/klauspost/compress/zstd" ) const Name = internalzstd.Name func init() { clobbering := true internalzstd.PretendInit(clobbering) } var ErrNotInUse = internalzstd.ErrNotInUse // SetLevel updates the registered compressor to use a particular compression // level. Returns ErrNotInUse if this module isn't registered (because it has // been overridden by another encoder with the same name), or any error // returned by zstd.NewWriter(nil, zstd.WithEncoderLevel(level). // // NOTE: this function is not threadsafe and must only be called from an init // function or from the main goroutine before any other goroutines have been // created. func SetLevel(level zstd.EncoderLevel) error { return internalzstd.SetLevel(level) }