mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
deps: bump to go-criu v8.3.0
go-criu v8.3.0 switches to protobuf-go-lite, which helps to remove google.golang.org/protobuf dependency from here, reducing the runc binary size from ~16M to ~14M. The only missing piece is proto.String, proto.Bool, proto.Int32 etc. helpers that return a pointer to a given variable. Those are replaced by a generic mkPtr, which in turn is to be replaced by the new builtin once Go < 1.26 is no longer supported. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
*.pb.* linguist-generated
|
||||
@@ -0,0 +1,8 @@
|
||||
/.cache/
|
||||
/.gocache/
|
||||
/bin/
|
||||
/vendor/
|
||||
.#*
|
||||
.aider*
|
||||
debug.test*
|
||||
/node_modules
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
linters:
|
||||
enable:
|
||||
- depguard
|
||||
- goimports
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- importas
|
||||
- ineffassign
|
||||
- misspell
|
||||
- revive
|
||||
- staticcheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unused
|
||||
|
||||
disable:
|
||||
- errcheck
|
||||
|
||||
run:
|
||||
concurrency: 4
|
||||
modules-download-mode: vendor
|
||||
|
||||
skip-dirs:
|
||||
- hack
|
||||
|
||||
linters-settings:
|
||||
staticcheck:
|
||||
checks:
|
||||
- all
|
||||
- '-SA1012' # Allow passing nil contexts.
|
||||
- '-SA1019' # Allow calling deprecated symbols.
|
||||
|
||||
importas:
|
||||
# Do not allow unaliased imports of aliased packages.
|
||||
no-unaliased: true
|
||||
|
||||
maligned:
|
||||
suggest-new: true
|
||||
|
||||
depguard:
|
||||
rules:
|
||||
main:
|
||||
deny:
|
||||
- pkg: io/ioutil
|
||||
desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil
|
||||
#- pkg: "github.com/stretchr/testify/assert"
|
||||
# desc: Use "gotest.tools/v3/assert" instead
|
||||
#- pkg: "github.com/stretchr/testify/require"
|
||||
# desc: Use "gotest.tools/v3/assert" instead
|
||||
- pkg: "github.com/stretchr/testify/suite"
|
||||
desc: Do not use
|
||||
|
||||
revive:
|
||||
rules:
|
||||
- name: package-comments
|
||||
disabled: true
|
||||
|
||||
issues:
|
||||
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||
max-issues-per-linter: 0
|
||||
|
||||
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
|
||||
max-same-issues: 0
|
||||
|
||||
exclude:
|
||||
- G601
|
||||
- G306
|
||||
- G204
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
*.pb.go
|
||||
*.pb.ts
|
||||
go.sum
|
||||
testdata
|
||||
thirdparty
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
Copyright (c) 2024-2025 Aperture Robotics, LLC. All rights reserved.
|
||||
Copyright (c) 2024-2025 Christian Stewart <christian@aperture.us>. All rights reserved.
|
||||
Copyright (c) 2021, PlanetScale Inc. All rights reserved.
|
||||
Copyright (c) 2013, The GoGo Authors. All rights reserved.
|
||||
Copyright (c) 2018 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
SHELL:=bash
|
||||
PROTOWRAP=hack/bin/protowrap
|
||||
GOIMPORTS=hack/bin/goimports
|
||||
GOFUMPT=hack/bin/gofumpt
|
||||
GOLANGCI_LINT=hack/bin/golangci-lint
|
||||
PROTOC_GEN_GO=hack/bin/protoc-gen-go-lite
|
||||
GOLIST=go list -f "{{ .Dir }}" -m
|
||||
|
||||
export GO111MODULE=on
|
||||
undefine GOOS
|
||||
undefine GOARCH
|
||||
|
||||
all:
|
||||
|
||||
vendor:
|
||||
go mod vendor
|
||||
|
||||
$(GOIMPORTS):
|
||||
cd ./hack; \
|
||||
go build -v \
|
||||
-o ./bin/goimports \
|
||||
golang.org/x/tools/cmd/goimports
|
||||
|
||||
$(GOFUMPT):
|
||||
cd ./hack; \
|
||||
go build -v \
|
||||
-o ./bin/gofumpt \
|
||||
mvdan.cc/gofumpt
|
||||
|
||||
$(PROTOWRAP):
|
||||
cd ./hack; \
|
||||
go build -v \
|
||||
-o ./bin/protowrap \
|
||||
github.com/aperturerobotics/goprotowrap/cmd/protowrap
|
||||
|
||||
$(GOLANGCI_LINT):
|
||||
cd ./hack; \
|
||||
go build -v \
|
||||
-o ./bin/golangci-lint \
|
||||
github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||
|
||||
$(PROTOC_GEN_GO):
|
||||
cd ./hack; \
|
||||
go build -v \
|
||||
-o ./bin/protoc-gen-go-lite \
|
||||
github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite
|
||||
|
||||
.PHONY: protoc-gen-go-lite-tool
|
||||
protoc-gen-go-lite-tool:
|
||||
cd ./hack; \
|
||||
go build -v \
|
||||
-o ./bin/protoc-gen-go-lite \
|
||||
github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite
|
||||
|
||||
.PHONY: build
|
||||
build: vendor
|
||||
go build -v
|
||||
|
||||
.PHONY: lint
|
||||
lint: $(GOLANGCI_LINT)
|
||||
$(GOLANGCI_LINT) run --timeout=10m
|
||||
|
||||
.PHONY: fix
|
||||
fix: $(GOLANGCI_LINT)
|
||||
$(GOLANGCI_LINT) run --fix --timeout=10m
|
||||
|
||||
.PHONY: format
|
||||
format: $(GOFUMPT) $(GOIMPORTS)
|
||||
$(GOIMPORTS) -w ./
|
||||
$(GOFUMPT) -w ./
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
go test -v ./...
|
||||
|
||||
.PHONY: gengo
|
||||
gengo: $(GOIMPORTS) $(PROTOWRAP) protoc-gen-go-lite-tool
|
||||
shopt -s globstar; \
|
||||
set -eo pipefail; \
|
||||
export PROJECT=$$(go list -m); \
|
||||
export PATH=$$(pwd)/hack/bin:$${PATH}; \
|
||||
mkdir -p $$(pwd)/vendor/$$(dirname $${PROJECT}); \
|
||||
rm $$(pwd)/vendor/$${PROJECT} || true; \
|
||||
ln -s $$(pwd) $$(pwd)/vendor/$${PROJECT} ; \
|
||||
protogen() { \
|
||||
$(PROTOWRAP) \
|
||||
-I $$(pwd)/vendor \
|
||||
-I $$(pwd) \
|
||||
--go-lite_out=$$(pwd)/vendor \
|
||||
--proto_path $$(pwd)/vendor \
|
||||
--print_structure \
|
||||
--only_specified_files \
|
||||
$$2 \
|
||||
$$(\
|
||||
git \
|
||||
ls-files "$$1" |\
|
||||
xargs printf -- \
|
||||
"$$(pwd)/vendor/$${PROJECT}/%s "); \
|
||||
}; \
|
||||
for d in ./types/known/*; do \
|
||||
protogen "$${d}/*.proto" "--go-lite_opt=features=marshal+marshal_strict+unmarshal+unmarshal_unsafe+size+equal+clone+text"; \
|
||||
done; \
|
||||
protogen "./types/descriptorpb/*.proto" ""; \
|
||||
protogen "./types/pluginpb/*.proto" ""; \
|
||||
protogen "./testproto/*.proto" ""; \
|
||||
rm $$(pwd)/vendor/$${PROJECT} || true
|
||||
$(GOIMPORTS) -w ./
|
||||
|
||||
.PHONY: check-gengo
|
||||
check-gengo: gengo
|
||||
git diff --exit-code HEAD
|
||||
test -z "$$(git ls-files --others --exclude-standard)" || (git ls-files --others --exclude-standard; exit 1)
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
Additional IP Rights Grant (Patents)
|
||||
|
||||
"This implementation" means the copyrightable works distributed by
|
||||
Google as part of the Go project.
|
||||
|
||||
Google 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,
|
||||
transfer and otherwise run, modify and propagate the contents of this
|
||||
implementation of Go, where such license applies only to those patent
|
||||
claims, both currently owned or controlled by Google and acquired in
|
||||
the future, licensable by Google that are necessarily infringed by this
|
||||
implementation of Go. This grant does not include claims that would be
|
||||
infringed only as a consequence of further modification of this
|
||||
implementation. If you or your agent or exclusive licensee institute or
|
||||
order or agree to the institution of patent litigation against any
|
||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that this implementation of Go or any code incorporated within this
|
||||
implementation of Go constitutes direct or contributory patent
|
||||
infringement, or inducement of patent infringement, then any patent
|
||||
rights granted to you under this License for this implementation of Go
|
||||
shall terminate as of the date such litigation is filed.
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
# protobuf-go-lite
|
||||
|
||||
[![GoDoc Widget]][GoDoc] [![Go Report Card Widget]][Go Report Card] [![DeepWiki Widget]][DeepWiki]
|
||||
|
||||
[GoDoc]: https://godoc.org/github.com/aperturerobotics/protobuf-go-lite
|
||||
[GoDoc Widget]: https://godoc.org/github.com/aperturerobotics/protobuf-go-lite?status.svg
|
||||
[Go Report Card Widget]: https://goreportcard.com/badge/github.com/aperturerobotics/protobuf-go-lite
|
||||
[Go Report Card]: https://goreportcard.com/report/github.com/aperturerobotics/protobuf-go-lite
|
||||
[DeepWiki Widget]: https://img.shields.io/badge/DeepWiki-aperturerobotics%2Fprotobuf--go--lite-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==
|
||||
[DeepWiki]: https://deepwiki.com/aperturerobotics/protobuf-go-lite
|
||||
|
||||
**protobuf-go-lite** is a stripped-down version of the [protobuf-go] code
|
||||
generator modified to work without reflection and merged with [vtprotobuf] to
|
||||
provide modular features with static code generation for marshal/unmarshal,
|
||||
size, clone, and equal. It bundles a fork of [protoc-gen-go-json] for JSON.
|
||||
|
||||
[protobuf-go]: https://github.com/protocolbuffers/protobuf-go
|
||||
[vtprotobuf]: https://github.com/planetscale/vtprotobuf
|
||||
[protoc-gen-go-json]: https://github.com/TheThingsIndustries/protoc-gen-go-json
|
||||
|
||||
Static code generation without reflection is more efficient at runtime and
|
||||
results in smaller code binaries. It also provides better support for [tinygo]
|
||||
which has limited reflection support.
|
||||
|
||||
[tinygo]: https://github.com/tinygo-org/tinygo
|
||||
|
||||
protobuf-go-lite supports Edition 2024 schemas that resolve to the open Go API
|
||||
and static, reflect-free generated output. The default `features=all` path
|
||||
supports explicit and implicit presence, legacy required fields, packed
|
||||
encoding, delimited message encoding, oneofs, maps, clone/equal, text,
|
||||
unmarshal, unsafe unmarshal, and JSON when the resolved JSON format is
|
||||
`ALLOW`.
|
||||
|
||||
protobuf-go-lite rejects Edition schemas that require closed enum semantics,
|
||||
`LEGACY_BEST_EFFORT` JSON, or explicit hybrid/opaque Go APIs. It does not
|
||||
support fieldmasks and extensions.
|
||||
|
||||
### Ecosystem
|
||||
|
||||
Lightweight Protobuf 3 RPCs are implemented in [StaRPC] for Go and TypeScript.
|
||||
|
||||
[StaRPC]: https://github.com/aperturerobotics/starpc
|
||||
|
||||
[protoc-gen-doc] is recommended for generating documentation.
|
||||
|
||||
[protoc-gen-doc]: https://github.com/pseudomuto/protoc-gen-doc
|
||||
|
||||
[protobuf-es-lite] is recommended for lightweight TypeScript protobufs.
|
||||
|
||||
[protobuf-es-lite]: https://github.com/aperturerobotics/protobuf-es-lite
|
||||
|
||||
## Protobuf
|
||||
|
||||
[protocol buffers](https://protobuf.dev) are a cross-platform cross-language
|
||||
message serialization format. Protobuf is a language for specifying the schema
|
||||
for structured data. This schema is compiled into language specific bindings.
|
||||
This project provides both a tool to generate Go code for the protocol buffer
|
||||
language, and also the runtime implementation to handle serialization of
|
||||
messages in Go.
|
||||
|
||||
See the [protocol buffer developer guide](https://protobuf.dev/overview) for
|
||||
more information about protocol buffers themselves.
|
||||
|
||||
## Example
|
||||
|
||||
See the [protobuf-project](https://github.com/aperturerobotics/protobuf-project)
|
||||
template for an example of how to use this package and vtprotobuf together with
|
||||
protowrap to generate protobufs for your project.
|
||||
|
||||
This package is available at **github.com/aperturerobotics/protobuf-go-lite**.
|
||||
|
||||
## Package index
|
||||
|
||||
Summary of the packages provided by this module:
|
||||
|
||||
* [`compiler/protogen`](https://pkg.go.dev/github.com/aperturerobotics/protobuf-go-lite/compiler/protogen):
|
||||
Package `protogen` provides support for writing protoc plugins.
|
||||
* [`cmd/protoc-gen-go-lite`](https://pkg.go.dev/github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite):
|
||||
The `protoc-gen-go-lite` binary is a protoc plugin to generate a Go protocol
|
||||
buffer package.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Install `protoc-gen-go-lite`:
|
||||
|
||||
```
|
||||
go install github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite@latest
|
||||
```
|
||||
|
||||
2. Update your `protoc` generator to use the new plug-in.
|
||||
|
||||
```
|
||||
for name in $(PROTO_SRC_NAMES); do \
|
||||
protoc \
|
||||
--plugin protoc-gen-go-lite="${GOBIN}/protoc-gen-go-lite" \
|
||||
--go-lite_out=. \
|
||||
--go-lite_opt=features=marshal+unmarshal+size+equal+clone \
|
||||
proto/$${name}.proto; \
|
||||
done
|
||||
```
|
||||
|
||||
`protobuf-go-lite` replaces `protoc-gen-go` and `protoc-gen-go-vtprotobuf` and should not be used with those generators.
|
||||
|
||||
Check out the [template](https://github.com/aperturerobotics/template) for a quick start!
|
||||
|
||||
## Available features
|
||||
|
||||
The following additional features from vtprotobuf can be enabled:
|
||||
|
||||
- `size`: generates a `func (p *YourProto) SizeVT() int` helper that behaves identically to calling `proto.Size(p)` on the message, except the size calculation is fully unrolled and does not use reflection. This helper function can be used directly, and it'll also be used by the `marshal` codegen to ensure the destination buffer is properly sized before ProtoBuf objects are marshalled to it.
|
||||
|
||||
- `equal`: generates the following helper methods
|
||||
|
||||
- `func (this *YourProto) EqualVT(that *YourProto) bool`: this function behaves almost identically to calling `proto.Equal(this, that)` on messages, except the equality calculation is fully unrolled and does not use reflection. This helper function can be used directly.
|
||||
|
||||
- `func (this *YourProto) EqualMessageVT(thatMsg any) bool`: this function behaves like the above `this.EqualVT(that)`, but allows comparing against arbitrary proto messages. If `thatMsg` is not of type `*YourProto`, false is returned. The uniform signature provided by this method allows accessing this method via type assertions even if the message type is not known at compile time. This allows implementing a generic `func EqualVT(proto.Message, proto.Message) bool` without reflection.
|
||||
|
||||
- `marshal`: generates the following helper methods
|
||||
|
||||
- `func (p *YourProto) MarshalVT() ([]byte, error)`: this function behaves identically to calling `proto.Marshal(p)`, except the actual marshalling has been fully unrolled and does not use reflection or allocate memory. This function simply allocates a properly sized buffer by calling `SizeVT` on the message and then uses `MarshalToSizedBufferVT` to marshal to it.
|
||||
|
||||
- `func (p *YourProto) MarshalToVT(data []byte) (int, error)`: this function can be used to marshal a message to an existing buffer. The buffer must be large enough to hold the marshalled message, otherwise this function will panic. It returns the number of bytes marshalled. This function is useful e.g. when using memory pooling to re-use serialization buffers.
|
||||
|
||||
- `func (p *YourProto) MarshalToSizedBufferVT(data []byte) (int, error)`: this function behaves like `MarshalTo` but expects that the input buffer has the exact size required to hold the message, otherwise it will panic.
|
||||
|
||||
- `marshal_strict`: generates the following helper methods
|
||||
|
||||
- `func (p *YourProto) MarshalVTStrict() ([]byte, error)`: this function behaves like `MarshalVT`, except fields are marshalled in a strict order by field's numbers they were declared in .proto file.
|
||||
|
||||
- `func (p *YourProto) MarshalToVTStrict(data []byte) (int, error)`: this function behaves like `MarshalToVT`, except fields are marshalled in a strict order by field's numbers they were declared in .proto file.
|
||||
|
||||
- `func (p *YourProto) MarshalToSizedBufferVTStrict(data []byte) (int, error)`: this function behaves like `MarshalToSizedBufferVT`, except fields are marshalled in a strict order by field's numbers they were declared in .proto file.
|
||||
|
||||
|
||||
- `unmarshal`: generates a `func (p *YourProto) UnmarshalVT(data []byte)` that behaves similarly to calling `proto.Unmarshal(data, p)` on the message, except the unmarshalling is performed by unrolled codegen without using reflection and allocating as little memory as possible. If the receiver `p` is **not** fully zeroed-out, the unmarshal call will actually behave like `proto.Merge(data, p)`. This is because the `proto.Unmarshal` in the ProtoBuf API is implemented by resetting the destination message and then calling `proto.Merge` on it. To ensure proper `Unmarshal` semantics, ensure you've called `proto.Reset` on your message before calling `UnmarshalVT`, or that your message has been newly allocated.
|
||||
|
||||
- `unmarshal_unsafe` generates a `func (p *YourProto) UnmarshalVTUnsafe(data []byte)` that behaves like `UnmarshalVT`, except it unsafely casts slices of data to `bytes` and `string` fields instead of copying them to newly allocated arrays, so that it performs less allocations. **Data received from the wire has to be left untouched for the lifetime of the message.** Otherwise, the message's `bytes` and `string` fields can be corrupted.
|
||||
|
||||
- `clone`: generates the following helper methods
|
||||
|
||||
- `func (p *YourProto) CloneVT() *YourProto`: this function behaves similarly to calling `proto.Clone(p)` on the message, except the cloning is performed by unrolled codegen without using reflection. If the receiver `p` is `nil` a typed `nil` is returned.
|
||||
|
||||
- `func (p *YourProto) CloneMessageVT() any`: this function behaves like the above `p.CloneVT()`, but provides a uniform signature in order to be accessible via type assertions even if the type is not known at compile time. This allows implementing a generic `func CloneMessageVT() any` without reflection. If the receiver `p` is `nil`, a typed `nil` pointer of the message type will be returned inside a `any` interface.
|
||||
|
||||
- `json`: generates the following helper methods
|
||||
|
||||
- `func (p *YourProto) UnmarshalJSON(data []byte) error` behaves similarly to calling `protojson.Unmarshal(data, p)` on the message, except the unmarshalling is performed by unrolled codegen without using reflection and allocating as little memory as possible (with json-iterator/go). If the receiver `p` is **not** fully zeroed-out, the unmarshal call will actually behave like `proto.Merge(data, p)`. To ensure proper `Unmarshal` semantics, ensure you've called `proto.Reset` on your message before calling `UnmarshalJSON`, or that your message has been newly allocated.
|
||||
|
||||
- `func (p *YourProto) UnmarshalJSONValue(val *fastjson.Value) error` unmarshals a `*fastjson.Value`.
|
||||
|
||||
- `func (p *YourProto) MarshalJSON() ([]byte, error)` behaves similarly to calling `protojson.Marshal(p)` on the message, except the marshalling is performed by unrolled codegen without using reflection and allocating as little memory as possible (with json-iterator/go).
|
||||
|
||||
- Adding a `//protobuf-go-lite:disable-json` comment before a message or enum will disable the json marshaler / unmarshaler.
|
||||
|
||||
## License
|
||||
|
||||
BSD-3
|
||||
+594
@@ -0,0 +1,594 @@
|
||||
package protobuf_go_lite
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"math/bits"
|
||||
"slices"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrInvalidLength is returned when decoding a negative length.
|
||||
ErrInvalidLength = errors.New("proto: negative length found during unmarshaling")
|
||||
// ErrIntOverflow is returned when decoding a varint representation of an integer that overflows 64 bits.
|
||||
ErrIntOverflow = errors.New("proto: integer overflow")
|
||||
// ErrUnexpectedEndOfGroup is returned when decoding a group end without a corresponding group start.
|
||||
ErrUnexpectedEndOfGroup = errors.New("proto: unexpected end of group")
|
||||
)
|
||||
|
||||
// Message is the base vtprotobuf message marshal/unmarshal interface.
|
||||
type Message interface {
|
||||
// SizeVT returns the size of the message when marshaled.
|
||||
SizeVT() int
|
||||
// MarshalToSizedBufferVT marshals to a buffer that already is SizeVT bytes long.
|
||||
MarshalToSizedBufferVT(dAtA []byte) (int, error)
|
||||
// MarshalVT marshals the message with vtprotobuf.
|
||||
MarshalVT() ([]byte, error)
|
||||
// UnmarshalVT unmarshals the message object with vtprotobuf.
|
||||
UnmarshalVT(data []byte) error
|
||||
// Reset resets the message.
|
||||
Reset()
|
||||
}
|
||||
|
||||
// JSONMessage is a message with MarshalJSON and UnmarshalJSON.
|
||||
type JSONMessage interface {
|
||||
// MarshalJSON marshals the message to JSON.
|
||||
MarshalJSON() ([]byte, error)
|
||||
// UnmarshalJSON unmarshals the message from JSON.
|
||||
UnmarshalJSON(data []byte) error
|
||||
}
|
||||
|
||||
// CloneMessage is a message with a CloneMessage function.
|
||||
type CloneMessage interface {
|
||||
// Message extends the base message type.
|
||||
Message
|
||||
// CloneMessageVT clones the object.
|
||||
CloneMessageVT() CloneMessage
|
||||
}
|
||||
|
||||
// CloneVT is a message with a CloneVT function (VTProtobuf).
|
||||
type CloneVT[T comparable] interface {
|
||||
comparable
|
||||
// CloneMessage is the non-generic clone interface.
|
||||
CloneMessage
|
||||
// CloneVT clones the object.
|
||||
CloneVT() T
|
||||
}
|
||||
|
||||
// CloneVTSlice clones a slice of CloneVT messages.
|
||||
func CloneVTSlice[S ~[]E, E CloneVT[E]](s S) S {
|
||||
out := make([]E, len(s))
|
||||
var empty E
|
||||
for i := range s {
|
||||
if s[i] != empty {
|
||||
out[i] = s[i].CloneVT()
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// EqualVT is a message with a EqualVT function (VTProtobuf).
|
||||
type EqualVT[T comparable] interface {
|
||||
comparable
|
||||
// EqualVT compares against the other message for equality.
|
||||
EqualVT(other T) bool
|
||||
}
|
||||
|
||||
// CompareComparable returns a compare function to compare two comparable types.
|
||||
func CompareComparable[T comparable]() func(t1, t2 T) bool {
|
||||
return func(t1, t2 T) bool {
|
||||
return t1 == t2
|
||||
}
|
||||
}
|
||||
|
||||
// CompareEqualVT returns a compare function to compare two VTProtobuf messages.
|
||||
func CompareEqualVT[T EqualVT[T]]() func(t1, t2 T) bool {
|
||||
return func(t1, t2 T) bool {
|
||||
return IsEqualVT(t1, t2)
|
||||
}
|
||||
}
|
||||
|
||||
// IsEqualVT checks if two EqualVT objects are equal.
|
||||
func IsEqualVT[T EqualVT[T]](t1, t2 T) bool {
|
||||
var empty T
|
||||
t1Empty, t2Empty := t1 == empty, t2 == empty
|
||||
if t1Empty != t2Empty {
|
||||
return false
|
||||
}
|
||||
if t1Empty {
|
||||
return true
|
||||
}
|
||||
return t1.EqualVT(t2)
|
||||
}
|
||||
|
||||
// IsEqualVTSlice checks if two slices of EqualVT messages are equal.
|
||||
func IsEqualVTSlice[S ~[]E, E EqualVT[E]](s1, s2 S) bool {
|
||||
return slices.EqualFunc(s1, s2, CompareEqualVT[E]())
|
||||
}
|
||||
|
||||
// EncodeVarint encodes a uint64 into a varint-encoded byte slice and returns the offset of the encoded value.
|
||||
// The provided offset is the offset after the last byte of the encoded value.
|
||||
func EncodeVarint(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= SizeOfVarint(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80) //nolint:gosec
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
|
||||
// AppendVarint appends v to b as a varint-encoded uint64.
|
||||
func AppendVarint(b []byte, v uint64) []byte {
|
||||
switch {
|
||||
case v < 1<<7:
|
||||
b = append(b, byte(v))
|
||||
case v < 1<<14:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte(v>>7))
|
||||
case v < 1<<21:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte(v>>14))
|
||||
case v < 1<<28:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte((v>>14)&0x7f|0x80),
|
||||
byte(v>>21))
|
||||
case v < 1<<35:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte((v>>14)&0x7f|0x80),
|
||||
byte((v>>21)&0x7f|0x80),
|
||||
byte(v>>28))
|
||||
case v < 1<<42:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte((v>>14)&0x7f|0x80),
|
||||
byte((v>>21)&0x7f|0x80),
|
||||
byte((v>>28)&0x7f|0x80),
|
||||
byte(v>>35))
|
||||
case v < 1<<49:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte((v>>14)&0x7f|0x80),
|
||||
byte((v>>21)&0x7f|0x80),
|
||||
byte((v>>28)&0x7f|0x80),
|
||||
byte((v>>35)&0x7f|0x80),
|
||||
byte(v>>42))
|
||||
case v < 1<<56:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte((v>>14)&0x7f|0x80),
|
||||
byte((v>>21)&0x7f|0x80),
|
||||
byte((v>>28)&0x7f|0x80),
|
||||
byte((v>>35)&0x7f|0x80),
|
||||
byte((v>>42)&0x7f|0x80),
|
||||
byte(v>>49))
|
||||
case v < 1<<63:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte((v>>14)&0x7f|0x80),
|
||||
byte((v>>21)&0x7f|0x80),
|
||||
byte((v>>28)&0x7f|0x80),
|
||||
byte((v>>35)&0x7f|0x80),
|
||||
byte((v>>42)&0x7f|0x80),
|
||||
byte((v>>49)&0x7f|0x80),
|
||||
byte(v>>56))
|
||||
default:
|
||||
b = append(b,
|
||||
byte((v>>0)&0x7f|0x80),
|
||||
byte((v>>7)&0x7f|0x80),
|
||||
byte((v>>14)&0x7f|0x80),
|
||||
byte((v>>21)&0x7f|0x80),
|
||||
byte((v>>28)&0x7f|0x80),
|
||||
byte((v>>35)&0x7f|0x80),
|
||||
byte((v>>42)&0x7f|0x80),
|
||||
byte((v>>49)&0x7f|0x80),
|
||||
byte((v>>56)&0x7f|0x80),
|
||||
1)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// ConsumeVarint parses b as a varint-encoded uint64, reporting its length.
|
||||
// This returns -1 upon any error, -1 for parse error and -2 for overflow.
|
||||
func ConsumeVarint(b []byte) (v uint64, n int) {
|
||||
var y uint64
|
||||
if len(b) <= 0 {
|
||||
return 0, -1
|
||||
}
|
||||
v = uint64(b[0])
|
||||
if v < 0x80 {
|
||||
return v, 1
|
||||
}
|
||||
v -= 0x80
|
||||
|
||||
if len(b) <= 1 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[1])
|
||||
v += y << 7
|
||||
if y < 0x80 {
|
||||
return v, 2
|
||||
}
|
||||
v -= 0x80 << 7
|
||||
|
||||
if len(b) <= 2 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[2])
|
||||
v += y << 14
|
||||
if y < 0x80 {
|
||||
return v, 3
|
||||
}
|
||||
v -= 0x80 << 14
|
||||
|
||||
if len(b) <= 3 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[3])
|
||||
v += y << 21
|
||||
if y < 0x80 {
|
||||
return v, 4
|
||||
}
|
||||
v -= 0x80 << 21
|
||||
|
||||
if len(b) <= 4 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[4])
|
||||
v += y << 28
|
||||
if y < 0x80 {
|
||||
return v, 5
|
||||
}
|
||||
v -= 0x80 << 28
|
||||
|
||||
if len(b) <= 5 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[5])
|
||||
v += y << 35
|
||||
if y < 0x80 {
|
||||
return v, 6
|
||||
}
|
||||
v -= 0x80 << 35
|
||||
|
||||
if len(b) <= 6 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[6])
|
||||
v += y << 42
|
||||
if y < 0x80 {
|
||||
return v, 7
|
||||
}
|
||||
v -= 0x80 << 42
|
||||
|
||||
if len(b) <= 7 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[7])
|
||||
v += y << 49
|
||||
if y < 0x80 {
|
||||
return v, 8
|
||||
}
|
||||
v -= 0x80 << 49
|
||||
|
||||
if len(b) <= 8 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[8])
|
||||
v += y << 56
|
||||
if y < 0x80 {
|
||||
return v, 9
|
||||
}
|
||||
v -= 0x80 << 56
|
||||
|
||||
if len(b) <= 9 {
|
||||
return 0, -1
|
||||
}
|
||||
y = uint64(b[9])
|
||||
v += y << 63
|
||||
if y < 2 {
|
||||
return v, 10
|
||||
}
|
||||
return 0, -2
|
||||
}
|
||||
|
||||
// SizeOfVarint returns the size of the varint-encoded value.
|
||||
func SizeOfVarint(x uint64) (n int) {
|
||||
return (bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
|
||||
// DecodeVarint decodes a varint at the given index, returning value, new index, and error.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeVarint(b []byte, idx int) (uint64, int, error) {
|
||||
v, n := ConsumeVarint(b[idx:])
|
||||
if n < 0 {
|
||||
if n == -1 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return 0, 0, ErrIntOverflow
|
||||
}
|
||||
return v, idx + n, nil
|
||||
}
|
||||
|
||||
// DecodeVarintInt32 decodes a varint as int32.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeVarintInt32(b []byte, idx int) (int32, int, error) {
|
||||
v, n := ConsumeVarint(b[idx:])
|
||||
if n < 0 {
|
||||
if n == -1 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return 0, 0, ErrIntOverflow
|
||||
}
|
||||
return int32(v), idx + n, nil //nolint:gosec
|
||||
}
|
||||
|
||||
// DecodeVarintInt64 decodes a varint as int64.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeVarintInt64(b []byte, idx int) (int64, int, error) {
|
||||
v, n := ConsumeVarint(b[idx:])
|
||||
if n < 0 {
|
||||
if n == -1 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return 0, 0, ErrIntOverflow
|
||||
}
|
||||
return int64(v), idx + n, nil //nolint:gosec
|
||||
}
|
||||
|
||||
// DecodeVarintUint32 decodes a varint as uint32.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeVarintUint32(b []byte, idx int) (uint32, int, error) {
|
||||
v, n := ConsumeVarint(b[idx:])
|
||||
if n < 0 {
|
||||
if n == -1 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return 0, 0, ErrIntOverflow
|
||||
}
|
||||
return uint32(v), idx + n, nil //nolint:gosec
|
||||
}
|
||||
|
||||
// DecodeVarintBool decodes a varint as bool.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeVarintBool(b []byte, idx int) (bool, int, error) {
|
||||
v, n := ConsumeVarint(b[idx:])
|
||||
if n < 0 {
|
||||
if n == -1 {
|
||||
return false, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return false, 0, ErrIntOverflow
|
||||
}
|
||||
return v != 0, idx + n, nil
|
||||
}
|
||||
|
||||
// DecodeSint32 decodes a zigzag-encoded sint32.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeSint32(b []byte, idx int) (int32, int, error) {
|
||||
v, n := ConsumeVarint(b[idx:])
|
||||
if n < 0 {
|
||||
if n == -1 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return 0, 0, ErrIntOverflow
|
||||
}
|
||||
return int32((uint32(v) >> 1) ^ uint32((int32(v&1)<<31)>>31)), idx + n, nil //nolint:gosec
|
||||
}
|
||||
|
||||
// DecodeSint64 decodes a zigzag-encoded sint64.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeSint64(b []byte, idx int) (int64, int, error) {
|
||||
v, n := ConsumeVarint(b[idx:])
|
||||
if n < 0 {
|
||||
if n == -1 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return 0, 0, ErrIntOverflow
|
||||
}
|
||||
return int64((v >> 1) ^ uint64((int64(v&1)<<63)>>63)), idx + n, nil //nolint:gosec
|
||||
}
|
||||
|
||||
// DecodeFixed32 decodes a fixed 32-bit value.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeFixed32(b []byte, idx int) (uint32, int, error) {
|
||||
if idx+4 > len(b) {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
v := uint32(b[idx]) | uint32(b[idx+1])<<8 | uint32(b[idx+2])<<16 | uint32(b[idx+3])<<24
|
||||
return v, idx + 4, nil
|
||||
}
|
||||
|
||||
// DecodeFixed64 decodes a fixed 64-bit value.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeFixed64(b []byte, idx int) (uint64, int, error) {
|
||||
if idx+8 > len(b) {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
v := uint64(b[idx]) | uint64(b[idx+1])<<8 | uint64(b[idx+2])<<16 | uint64(b[idx+3])<<24 |
|
||||
uint64(b[idx+4])<<32 | uint64(b[idx+5])<<40 | uint64(b[idx+6])<<48 | uint64(b[idx+7])<<56
|
||||
return v, idx + 8, nil
|
||||
}
|
||||
|
||||
// DecodeFloat32 decodes a 32-bit float.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeFloat32(b []byte, idx int) (float32, int, error) {
|
||||
v, idx, err := DecodeFixed32(b, idx)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return math.Float32frombits(v), idx, nil
|
||||
}
|
||||
|
||||
// DecodeFloat64 decodes a 64-bit float.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeFloat64(b []byte, idx int) (float64, int, error) {
|
||||
v, idx, err := DecodeFixed64(b, idx)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return math.Float64frombits(v), idx, nil
|
||||
}
|
||||
|
||||
// DecodeBytes decodes a length-prefixed byte slice. If copy is false, returns a sub-slice.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeBytes(b []byte, idx int, cp bool) ([]byte, int, error) {
|
||||
length, idx, err := DecodeVarint(b, idx)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
l := int(length) //nolint:gosec
|
||||
if l < 0 {
|
||||
return nil, 0, ErrInvalidLength
|
||||
}
|
||||
end := idx + l
|
||||
if end < idx || end > len(b) {
|
||||
return nil, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
if cp {
|
||||
out := make([]byte, l)
|
||||
copy(out, b[idx:end])
|
||||
return out, end, nil
|
||||
}
|
||||
return b[idx:end], end, nil
|
||||
}
|
||||
|
||||
// DecodeString decodes a length-prefixed string (with copy).
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeString(b []byte, idx int) (string, int, error) {
|
||||
length, idx, err := DecodeVarint(b, idx)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
l := int(length) //nolint:gosec
|
||||
if l < 0 {
|
||||
return "", 0, ErrInvalidLength
|
||||
}
|
||||
end := idx + l
|
||||
if end < idx || end > len(b) {
|
||||
return "", 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
return string(b[idx:end]), end, nil
|
||||
}
|
||||
|
||||
// DecodeStringUnsafe decodes a length-prefixed string without copying.
|
||||
// The returned string shares memory with the input slice.
|
||||
// Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.
|
||||
func DecodeStringUnsafe(b []byte, idx int) (string, int, error) {
|
||||
length, idx, err := DecodeVarint(b, idx)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
l := int(length) //nolint:gosec
|
||||
if l < 0 {
|
||||
return "", 0, ErrInvalidLength
|
||||
}
|
||||
end := idx + l
|
||||
if end < idx || end > len(b) {
|
||||
return "", 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
if l == 0 {
|
||||
return "", end, nil
|
||||
}
|
||||
return unsafe.String(&b[idx], l), end, nil
|
||||
}
|
||||
|
||||
// SizeOfZigzag returns the size of the zigzag-encoded value.
|
||||
func SizeOfZigzag(x uint64) (n int) {
|
||||
return SizeOfVarint(uint64((x << 1) ^ uint64((int64(x) >> 63)))) //nolint
|
||||
}
|
||||
|
||||
// Skip the first record of the byte slice and return the offset of the next record.
|
||||
func Skip(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7) //nolint:gosec
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLength
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroup
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLength
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
+2
-2
@@ -22,13 +22,13 @@ rpc/rpc.proto:
|
||||
curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/rpc.proto -o $@
|
||||
|
||||
rpc/rpc.pb.go: rpc/rpc.proto
|
||||
protoc --go_out=. --go_opt=M$^=rpc/ $^
|
||||
protoc --go-lite_out=. --go-lite_opt=M$^=rpc/ $^
|
||||
|
||||
stats/stats.proto:
|
||||
curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/stats.proto -o $@
|
||||
|
||||
stats/stats.pb.go: stats/stats.proto
|
||||
protoc --go_out=. --go_opt=M$^=stats/ $^
|
||||
protoc --go-lite_out=. --go-lite_opt=M$^=stats/ $^
|
||||
|
||||
vendor:
|
||||
$(GO) mod tidy
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// Package proto provides a small helper for constructing pointers to
|
||||
// scalar values, as used by proto2-generated optional/required fields.
|
||||
//
|
||||
// protobuf-go-lite does not ship the proto.String/Int32/Bool constructors
|
||||
// that google.golang.org/protobuf/proto offers, so Ptr replaces them.
|
||||
package proto
|
||||
|
||||
// Ptr returns a pointer to v. It is handy for setting proto2 optional and
|
||||
// required scalar fields, e.g. Ptr("foo"), Ptr(true), Ptr[int32](4).
|
||||
//
|
||||
// TODO: drop this in favor of the built-in new(v) once the minimum
|
||||
// supported Go version is 1.26 or later.
|
||||
func Ptr[T any](v T) *T { return &v }
|
||||
+7
-7
@@ -9,8 +9,8 @@ import (
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
proto "github.com/checkpoint-restore/go-criu/v8/internal/proto"
|
||||
"github.com/checkpoint-restore/go-criu/v8/rpc"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// extraFilesStartFd is the first fd number assigned to cmd.ExtraFiles by os/exec.
|
||||
@@ -72,8 +72,8 @@ func (c *Criu) ensureInheritFd(opts *rpc.CriuOpts) {
|
||||
for i, key := range keys {
|
||||
fd := int32(extraFilesStartFd + i)
|
||||
opts.InheritFd = append(opts.InheritFd, &rpc.InheritFd{
|
||||
Key: proto.String(key),
|
||||
Fd: proto.Int32(fd),
|
||||
Key: proto.Ptr(key),
|
||||
Fd: proto.Ptr(fd),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy N
|
||||
}
|
||||
|
||||
if nfy != nil {
|
||||
opts.NotifyScripts = proto.Bool(true)
|
||||
opts.NotifyScripts = proto.Ptr(true)
|
||||
}
|
||||
|
||||
if features != nil {
|
||||
@@ -200,7 +200,7 @@ func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy N
|
||||
}
|
||||
|
||||
for {
|
||||
reqB, err := proto.Marshal(&req)
|
||||
reqB, err := req.MarshalVT()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy N
|
||||
}
|
||||
|
||||
resp = &rpc.CriuResp{}
|
||||
err = proto.Unmarshal(respB[:respS], resp)
|
||||
err = resp.UnmarshalVT(respB[:respS])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -259,7 +259,7 @@ func (c *Criu) doSwrkWithResp(reqType rpc.CriuReqType, opts *rpc.CriuOpts, nfy N
|
||||
|
||||
req = rpc.CriuReq{
|
||||
Type: &respType,
|
||||
NotifySuccess: proto.Bool(true),
|
||||
NotifySuccess: proto.Ptr(true),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11865
-1223
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user