mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
build(deps): bump the go-opentelemetry-io group with 6 updates (#7283)
Bumps the go-opentelemetry-io group with 6 updates: | Package | From | To | | --- | --- | --- | | [go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp](https://github.com/open-telemetry/opentelemetry-go-contrib) | `0.58.0` | `0.59.0` | | [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go) | `1.33.0` | `1.34.0` | | [go.opentelemetry.io/otel/exporters/otlp/otlptrace](https://github.com/open-telemetry/opentelemetry-go) | `1.33.0` | `1.34.0` | | [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc](https://github.com/open-telemetry/opentelemetry-go) | `1.33.0` | `1.34.0` | | [go.opentelemetry.io/otel/sdk](https://github.com/open-telemetry/opentelemetry-go) | `1.33.0` | `1.34.0` | | [go.opentelemetry.io/otel/trace](https://github.com/open-telemetry/opentelemetry-go) | `1.33.0` | `1.34.0` | Updates `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` from 0.58.0 to 0.59.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go-contrib/compare/zpages/v0.58.0...zpages/v0.59.0) Updates `go.opentelemetry.io/otel` from 1.33.0 to 1.34.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.33.0...v1.34.0) Updates `go.opentelemetry.io/otel/exporters/otlp/otlptrace` from 1.33.0 to 1.34.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.33.0...v1.34.0) Updates `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` from 1.33.0 to 1.34.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.33.0...v1.34.0) Updates `go.opentelemetry.io/otel/sdk` from 1.33.0 to 1.34.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.33.0...v1.34.0) Updates `go.opentelemetry.io/otel/trace` from 1.33.0 to 1.34.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.33.0...v1.34.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-opentelemetry-io - dependency-name: go.opentelemetry.io/otel dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-opentelemetry-io - dependency-name: go.opentelemetry.io/otel/exporters/otlp/otlptrace dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-opentelemetry-io - dependency-name: go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-opentelemetry-io - dependency-name: go.opentelemetry.io/otel/sdk dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-opentelemetry-io - dependency-name: go.opentelemetry.io/otel/trace dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-opentelemetry-io ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -37,12 +37,12 @@ require (
|
||||
github.com/tchap/go-patricia/v2 v2.3.2
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
|
||||
github.com/yashtewari/glob-intersection v0.2.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0
|
||||
go.opentelemetry.io/otel v1.33.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0
|
||||
go.opentelemetry.io/otel/sdk v1.33.0
|
||||
go.opentelemetry.io/otel/trace v1.33.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0
|
||||
go.opentelemetry.io/otel v1.34.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0
|
||||
go.opentelemetry.io/otel/sdk v1.34.0
|
||||
go.opentelemetry.io/otel/trace v1.34.0
|
||||
go.uber.org/automaxprocs v1.6.0
|
||||
golang.org/x/net v0.34.0
|
||||
golang.org/x/time v0.9.0
|
||||
@@ -67,7 +67,7 @@ require (
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/google/flatbuffers v24.3.25+incompatible // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
@@ -95,8 +95,8 @@ require (
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.33.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.34.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
@@ -105,9 +105,9 @@ require (
|
||||
golang.org/x/sys v0.29.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/tools v0.22.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
|
||||
google.golang.org/protobuf v1.35.2 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
|
||||
google.golang.org/protobuf v1.36.3 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
)
|
||||
|
||||
|
||||
@@ -111,8 +111,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 h1:TmHmbvxPmaegwhDubVz0lICL0J5Ka2vwTzhoePEXsGE=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0/go.mod h1:qztMSjm835F2bXf+5HKAPIS5qsmQDqZna/PgVt4rWtI=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1/go.mod h1:RBRO7fro65R6tjKzYgLAFo0t1QEXY1Dp+i/bvpRiqiQ=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
@@ -227,24 +227,24 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 h1:yd02MEjBdJkG3uabWP9apV+OuWRIXGDuJEUJbOHmCFU=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0/go.mod h1:umTcuxiv1n/s/S6/c2AT/g2CQ7u5C59sHDNmfSwgz7Q=
|
||||
go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
|
||||
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 h1:Vh5HayB/0HHfOQA7Ctx69E/Y/DcQSMPpKANYVMQ7fBA=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0/go.mod h1:cpgtDBaqD/6ok/UG0jT15/uKjAY8mRA53diogHBg3UI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0 h1:5pojmb1U1AogINhN3SurB+zm/nIcusopeBNp42f45QM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0/go.mod h1:57gTHJSE5S1tqg+EKsLPlTWhpHMsWlVmer+LA926XiA=
|
||||
go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5WtEnklQ=
|
||||
go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M=
|
||||
go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM=
|
||||
go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I=
|
||||
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
|
||||
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0 h1:OeNbIYk/2C15ckl7glBlOBp5+WlYsOElzTNmiPW/x60=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0/go.mod h1:7Bept48yIeqxP2OZ9/AqIpYS94h2or0aB4FypJTc8ZM=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0 h1:tgJ0uaNS4c98WRNUEx5U3aDlrDOI5Rs+1Vifcw4DJ8U=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0/go.mod h1:U7HYyW0zt/a9x5J1Kjs+r1f/d4ZHnYFclhYY2+YbeoE=
|
||||
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
|
||||
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
|
||||
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
|
||||
go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
|
||||
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
|
||||
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
|
||||
go.opentelemetry.io/proto/otlp v1.4.0 h1:TA9WRvW6zMwP+Ssb6fLoUIuirti1gGbP28GcKG1jgeg=
|
||||
go.opentelemetry.io/proto/otlp v1.4.0/go.mod h1:PPBWZIP98o2ElSqI35IHfu7hIhSwvc5N38Jw8pXuGFY=
|
||||
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
|
||||
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
|
||||
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
|
||||
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
|
||||
@@ -352,10 +352,10 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 h1:CkkIfIt50+lT6NHAVoRYEyAvQGFM7xEwXUUywFvEb3Q=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576/go.mod h1:1R3kvZ1dtP3+4p4d3G8uJ8rFk/fWlScl38vanWACI08=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 h1:8ZmaLZE4XWrtU3MyClkYqqtl6Oegr3235h7jxsDyqCY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f h1:gap6+3Gk41EItBuyi4XX/bp4oqJ3UwuIMl25yGinuAA=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:Ic02D47M+zbarjYYUlK57y316f2MoN0gjAwI3f2S95o=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
@@ -372,8 +372,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
|
||||
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ func populateFieldValueFromPath(msgValue protoreflect.Message, fieldPath []strin
|
||||
}
|
||||
|
||||
// Check if oneof already set
|
||||
if of := fieldDescriptor.ContainingOneof(); of != nil {
|
||||
if of := fieldDescriptor.ContainingOneof(); of != nil && !of.IsSynthetic() {
|
||||
if f := msgValue.WhichOneof(of); f != nil {
|
||||
return fmt.Errorf("field already set for oneof %q", of.FullName().Name())
|
||||
}
|
||||
|
||||
+29
-16
@@ -12,6 +12,7 @@ import (
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
@@ -21,15 +22,16 @@ type middleware struct {
|
||||
operation string
|
||||
server string
|
||||
|
||||
tracer trace.Tracer
|
||||
propagators propagation.TextMapPropagator
|
||||
spanStartOptions []trace.SpanStartOption
|
||||
readEvent bool
|
||||
writeEvent bool
|
||||
filters []Filter
|
||||
spanNameFormatter func(string, *http.Request) string
|
||||
publicEndpoint bool
|
||||
publicEndpointFn func(*http.Request) bool
|
||||
tracer trace.Tracer
|
||||
propagators propagation.TextMapPropagator
|
||||
spanStartOptions []trace.SpanStartOption
|
||||
readEvent bool
|
||||
writeEvent bool
|
||||
filters []Filter
|
||||
spanNameFormatter func(string, *http.Request) string
|
||||
publicEndpoint bool
|
||||
publicEndpointFn func(*http.Request) bool
|
||||
metricAttributesFn func(*http.Request) []attribute.KeyValue
|
||||
|
||||
semconv semconv.HTTPServer
|
||||
}
|
||||
@@ -79,6 +81,7 @@ func (h *middleware) configure(c *config) {
|
||||
h.publicEndpointFn = c.PublicEndpointFn
|
||||
h.server = c.ServerName
|
||||
h.semconv = semconv.NewHTTPServer(c.Meter)
|
||||
h.metricAttributesFn = c.MetricAttributesFn
|
||||
}
|
||||
|
||||
// serveHTTP sets up tracing and calls the given next http.Handler with the span
|
||||
@@ -189,14 +192,16 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http
|
||||
// Use floating point division here for higher precision (instead of Millisecond method).
|
||||
elapsedTime := float64(time.Since(requestStartTime)) / float64(time.Millisecond)
|
||||
|
||||
metricAttributes := semconv.MetricAttributes{
|
||||
Req: r,
|
||||
StatusCode: statusCode,
|
||||
AdditionalAttributes: append(labeler.Get(), h.metricAttributesFromRequest(r)...),
|
||||
}
|
||||
|
||||
h.semconv.RecordMetrics(ctx, semconv.ServerMetricData{
|
||||
ServerName: h.server,
|
||||
ResponseSize: bytesWritten,
|
||||
MetricAttributes: semconv.MetricAttributes{
|
||||
Req: r,
|
||||
StatusCode: statusCode,
|
||||
AdditionalAttributes: labeler.Get(),
|
||||
},
|
||||
ServerName: h.server,
|
||||
ResponseSize: bytesWritten,
|
||||
MetricAttributes: metricAttributes,
|
||||
MetricData: semconv.MetricData{
|
||||
RequestSize: bw.BytesRead(),
|
||||
ElapsedTime: elapsedTime,
|
||||
@@ -204,6 +209,14 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http
|
||||
})
|
||||
}
|
||||
|
||||
func (h *middleware) metricAttributesFromRequest(r *http.Request) []attribute.KeyValue {
|
||||
var attributeForRequest []attribute.KeyValue
|
||||
if h.metricAttributesFn != nil {
|
||||
attributeForRequest = h.metricAttributesFn(r)
|
||||
}
|
||||
return attributeForRequest
|
||||
}
|
||||
|
||||
// WithRouteTag annotates spans and metrics with the provided route name
|
||||
// with HTTP route attribute.
|
||||
func WithRouteTag(route string, h http.Handler) http.Handler {
|
||||
|
||||
Generated
Vendored
+86
-33
@@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/env.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@@ -16,6 +19,10 @@ import (
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
// OTelSemConvStabilityOptIn is an environment variable.
|
||||
// That can be set to "old" or "http/dup" to opt into the new HTTP semantic conventions.
|
||||
const OTelSemConvStabilityOptIn = "OTEL_SEMCONV_STABILITY_OPT_IN"
|
||||
|
||||
type ResponseTelemetry struct {
|
||||
StatusCode int
|
||||
ReadBytes int64
|
||||
@@ -31,6 +38,11 @@ type HTTPServer struct {
|
||||
requestBytesCounter metric.Int64Counter
|
||||
responseBytesCounter metric.Int64Counter
|
||||
serverLatencyMeasure metric.Float64Histogram
|
||||
|
||||
// New metrics
|
||||
requestBodySizeHistogram metric.Int64Histogram
|
||||
responseBodySizeHistogram metric.Int64Histogram
|
||||
requestDurationHistogram metric.Float64Histogram
|
||||
}
|
||||
|
||||
// RequestTraceAttrs returns trace attributes for an HTTP request received by a
|
||||
@@ -103,38 +115,56 @@ type MetricData struct {
|
||||
ElapsedTime float64
|
||||
}
|
||||
|
||||
var metricAddOptionPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &[]metric.AddOption{}
|
||||
},
|
||||
}
|
||||
|
||||
func (s HTTPServer) RecordMetrics(ctx context.Context, md ServerMetricData) {
|
||||
if s.requestBytesCounter == nil || s.responseBytesCounter == nil || s.serverLatencyMeasure == nil {
|
||||
// This will happen if an HTTPServer{} is used instead of NewHTTPServer.
|
||||
return
|
||||
var (
|
||||
metricAddOptionPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &[]metric.AddOption{}
|
||||
},
|
||||
}
|
||||
|
||||
attributes := OldHTTPServer{}.MetricAttributes(md.ServerName, md.Req, md.StatusCode, md.AdditionalAttributes)
|
||||
o := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
addOpts := metricAddOptionPool.Get().(*[]metric.AddOption)
|
||||
*addOpts = append(*addOpts, o)
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, *addOpts...)
|
||||
s.responseBytesCounter.Add(ctx, md.ResponseSize, *addOpts...)
|
||||
s.serverLatencyMeasure.Record(ctx, md.ElapsedTime, o)
|
||||
*addOpts = (*addOpts)[:0]
|
||||
metricAddOptionPool.Put(addOpts)
|
||||
metricRecordOptionPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &[]metric.RecordOption{}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// TODO: Duplicate Metrics
|
||||
func (s HTTPServer) RecordMetrics(ctx context.Context, md ServerMetricData) {
|
||||
if s.requestBytesCounter != nil && s.responseBytesCounter != nil && s.serverLatencyMeasure != nil {
|
||||
attributes := OldHTTPServer{}.MetricAttributes(md.ServerName, md.Req, md.StatusCode, md.AdditionalAttributes)
|
||||
o := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
addOpts := metricAddOptionPool.Get().(*[]metric.AddOption)
|
||||
*addOpts = append(*addOpts, o)
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, *addOpts...)
|
||||
s.responseBytesCounter.Add(ctx, md.ResponseSize, *addOpts...)
|
||||
s.serverLatencyMeasure.Record(ctx, md.ElapsedTime, o)
|
||||
*addOpts = (*addOpts)[:0]
|
||||
metricAddOptionPool.Put(addOpts)
|
||||
}
|
||||
|
||||
if s.duplicate && s.requestDurationHistogram != nil && s.requestBodySizeHistogram != nil && s.responseBodySizeHistogram != nil {
|
||||
attributes := CurrentHTTPServer{}.MetricAttributes(md.ServerName, md.Req, md.StatusCode, md.AdditionalAttributes)
|
||||
o := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption)
|
||||
*recordOpts = append(*recordOpts, o)
|
||||
s.requestBodySizeHistogram.Record(ctx, md.RequestSize, *recordOpts...)
|
||||
s.responseBodySizeHistogram.Record(ctx, md.ResponseSize, *recordOpts...)
|
||||
s.requestDurationHistogram.Record(ctx, md.ElapsedTime, o)
|
||||
*recordOpts = (*recordOpts)[:0]
|
||||
metricRecordOptionPool.Put(recordOpts)
|
||||
}
|
||||
}
|
||||
|
||||
func NewHTTPServer(meter metric.Meter) HTTPServer {
|
||||
env := strings.ToLower(os.Getenv("OTEL_SEMCONV_STABILITY_OPT_IN"))
|
||||
env := strings.ToLower(os.Getenv(OTelSemConvStabilityOptIn))
|
||||
duplicate := env == "http/dup"
|
||||
server := HTTPServer{
|
||||
duplicate: duplicate,
|
||||
}
|
||||
server.requestBytesCounter, server.responseBytesCounter, server.serverLatencyMeasure = OldHTTPServer{}.createMeasures(meter)
|
||||
if duplicate {
|
||||
server.requestBodySizeHistogram, server.responseBodySizeHistogram, server.requestDurationHistogram = CurrentHTTPServer{}.createMeasures(meter)
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
@@ -145,14 +175,23 @@ type HTTPClient struct {
|
||||
requestBytesCounter metric.Int64Counter
|
||||
responseBytesCounter metric.Int64Counter
|
||||
latencyMeasure metric.Float64Histogram
|
||||
|
||||
// new metrics
|
||||
requestBodySize metric.Int64Histogram
|
||||
requestDuration metric.Float64Histogram
|
||||
}
|
||||
|
||||
func NewHTTPClient(meter metric.Meter) HTTPClient {
|
||||
env := strings.ToLower(os.Getenv("OTEL_SEMCONV_STABILITY_OPT_IN"))
|
||||
env := strings.ToLower(os.Getenv(OTelSemConvStabilityOptIn))
|
||||
duplicate := env == "http/dup"
|
||||
client := HTTPClient{
|
||||
duplicate: env == "http/dup",
|
||||
duplicate: duplicate,
|
||||
}
|
||||
client.requestBytesCounter, client.responseBytesCounter, client.latencyMeasure = OldHTTPClient{}.createMeasures(meter)
|
||||
if duplicate {
|
||||
client.requestBodySize, client.requestDuration = CurrentHTTPClient{}.createMeasures(meter)
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
@@ -204,34 +243,48 @@ func (o MetricOpts) AddOptions() metric.AddOption {
|
||||
return o.addOptions
|
||||
}
|
||||
|
||||
func (c HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts {
|
||||
func (c HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts {
|
||||
opts := map[string]MetricOpts{}
|
||||
|
||||
attributes := OldHTTPClient{}.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes)
|
||||
// TODO: Duplicate Metrics
|
||||
set := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
return MetricOpts{
|
||||
opts["old"] = MetricOpts{
|
||||
measurement: set,
|
||||
addOptions: set,
|
||||
}
|
||||
|
||||
if c.duplicate {
|
||||
attributes := CurrentHTTPClient{}.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes)
|
||||
set := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
opts["new"] = MetricOpts{
|
||||
measurement: set,
|
||||
addOptions: set,
|
||||
}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func (s HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) {
|
||||
func (s HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) {
|
||||
if s.requestBytesCounter == nil || s.latencyMeasure == nil {
|
||||
// This will happen if an HTTPClient{} is used instead of NewHTTPClient().
|
||||
return
|
||||
}
|
||||
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, opts.AddOptions())
|
||||
s.latencyMeasure.Record(ctx, md.ElapsedTime, opts.MeasurementOption())
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, opts["old"].AddOptions())
|
||||
s.latencyMeasure.Record(ctx, md.ElapsedTime, opts["old"].MeasurementOption())
|
||||
|
||||
// TODO: Duplicate Metrics
|
||||
if s.duplicate {
|
||||
s.requestBodySize.Record(ctx, md.RequestSize, opts["new"].MeasurementOption())
|
||||
s.requestDuration.Record(ctx, md.ElapsedTime, opts["new"].MeasurementOption())
|
||||
}
|
||||
}
|
||||
|
||||
func (s HTTPClient) RecordResponseSize(ctx context.Context, responseData int64, opts metric.AddOption) {
|
||||
func (s HTTPClient) RecordResponseSize(ctx context.Context, responseData int64, opts map[string]MetricOpts) {
|
||||
if s.responseBytesCounter == nil {
|
||||
// This will happen if an HTTPClient{} is used instead of NewHTTPClient().
|
||||
return
|
||||
}
|
||||
|
||||
s.responseBytesCounter.Add(ctx, responseData, opts)
|
||||
// TODO: Duplicate Metrics
|
||||
s.responseBytesCounter.Add(ctx, responseData, opts["old"].AddOptions())
|
||||
}
|
||||
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
|
||||
// Generate semconv package:
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/bench_test.go.tmpl "--data={}" --out=bench_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/env.go.tmpl "--data={}" --out=env.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/env_test.go.tmpl "--data={}" --out=env_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/httpconv.go.tmpl "--data={}" --out=httpconv.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/httpconv_test.go.tmpl "--data={}" --out=httpconv_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/util.go.tmpl "--data={}" --out=util.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/util_test.go.tmpl "--data={}" --out=util_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/v1.20.0.go.tmpl "--data={}" --out=v1.20.0.go
|
||||
Generated
Vendored
+171
@@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/httpconv.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@@ -7,10 +10,13 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/noop"
|
||||
semconvNew "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
)
|
||||
|
||||
@@ -199,6 +205,86 @@ func (n CurrentHTTPServer) Route(route string) attribute.KeyValue {
|
||||
return semconvNew.HTTPRoute(route)
|
||||
}
|
||||
|
||||
func (n CurrentHTTPServer) createMeasures(meter metric.Meter) (metric.Int64Histogram, metric.Int64Histogram, metric.Float64Histogram) {
|
||||
if meter == nil {
|
||||
return noop.Int64Histogram{}, noop.Int64Histogram{}, noop.Float64Histogram{}
|
||||
}
|
||||
|
||||
var err error
|
||||
requestBodySizeHistogram, err := meter.Int64Histogram(
|
||||
semconvNew.HTTPServerRequestBodySizeName,
|
||||
metric.WithUnit(semconvNew.HTTPServerRequestBodySizeUnit),
|
||||
metric.WithDescription(semconvNew.HTTPServerRequestBodySizeDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
responseBodySizeHistogram, err := meter.Int64Histogram(
|
||||
semconvNew.HTTPServerResponseBodySizeName,
|
||||
metric.WithUnit(semconvNew.HTTPServerResponseBodySizeUnit),
|
||||
metric.WithDescription(semconvNew.HTTPServerResponseBodySizeDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
requestDurationHistogram, err := meter.Float64Histogram(
|
||||
semconvNew.HTTPServerRequestDurationName,
|
||||
metric.WithUnit(semconvNew.HTTPServerRequestDurationUnit),
|
||||
metric.WithDescription(semconvNew.HTTPServerRequestDurationDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
return requestBodySizeHistogram, responseBodySizeHistogram, requestDurationHistogram
|
||||
}
|
||||
|
||||
func (n CurrentHTTPServer) MetricAttributes(server string, req *http.Request, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue {
|
||||
num := len(additionalAttributes) + 3
|
||||
var host string
|
||||
var p int
|
||||
if server == "" {
|
||||
host, p = SplitHostPort(req.Host)
|
||||
} else {
|
||||
// Prioritize the primary server name.
|
||||
host, p = SplitHostPort(server)
|
||||
if p < 0 {
|
||||
_, p = SplitHostPort(req.Host)
|
||||
}
|
||||
}
|
||||
hostPort := requiredHTTPPort(req.TLS != nil, p)
|
||||
if hostPort > 0 {
|
||||
num++
|
||||
}
|
||||
protoName, protoVersion := netProtocol(req.Proto)
|
||||
if protoName != "" {
|
||||
num++
|
||||
}
|
||||
if protoVersion != "" {
|
||||
num++
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
num++
|
||||
}
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, num)
|
||||
attributes = append(attributes,
|
||||
semconvNew.HTTPRequestMethodKey.String(standardizeHTTPMethod(req.Method)),
|
||||
n.scheme(req.TLS != nil),
|
||||
semconvNew.ServerAddress(host))
|
||||
|
||||
if hostPort > 0 {
|
||||
attributes = append(attributes, semconvNew.ServerPort(hostPort))
|
||||
}
|
||||
if protoName != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolName(protoName))
|
||||
}
|
||||
if protoVersion != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolVersion(protoVersion))
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
attributes = append(attributes, semconvNew.HTTPResponseStatusCode(statusCode))
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
type CurrentHTTPClient struct{}
|
||||
|
||||
// RequestTraceAttrs returns trace attributes for an HTTP request made by a client.
|
||||
@@ -343,6 +429,91 @@ func (n CurrentHTTPClient) method(method string) (attribute.KeyValue, attribute.
|
||||
return semconvNew.HTTPRequestMethodGet, orig
|
||||
}
|
||||
|
||||
func (n CurrentHTTPClient) createMeasures(meter metric.Meter) (metric.Int64Histogram, metric.Float64Histogram) {
|
||||
if meter == nil {
|
||||
return noop.Int64Histogram{}, noop.Float64Histogram{}
|
||||
}
|
||||
|
||||
var err error
|
||||
requestBodySize, err := meter.Int64Histogram(
|
||||
semconvNew.HTTPClientRequestBodySizeName,
|
||||
metric.WithUnit(semconvNew.HTTPClientRequestBodySizeUnit),
|
||||
metric.WithDescription(semconvNew.HTTPClientRequestBodySizeDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
requestDuration, err := meter.Float64Histogram(
|
||||
semconvNew.HTTPClientRequestDurationName,
|
||||
metric.WithUnit(semconvNew.HTTPClientRequestDurationUnit),
|
||||
metric.WithDescription(semconvNew.HTTPClientRequestDurationDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
return requestBodySize, requestDuration
|
||||
}
|
||||
|
||||
func (n CurrentHTTPClient) MetricAttributes(req *http.Request, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue {
|
||||
num := len(additionalAttributes) + 2
|
||||
var h string
|
||||
if req.URL != nil {
|
||||
h = req.URL.Host
|
||||
}
|
||||
var requestHost string
|
||||
var requestPort int
|
||||
for _, hostport := range []string{h, req.Header.Get("Host")} {
|
||||
requestHost, requestPort = SplitHostPort(hostport)
|
||||
if requestHost != "" || requestPort > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
port := requiredHTTPPort(req.URL != nil && req.URL.Scheme == "https", requestPort)
|
||||
if port > 0 {
|
||||
num++
|
||||
}
|
||||
|
||||
protoName, protoVersion := netProtocol(req.Proto)
|
||||
if protoName != "" {
|
||||
num++
|
||||
}
|
||||
if protoVersion != "" {
|
||||
num++
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
num++
|
||||
}
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, num)
|
||||
attributes = append(attributes,
|
||||
semconvNew.HTTPRequestMethodKey.String(standardizeHTTPMethod(req.Method)),
|
||||
semconvNew.ServerAddress(requestHost),
|
||||
n.scheme(req.TLS != nil),
|
||||
)
|
||||
|
||||
if port > 0 {
|
||||
attributes = append(attributes, semconvNew.ServerPort(port))
|
||||
}
|
||||
if protoName != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolName(protoName))
|
||||
}
|
||||
if protoVersion != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolVersion(protoVersion))
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
attributes = append(attributes, semconvNew.HTTPResponseStatusCode(statusCode))
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
func (n CurrentHTTPClient) scheme(https bool) attribute.KeyValue { // nolint:revive
|
||||
if https {
|
||||
return semconvNew.URLScheme("https")
|
||||
}
|
||||
return semconvNew.URLScheme("http")
|
||||
}
|
||||
|
||||
func isErrorStatusCode(code int) bool {
|
||||
return code >= 400 || code < 100
|
||||
}
|
||||
|
||||
Generated
Vendored
+13
@@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/util.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@@ -96,3 +99,13 @@ func handleErr(err error) {
|
||||
otel.Handle(err)
|
||||
}
|
||||
}
|
||||
|
||||
func standardizeHTTPMethod(method string) string {
|
||||
method = strings.ToUpper(method)
|
||||
switch method {
|
||||
case http.MethodConnect, http.MethodDelete, http.MethodGet, http.MethodHead, http.MethodOptions, http.MethodPatch, http.MethodPost, http.MethodPut, http.MethodTrace:
|
||||
default:
|
||||
method = "_OTHER"
|
||||
}
|
||||
return method
|
||||
}
|
||||
|
||||
Generated
Vendored
+5
-13
@@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/v120.0.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@@ -8,7 +11,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconvutil"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
@@ -144,7 +146,7 @@ func (o OldHTTPServer) MetricAttributes(server string, req *http.Request, status
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, n)
|
||||
attributes = append(attributes,
|
||||
standardizeHTTPMethodMetric(req.Method),
|
||||
semconv.HTTPMethod(standardizeHTTPMethod(req.Method)),
|
||||
o.scheme(req.TLS != nil),
|
||||
semconv.NetHostName(host))
|
||||
|
||||
@@ -214,7 +216,7 @@ func (o OldHTTPClient) MetricAttributes(req *http.Request, statusCode int, addit
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, n)
|
||||
attributes = append(attributes,
|
||||
standardizeHTTPMethodMetric(req.Method),
|
||||
semconv.HTTPMethod(standardizeHTTPMethod(req.Method)),
|
||||
semconv.NetPeerName(requestHost),
|
||||
)
|
||||
|
||||
@@ -262,13 +264,3 @@ func (o OldHTTPClient) createMeasures(meter metric.Meter) (metric.Int64Counter,
|
||||
|
||||
return requestBytesCounter, responseBytesCounter, latencyMeasure
|
||||
}
|
||||
|
||||
func standardizeHTTPMethodMetric(method string) attribute.KeyValue {
|
||||
method = strings.ToUpper(method)
|
||||
switch method {
|
||||
case http.MethodConnect, http.MethodDelete, http.MethodGet, http.MethodHead, http.MethodOptions, http.MethodPatch, http.MethodPost, http.MethodPut, http.MethodTrace:
|
||||
default:
|
||||
method = "_OTHER"
|
||||
}
|
||||
return semconv.HTTPMethod(method)
|
||||
}
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -153,7 +153,7 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
|
||||
// For handling response bytes we leverage a callback when the client reads the http response
|
||||
readRecordFunc := func(n int64) {
|
||||
t.semconv.RecordResponseSize(ctx, n, metricOpts.AddOptions())
|
||||
t.semconv.RecordResponseSize(ctx, n, metricOpts)
|
||||
}
|
||||
|
||||
// traces
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http
|
||||
|
||||
// Version is the current release version of the otelhttp instrumentation.
|
||||
func Version() string {
|
||||
return "0.58.0"
|
||||
return "0.59.0"
|
||||
// This string is updated by the pre_release.sh script during release
|
||||
}
|
||||
|
||||
|
||||
+17
-4
@@ -8,6 +8,21 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
||||
## [1.34.0/0.56.0/0.10.0] 2025-01-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Remove the notices from `Logger` to make the whole Logs API user-facing in `go.opentelemetry.io/otel/log`. (#6167)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Relax minimum Go version to 1.22.0 in various modules. (#6073)
|
||||
- The `Type` name logged for the `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` client is corrected from `otlphttpgrpc` to `otlptracegrpc`. (#6143)
|
||||
- The `Type` name logged for the `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlphttpgrpc` client is corrected from `otlphttphttp` to `otlptracehttp`. (#6143)
|
||||
|
||||
## [1.33.0/0.55.0/0.9.0/0.0.12] 2024-12-12
|
||||
|
||||
### Added
|
||||
@@ -37,9 +52,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- Fix attribute value truncation in `go.opentelemetry.io/otel/sdk/trace`. (#5997)
|
||||
- Fix attribute value truncation in `go.opentelemetry.io/otel/sdk/log`. (#6032)
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
||||
## [1.32.0/0.54.0/0.8.0/0.0.11] 2024-11-08
|
||||
|
||||
### Added
|
||||
@@ -3185,7 +3197,8 @@ It contains api and sdk for trace and meter.
|
||||
- CircleCI build CI manifest files.
|
||||
- CODEOWNERS file to track owners of this project.
|
||||
|
||||
[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.33.0...HEAD
|
||||
[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.34.0...HEAD
|
||||
[1.34.0/0.56.0/0.10.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.34.0
|
||||
[1.33.0/0.55.0/0.9.0/0.0.12]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.33.0
|
||||
[1.32.0/0.54.0/0.8.0/0.0.11]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.32.0
|
||||
[1.31.0/0.53.0/0.7.0/0.0.10]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.31.0
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# OpenTelemetry-Go
|
||||
|
||||
[](https://github.com/open-telemetry/opentelemetry-go/actions?query=workflow%3Aci+branch%3Amain)
|
||||
[](https://github.com/open-telemetry/opentelemetry-go/actions/workflows/ci.yml)
|
||||
[](https://app.codecov.io/gh/open-telemetry/opentelemetry-go?branch=main)
|
||||
[](https://pkg.go.dev/go.opentelemetry.io/otel)
|
||||
[](https://goreportcard.com/report/go.opentelemetry.io/otel)
|
||||
|
||||
+3
-3
@@ -130,6 +130,6 @@ Importantly, bump any package versions referenced to be the latest one you just
|
||||
|
||||
Bump the dependencies in the following Go services:
|
||||
|
||||
- [`accountingservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/accountingservice)
|
||||
- [`checkoutservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/checkoutservice)
|
||||
- [`productcatalogservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/productcatalogservice)
|
||||
- [`accounting`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/accounting)
|
||||
- [`checkoutservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/checkout)
|
||||
- [`productcatalogservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/product-catalog)
|
||||
|
||||
+1
-1
@@ -294,7 +294,7 @@ func (c *client) MarshalLog() interface{} {
|
||||
Type string
|
||||
Endpoint string
|
||||
}{
|
||||
Type: "otlphttpgrpc",
|
||||
Type: "otlptracegrpc",
|
||||
Endpoint: c.endpoint,
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
|
||||
|
||||
// Version is the current release version of the OpenTelemetry OTLP trace exporter in use.
|
||||
func Version() string {
|
||||
return "1.33.0"
|
||||
return "1.34.0"
|
||||
}
|
||||
|
||||
-6
@@ -14,12 +14,6 @@
|
||||
"matchDepTypes": ["indirect"],
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"matchFileNames": ["internal/tools/**"],
|
||||
"matchManagers": ["gomod"],
|
||||
"matchDepTypes": ["indirect"],
|
||||
"enabled": false
|
||||
},
|
||||
{
|
||||
"matchPackageNames": ["google.golang.org/genproto/googleapis/**"],
|
||||
"groupName": "googleapis"
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ package sdk // import "go.opentelemetry.io/otel/sdk"
|
||||
|
||||
// Version is the current release version of the OpenTelemetry SDK in use.
|
||||
func Version() string {
|
||||
return "1.33.0"
|
||||
return "1.34.0"
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ package otel // import "go.opentelemetry.io/otel"
|
||||
|
||||
// Version is the current release version of OpenTelemetry in use.
|
||||
func Version() string {
|
||||
return "1.33.0"
|
||||
return "1.34.0"
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@
|
||||
|
||||
module-sets:
|
||||
stable-v1:
|
||||
version: v1.33.0
|
||||
version: v1.34.0
|
||||
modules:
|
||||
- go.opentelemetry.io/otel
|
||||
- go.opentelemetry.io/otel/bridge/opencensus
|
||||
@@ -23,11 +23,11 @@ module-sets:
|
||||
- go.opentelemetry.io/otel/sdk/metric
|
||||
- go.opentelemetry.io/otel/trace
|
||||
experimental-metrics:
|
||||
version: v0.55.0
|
||||
version: v0.56.0
|
||||
modules:
|
||||
- go.opentelemetry.io/otel/exporters/prometheus
|
||||
experimental-logs:
|
||||
version: v0.9.0
|
||||
version: v0.10.0
|
||||
modules:
|
||||
- go.opentelemetry.io/otel/log
|
||||
- go.opentelemetry.io/otel/sdk/log
|
||||
|
||||
+4
-2
@@ -311,7 +311,8 @@ type ResourceSpans struct {
|
||||
// A list of ScopeSpans that originate from a resource.
|
||||
ScopeSpans []*ScopeSpans `protobuf:"bytes,2,rep,name=scope_spans,json=scopeSpans,proto3" json:"scope_spans,omitempty"`
|
||||
// The Schema URL, if known. This is the identifier of the Schema that the resource data
|
||||
// is recorded in. To learn more about Schema URL see
|
||||
// is recorded in. Notably, the last part of the URL path is the version number of the
|
||||
// schema: http[s]://server[:port]/path/<version>. To learn more about Schema URL see
|
||||
// https://opentelemetry.io/docs/specs/otel/schemas/#schema-url
|
||||
// This schema_url applies to the data in the "resource" field. It does not apply
|
||||
// to the data in the "scope_spans" field which have their own schema_url field.
|
||||
@@ -384,7 +385,8 @@ type ScopeSpans struct {
|
||||
// A list of Spans that originate from an instrumentation scope.
|
||||
Spans []*Span `protobuf:"bytes,2,rep,name=spans,proto3" json:"spans,omitempty"`
|
||||
// The Schema URL, if known. This is the identifier of the Schema that the span data
|
||||
// is recorded in. To learn more about Schema URL see
|
||||
// is recorded in. Notably, the last part of the URL path is the version number of the
|
||||
// schema: http[s]://server[:port]/path/<version>. To learn more about Schema URL see
|
||||
// https://opentelemetry.io/docs/specs/otel/schemas/#schema-url
|
||||
// This schema_url applies to all spans and span events in the "spans" field.
|
||||
SchemaUrl string `protobuf:"bytes,3,opt,name=schema_url,json=schemaUrl,proto3" json:"schema_url,omitempty"`
|
||||
|
||||
+80
-48
@@ -80,11 +80,12 @@ type ErrorInfo struct {
|
||||
Domain string `protobuf:"bytes,2,opt,name=domain,proto3" json:"domain,omitempty"`
|
||||
// Additional structured details about this error.
|
||||
//
|
||||
// Keys should match /[a-zA-Z0-9-_]/ and be limited to 64 characters in
|
||||
// Keys must match a regular expression of `[a-z][a-zA-Z0-9-_]+` but should
|
||||
// ideally be lowerCamelCase. Also, they must be limited to 64 characters in
|
||||
// length. When identifying the current value of an exceeded limit, the units
|
||||
// should be contained in the key, not the value. For example, rather than
|
||||
// {"instanceLimit": "100/request"}, should be returned as,
|
||||
// {"instanceLimitPerRequest": "100"}, if the client exceeds the number of
|
||||
// `{"instanceLimit": "100/request"}`, should be returned as,
|
||||
// `{"instanceLimitPerRequest": "100"}`, if the client exceeds the number of
|
||||
// instances that can be created in a single (batch) request.
|
||||
Metadata map[string]string `protobuf:"bytes,3,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
}
|
||||
@@ -870,6 +871,16 @@ type BadRequest_FieldViolation struct {
|
||||
Field string `protobuf:"bytes,1,opt,name=field,proto3" json:"field,omitempty"`
|
||||
// A description of why the request element is bad.
|
||||
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
|
||||
// The reason of the field-level error. This is a constant value that
|
||||
// identifies the proximate cause of the field-level error. It should
|
||||
// uniquely identify the type of the FieldViolation within the scope of the
|
||||
// google.rpc.ErrorInfo.domain. This should be at most 63
|
||||
// characters and match a regular expression of `[A-Z][A-Z0-9_]+[A-Z0-9]`,
|
||||
// which represents UPPER_SNAKE_CASE.
|
||||
Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"`
|
||||
// Provides a localized error message for field-level errors that is safe to
|
||||
// return to the API consumer.
|
||||
LocalizedMessage *LocalizedMessage `protobuf:"bytes,4,opt,name=localized_message,json=localizedMessage,proto3" json:"localized_message,omitempty"`
|
||||
}
|
||||
|
||||
func (x *BadRequest_FieldViolation) Reset() {
|
||||
@@ -918,6 +929,20 @@ func (x *BadRequest_FieldViolation) GetDescription() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BadRequest_FieldViolation) GetReason() string {
|
||||
if x != nil {
|
||||
return x.Reason
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BadRequest_FieldViolation) GetLocalizedMessage() *LocalizedMessage {
|
||||
if x != nil {
|
||||
return x.LocalizedMessage
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Describes a URL link.
|
||||
type Help_Link struct {
|
||||
state protoimpl.MessageState
|
||||
@@ -1026,51 +1051,57 @@ var file_google_rpc_error_details_proto_rawDesc = []byte{
|
||||
0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
|
||||
0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72,
|
||||
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65,
|
||||
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xa8, 0x01, 0x0a, 0x0a, 0x42, 0x61,
|
||||
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x8c, 0x02, 0x0a, 0x0a, 0x42, 0x61,
|
||||
0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x50, 0x0a, 0x10, 0x66, 0x69, 0x65, 0x6c,
|
||||
0x64, 0x5f, 0x76, 0x69, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03,
|
||||
0x28, 0x0b, 0x32, 0x25, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x72, 0x70, 0x63, 0x2e,
|
||||
0x42, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64,
|
||||
0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0f, 0x66, 0x69, 0x65, 0x6c, 0x64,
|
||||
0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0x48, 0x0a, 0x0e, 0x46, 0x69,
|
||||
0x65, 0x6c, 0x64, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05,
|
||||
0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x66, 0x69, 0x65,
|
||||
0x6c, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x22, 0x4f, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49,
|
||||
0x6e, 0x66, 0x6f, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69,
|
||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x61,
|
||||
0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x6e,
|
||||
0x67, 0x44, 0x61, 0x74, 0x61, 0x22, 0x90, 0x01, 0x0a, 0x0c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72,
|
||||
0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72,
|
||||
0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72,
|
||||
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x72,
|
||||
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65,
|
||||
0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
|
||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73,
|
||||
0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x6f, 0x0a, 0x04, 0x48, 0x65, 0x6c, 0x70,
|
||||
0x12, 0x2b, 0x0a, 0x05, 0x6c, 0x69, 0x6e, 0x6b, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32,
|
||||
0x15, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x48, 0x65, 0x6c,
|
||||
0x70, 0x2e, 0x4c, 0x69, 0x6e, 0x6b, 0x52, 0x05, 0x6c, 0x69, 0x6e, 0x6b, 0x73, 0x1a, 0x3a, 0x0a,
|
||||
0x04, 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63,
|
||||
0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x44, 0x0a, 0x10, 0x4c, 0x6f, 0x63,
|
||||
0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6c,
|
||||
0x6f, 0x63, 0x61, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42,
|
||||
0x6c, 0x0a, 0x0e, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x72, 0x70,
|
||||
0x63, 0x42, 0x11, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x50,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67,
|
||||
0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x67, 0x65, 0x6e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x61, 0x70, 0x69, 0x73, 0x2f, 0x72, 0x70,
|
||||
0x63, 0x2f, 0x65, 0x72, 0x72, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x3b, 0x65, 0x72, 0x72,
|
||||
0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0xa2, 0x02, 0x03, 0x52, 0x50, 0x43, 0x62, 0x06, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0xab, 0x01, 0x0a, 0x0e, 0x46,
|
||||
0x69, 0x65, 0x6c, 0x64, 0x56, 0x69, 0x6f, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a,
|
||||
0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x66, 0x69,
|
||||
0x65, 0x6c, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
|
||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x49, 0x0a,
|
||||
0x11, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||
0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
|
||||
0x65, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x4d,
|
||||
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x10, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65,
|
||||
0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x4f, 0x0a, 0x0b, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x65, 0x72, 0x76, 0x69, 0x6e,
|
||||
0x67, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65,
|
||||
0x72, 0x76, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x61, 0x22, 0x90, 0x01, 0x0a, 0x0c, 0x52, 0x65,
|
||||
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65,
|
||||
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12,
|
||||
0x23, 0x0a, 0x0d, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
|
||||
0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65,
|
||||
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x6f, 0x0a, 0x04,
|
||||
0x48, 0x65, 0x6c, 0x70, 0x12, 0x2b, 0x0a, 0x05, 0x6c, 0x69, 0x6e, 0x6b, 0x73, 0x18, 0x01, 0x20,
|
||||
0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x72, 0x70, 0x63,
|
||||
0x2e, 0x48, 0x65, 0x6c, 0x70, 0x2e, 0x4c, 0x69, 0x6e, 0x6b, 0x52, 0x05, 0x6c, 0x69, 0x6e, 0x6b,
|
||||
0x73, 0x1a, 0x3a, 0x0a, 0x04, 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73,
|
||||
0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b,
|
||||
0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x75,
|
||||
0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x44, 0x0a,
|
||||
0x10, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x06, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73,
|
||||
0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x42, 0x6c, 0x0a, 0x0e, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,
|
||||
0x65, 0x2e, 0x72, 0x70, 0x63, 0x42, 0x11, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x44, 0x65, 0x74, 0x61,
|
||||
0x69, 0x6c, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3f, 0x67, 0x6f, 0x6f, 0x67,
|
||||
0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x67, 0x65,
|
||||
0x6e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x61, 0x70, 0x69,
|
||||
0x73, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x72, 0x72, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73,
|
||||
0x3b, 0x65, 0x72, 0x72, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0xa2, 0x02, 0x03, 0x52, 0x50,
|
||||
0x43, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -1111,11 +1142,12 @@ var file_google_rpc_error_details_proto_depIdxs = []int32{
|
||||
12, // 3: google.rpc.PreconditionFailure.violations:type_name -> google.rpc.PreconditionFailure.Violation
|
||||
13, // 4: google.rpc.BadRequest.field_violations:type_name -> google.rpc.BadRequest.FieldViolation
|
||||
14, // 5: google.rpc.Help.links:type_name -> google.rpc.Help.Link
|
||||
6, // [6:6] is the sub-list for method output_type
|
||||
6, // [6:6] is the sub-list for method input_type
|
||||
6, // [6:6] is the sub-list for extension type_name
|
||||
6, // [6:6] is the sub-list for extension extendee
|
||||
0, // [0:6] is the sub-list for field type_name
|
||||
9, // 6: google.rpc.BadRequest.FieldViolation.localized_message:type_name -> google.rpc.LocalizedMessage
|
||||
7, // [7:7] is the sub-list for method output_type
|
||||
7, // [7:7] is the sub-list for method input_type
|
||||
7, // [7:7] is the sub-list for extension type_name
|
||||
7, // [7:7] is the sub-list for extension extendee
|
||||
0, // [0:7] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_google_rpc_error_details_proto_init() }
|
||||
|
||||
+1
-1
@@ -192,7 +192,7 @@ func (d decoder) unmarshalMessage(m protoreflect.Message, skipTypeURL bool) erro
|
||||
fd = fieldDescs.ByTextName(name)
|
||||
}
|
||||
}
|
||||
if flags.ProtoLegacy {
|
||||
if flags.ProtoLegacyWeak {
|
||||
if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
|
||||
fd = nil // reset since the weak reference is not linked in
|
||||
}
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ func (d decoder) unmarshalMessage(m protoreflect.Message, checkDelims bool) erro
|
||||
} else if xtErr != nil && xtErr != protoregistry.NotFound {
|
||||
return d.newError(tok.Pos(), "unable to resolve [%s]: %v", tok.RawString(), xtErr)
|
||||
}
|
||||
if flags.ProtoLegacy {
|
||||
if flags.ProtoLegacyWeak {
|
||||
if fd != nil && fd.IsWeak() && fd.Message().IsPlaceholder() {
|
||||
fd = nil // reset since the weak reference is not linked in
|
||||
}
|
||||
|
||||
Generated
Vendored
BIN
Binary file not shown.
-40
@@ -1,40 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !go1.13
|
||||
// +build !go1.13
|
||||
|
||||
package errors
|
||||
|
||||
import "reflect"
|
||||
|
||||
// Is is a copy of Go 1.13's errors.Is for use with older Go versions.
|
||||
func Is(err, target error) bool {
|
||||
if target == nil {
|
||||
return err == target
|
||||
}
|
||||
|
||||
isComparable := reflect.TypeOf(target).Comparable()
|
||||
for {
|
||||
if isComparable && err == target {
|
||||
return true
|
||||
}
|
||||
if x, ok := err.(interface{ Is(error) bool }); ok && x.Is(target) {
|
||||
return true
|
||||
}
|
||||
if err = unwrap(err); err == nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func unwrap(err error) error {
|
||||
u, ok := err.(interface {
|
||||
Unwrap() error
|
||||
})
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return u.Unwrap()
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build go1.13
|
||||
// +build go1.13
|
||||
|
||||
package errors
|
||||
|
||||
import "errors"
|
||||
|
||||
// Is is errors.Is.
|
||||
func Is(err, target error) bool { return errors.Is(err, target) }
|
||||
+3
@@ -117,6 +117,9 @@ type (
|
||||
// GenerateLegacyUnmarshalJSON determines if the plugin generates the
|
||||
// UnmarshalJSON([]byte) error method for enums.
|
||||
GenerateLegacyUnmarshalJSON bool
|
||||
// APILevel controls which API (Open, Hybrid or Opaque) should be used
|
||||
// for generated code (.pb.go files).
|
||||
APILevel int
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
+4
@@ -32,6 +32,10 @@ func unmarshalGoFeature(b []byte, parent EditionFeatures) EditionFeatures {
|
||||
v, m := protowire.ConsumeVarint(b)
|
||||
b = b[m:]
|
||||
parent.GenerateLegacyUnmarshalJSON = protowire.DecodeBool(v)
|
||||
case genid.GoFeatures_ApiLevel_field_number:
|
||||
v, m := protowire.ConsumeVarint(b)
|
||||
b = b[m:]
|
||||
parent.APILevel = int(v)
|
||||
case genid.GoFeatures_StripEnumPrefix_field_number:
|
||||
v, m := protowire.ConsumeVarint(b)
|
||||
b = b[m:]
|
||||
|
||||
+5
@@ -22,3 +22,8 @@ const ProtoLegacy = protoLegacy
|
||||
// extension fields at unmarshal time, but defers creating the message
|
||||
// structure until the extension is first accessed.
|
||||
const LazyUnmarshalExtensions = ProtoLegacy
|
||||
|
||||
// ProtoLegacyWeak specifies whether to enable support for weak fields.
|
||||
// This flag was split out of ProtoLegacy in preparation for removing
|
||||
// support for weak fields (independent of the other protolegacy features).
|
||||
const ProtoLegacyWeak = ProtoLegacy
|
||||
|
||||
+17
@@ -21,18 +21,35 @@ const (
|
||||
// Field names for pb.GoFeatures.
|
||||
const (
|
||||
GoFeatures_LegacyUnmarshalJsonEnum_field_name protoreflect.Name = "legacy_unmarshal_json_enum"
|
||||
GoFeatures_ApiLevel_field_name protoreflect.Name = "api_level"
|
||||
GoFeatures_StripEnumPrefix_field_name protoreflect.Name = "strip_enum_prefix"
|
||||
|
||||
GoFeatures_LegacyUnmarshalJsonEnum_field_fullname protoreflect.FullName = "pb.GoFeatures.legacy_unmarshal_json_enum"
|
||||
GoFeatures_ApiLevel_field_fullname protoreflect.FullName = "pb.GoFeatures.api_level"
|
||||
GoFeatures_StripEnumPrefix_field_fullname protoreflect.FullName = "pb.GoFeatures.strip_enum_prefix"
|
||||
)
|
||||
|
||||
// Field numbers for pb.GoFeatures.
|
||||
const (
|
||||
GoFeatures_LegacyUnmarshalJsonEnum_field_number protoreflect.FieldNumber = 1
|
||||
GoFeatures_ApiLevel_field_number protoreflect.FieldNumber = 2
|
||||
GoFeatures_StripEnumPrefix_field_number protoreflect.FieldNumber = 3
|
||||
)
|
||||
|
||||
// Full and short names for pb.GoFeatures.APILevel.
|
||||
const (
|
||||
GoFeatures_APILevel_enum_fullname = "pb.GoFeatures.APILevel"
|
||||
GoFeatures_APILevel_enum_name = "APILevel"
|
||||
)
|
||||
|
||||
// Enum values for pb.GoFeatures.APILevel.
|
||||
const (
|
||||
GoFeatures_API_LEVEL_UNSPECIFIED_enum_value = 0
|
||||
GoFeatures_API_OPEN_enum_value = 1
|
||||
GoFeatures_API_HYBRID_enum_value = 2
|
||||
GoFeatures_API_OPAQUE_enum_value = 3
|
||||
)
|
||||
|
||||
// Full and short names for pb.GoFeatures.StripEnumPrefix.
|
||||
const (
|
||||
GoFeatures_StripEnumPrefix_enum_fullname = "pb.GoFeatures.StripEnumPrefix"
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package genid
|
||||
|
||||
const (
|
||||
NoUnkeyedLiteral_goname = "noUnkeyedLiteral"
|
||||
NoUnkeyedLiteralA_goname = "XXX_NoUnkeyedLiteral"
|
||||
|
||||
BuilderSuffix_goname = "_builder"
|
||||
)
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
func (Export) UnmarshalField(msg any, fieldNum int32) {
|
||||
UnmarshalField(msg.(protoreflect.ProtoMessage).ProtoReflect(), protoreflect.FieldNumber(fieldNum))
|
||||
}
|
||||
|
||||
// Present checks the presence set for a certain field number (zero
|
||||
// based, ordered by appearance in original proto file). part is
|
||||
// a pointer to the correct element in the bitmask array, num is the
|
||||
// field number unaltered. Example (field number 70 -> part =
|
||||
// &m.XXX_presence[1], num = 70)
|
||||
func (Export) Present(part *uint32, num uint32) bool {
|
||||
// This hook will read an unprotected shadow presence set if
|
||||
// we're unning under the race detector
|
||||
raceDetectHookPresent(part, num)
|
||||
return atomic.LoadUint32(part)&(1<<(num%32)) > 0
|
||||
}
|
||||
|
||||
// SetPresent adds a field to the presence set. part is a pointer to
|
||||
// the relevant element in the array and num is the field number
|
||||
// unaltered. size is the number of fields in the protocol
|
||||
// buffer.
|
||||
func (Export) SetPresent(part *uint32, num uint32, size uint32) {
|
||||
// This hook will mutate an unprotected shadow presence set if
|
||||
// we're running under the race detector
|
||||
raceDetectHookSetPresent(part, num, presenceSize(size))
|
||||
for {
|
||||
old := atomic.LoadUint32(part)
|
||||
if atomic.CompareAndSwapUint32(part, old, old|(1<<(num%32))) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetPresentNonAtomic is like SetPresent, but operates non-atomically.
|
||||
// It is meant for use by builder methods, where the message is known not
|
||||
// to be accessible yet by other goroutines.
|
||||
func (Export) SetPresentNonAtomic(part *uint32, num uint32, size uint32) {
|
||||
// This hook will mutate an unprotected shadow presence set if
|
||||
// we're running under the race detector
|
||||
raceDetectHookSetPresent(part, num, presenceSize(size))
|
||||
*part |= 1 << (num % 32)
|
||||
}
|
||||
|
||||
// ClearPresence removes a field from the presence set. part is a
|
||||
// pointer to the relevant element in the presence array and num is
|
||||
// the field number unaltered.
|
||||
func (Export) ClearPresent(part *uint32, num uint32) {
|
||||
// This hook will mutate an unprotected shadow presence set if
|
||||
// we're running under the race detector
|
||||
raceDetectHookClearPresent(part, num)
|
||||
for {
|
||||
old := atomic.LoadUint32(part)
|
||||
if atomic.CompareAndSwapUint32(part, old, old&^(1<<(num%32))) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// interfaceToPointer takes a pointer to an empty interface whose value is a
|
||||
// pointer type, and converts it into a "pointer" that points to the same
|
||||
// target
|
||||
func interfaceToPointer(i *any) pointer {
|
||||
return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
|
||||
}
|
||||
|
||||
func (p pointer) atomicGetPointer() pointer {
|
||||
return pointer{p: atomic.LoadPointer((*unsafe.Pointer)(p.p))}
|
||||
}
|
||||
|
||||
func (p pointer) atomicSetPointer(q pointer) {
|
||||
atomic.StorePointer((*unsafe.Pointer)(p.p), q.p)
|
||||
}
|
||||
|
||||
// AtomicCheckPointerIsNil takes an interface (which is a pointer to a
|
||||
// pointer) and returns true if the pointed-to pointer is nil (using an
|
||||
// atomic load). This function is inlineable and, on x86, just becomes a
|
||||
// simple load and compare.
|
||||
func (Export) AtomicCheckPointerIsNil(ptr any) bool {
|
||||
return interfaceToPointer(&ptr).atomicGetPointer().IsNil()
|
||||
}
|
||||
|
||||
// AtomicSetPointer takes two interfaces (first is a pointer to a pointer,
|
||||
// second is a pointer) and atomically sets the second pointer into location
|
||||
// referenced by first pointer. Unfortunately, atomicSetPointer() does not inline
|
||||
// (even on x86), so this does not become a simple store on x86.
|
||||
func (Export) AtomicSetPointer(dstPtr, valPtr any) {
|
||||
interfaceToPointer(&dstPtr).atomicSetPointer(interfaceToPointer(&valPtr))
|
||||
}
|
||||
|
||||
// AtomicLoadPointer loads the pointer at the location pointed at by src,
|
||||
// and stores that pointer value into the location pointed at by dst.
|
||||
func (Export) AtomicLoadPointer(ptr Pointer, dst Pointer) {
|
||||
*(*unsafe.Pointer)(unsafe.Pointer(dst)) = atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(ptr)))
|
||||
}
|
||||
|
||||
// AtomicInitializePointer makes ptr and dst point to the same value.
|
||||
//
|
||||
// If *ptr is a nil pointer, it sets *ptr = *dst.
|
||||
//
|
||||
// If *ptr is a non-nil pointer, it sets *dst = *ptr.
|
||||
func (Export) AtomicInitializePointer(ptr Pointer, dst Pointer) {
|
||||
if !atomic.CompareAndSwapPointer((*unsafe.Pointer)(ptr), unsafe.Pointer(nil), *(*unsafe.Pointer)(dst)) {
|
||||
*(*unsafe.Pointer)(unsafe.Pointer(dst)) = atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(ptr)))
|
||||
}
|
||||
}
|
||||
|
||||
// MessageFieldStringOf returns the field formatted as a string,
|
||||
// either as the field name if resolvable otherwise as a decimal string.
|
||||
func (Export) MessageFieldStringOf(md protoreflect.MessageDescriptor, n protoreflect.FieldNumber) string {
|
||||
fd := md.Fields().ByNumber(n)
|
||||
if fd != nil {
|
||||
return string(fd.Name())
|
||||
}
|
||||
return strconv.Itoa(int(n))
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !race
|
||||
|
||||
package impl
|
||||
|
||||
// There is no additional data as we're not running under race detector.
|
||||
type RaceDetectHookData struct{}
|
||||
|
||||
// Empty stubs for when not using the race detector. Calls to these from index.go should be optimized away.
|
||||
func (presence) raceDetectHookPresent(num uint32) {}
|
||||
func (presence) raceDetectHookSetPresent(num uint32, size presenceSize) {}
|
||||
func (presence) raceDetectHookClearPresent(num uint32) {}
|
||||
func (presence) raceDetectHookAllocAndCopy(src presence) {}
|
||||
|
||||
// raceDetectHookPresent is called by the generated file interface
|
||||
// (*proto.internalFuncs) Present to optionally read an unprotected
|
||||
// shadow bitmap when race detection is enabled. In regular code it is
|
||||
// a noop.
|
||||
func raceDetectHookPresent(field *uint32, num uint32) {}
|
||||
|
||||
// raceDetectHookSetPresent is called by the generated file interface
|
||||
// (*proto.internalFuncs) SetPresent to optionally write an unprotected
|
||||
// shadow bitmap when race detection is enabled. In regular code it is
|
||||
// a noop.
|
||||
func raceDetectHookSetPresent(field *uint32, num uint32, size presenceSize) {}
|
||||
|
||||
// raceDetectHookClearPresent is called by the generated file interface
|
||||
// (*proto.internalFuncs) ClearPresent to optionally write an unprotected
|
||||
// shadow bitmap when race detection is enabled. In regular code it is
|
||||
// a noop.
|
||||
func raceDetectHookClearPresent(field *uint32, num uint32) {}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build race
|
||||
|
||||
package impl
|
||||
|
||||
// When running under race detector, we add a presence map of bytes, that we can access
|
||||
// in the hook functions so that we trigger the race detection whenever we have concurrent
|
||||
// Read-Writes or Write-Writes. The race detector does not otherwise detect invalid concurrent
|
||||
// access to lazy fields as all updates of bitmaps and pointers are done using atomic operations.
|
||||
type RaceDetectHookData struct {
|
||||
shadowPresence *[]byte
|
||||
}
|
||||
|
||||
// Hooks for presence bitmap operations that allocate, read and write the shadowPresence
|
||||
// using non-atomic operations.
|
||||
func (data *RaceDetectHookData) raceDetectHookAlloc(size presenceSize) {
|
||||
sp := make([]byte, size)
|
||||
atomicStoreShadowPresence(&data.shadowPresence, &sp)
|
||||
}
|
||||
|
||||
func (p presence) raceDetectHookPresent(num uint32) {
|
||||
data := p.toRaceDetectData()
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
sp := atomicLoadShadowPresence(&data.shadowPresence)
|
||||
if sp != nil {
|
||||
_ = (*sp)[num]
|
||||
}
|
||||
}
|
||||
|
||||
func (p presence) raceDetectHookSetPresent(num uint32, size presenceSize) {
|
||||
data := p.toRaceDetectData()
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
sp := atomicLoadShadowPresence(&data.shadowPresence)
|
||||
if sp == nil {
|
||||
data.raceDetectHookAlloc(size)
|
||||
sp = atomicLoadShadowPresence(&data.shadowPresence)
|
||||
}
|
||||
(*sp)[num] = 1
|
||||
}
|
||||
|
||||
func (p presence) raceDetectHookClearPresent(num uint32) {
|
||||
data := p.toRaceDetectData()
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
sp := atomicLoadShadowPresence(&data.shadowPresence)
|
||||
if sp != nil {
|
||||
(*sp)[num] = 0
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// raceDetectHookAllocAndCopy allocates a new shadowPresence slice at lazy and copies
|
||||
// shadowPresence bytes from src to lazy.
|
||||
func (p presence) raceDetectHookAllocAndCopy(q presence) {
|
||||
sData := q.toRaceDetectData()
|
||||
dData := p.toRaceDetectData()
|
||||
if sData == nil {
|
||||
return
|
||||
}
|
||||
srcSp := atomicLoadShadowPresence(&sData.shadowPresence)
|
||||
if srcSp == nil {
|
||||
atomicStoreShadowPresence(&dData.shadowPresence, nil)
|
||||
return
|
||||
}
|
||||
n := len(*srcSp)
|
||||
dSlice := make([]byte, n)
|
||||
atomicStoreShadowPresence(&dData.shadowPresence, &dSlice)
|
||||
for i := 0; i < n; i++ {
|
||||
dSlice[i] = (*srcSp)[i]
|
||||
}
|
||||
}
|
||||
|
||||
// raceDetectHookPresent is called by the generated file interface
|
||||
// (*proto.internalFuncs) Present to optionally read an unprotected
|
||||
// shadow bitmap when race detection is enabled. In regular code it is
|
||||
// a noop.
|
||||
func raceDetectHookPresent(field *uint32, num uint32) {
|
||||
data := findPointerToRaceDetectData(field, num)
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
sp := atomicLoadShadowPresence(&data.shadowPresence)
|
||||
if sp != nil {
|
||||
_ = (*sp)[num]
|
||||
}
|
||||
}
|
||||
|
||||
// raceDetectHookSetPresent is called by the generated file interface
|
||||
// (*proto.internalFuncs) SetPresent to optionally write an unprotected
|
||||
// shadow bitmap when race detection is enabled. In regular code it is
|
||||
// a noop.
|
||||
func raceDetectHookSetPresent(field *uint32, num uint32, size presenceSize) {
|
||||
data := findPointerToRaceDetectData(field, num)
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
sp := atomicLoadShadowPresence(&data.shadowPresence)
|
||||
if sp == nil {
|
||||
data.raceDetectHookAlloc(size)
|
||||
sp = atomicLoadShadowPresence(&data.shadowPresence)
|
||||
}
|
||||
(*sp)[num] = 1
|
||||
}
|
||||
|
||||
// raceDetectHookClearPresent is called by the generated file interface
|
||||
// (*proto.internalFuncs) ClearPresent to optionally write an unprotected
|
||||
// shadow bitmap when race detection is enabled. In regular code it is
|
||||
// a noop.
|
||||
func raceDetectHookClearPresent(field *uint32, num uint32) {
|
||||
data := findPointerToRaceDetectData(field, num)
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
sp := atomicLoadShadowPresence(&data.shadowPresence)
|
||||
if sp != nil {
|
||||
(*sp)[num] = 0
|
||||
}
|
||||
}
|
||||
+33
@@ -35,6 +35,12 @@ func (mi *MessageInfo) checkInitializedPointer(p pointer) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var presence presence
|
||||
if mi.presenceOffset.IsValid() {
|
||||
presence = p.Apply(mi.presenceOffset).PresenceInfo()
|
||||
}
|
||||
|
||||
if mi.extensionOffset.IsValid() {
|
||||
e := p.Apply(mi.extensionOffset).Extensions()
|
||||
if err := mi.isInitExtensions(e); err != nil {
|
||||
@@ -45,6 +51,33 @@ func (mi *MessageInfo) checkInitializedPointer(p pointer) error {
|
||||
if !f.isRequired && f.funcs.isInit == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if f.presenceIndex != noPresence {
|
||||
if !presence.Present(f.presenceIndex) {
|
||||
if f.isRequired {
|
||||
return errors.RequiredNotSet(string(mi.Desc.Fields().ByNumber(f.num).FullName()))
|
||||
}
|
||||
continue
|
||||
}
|
||||
if f.funcs.isInit != nil {
|
||||
f.mi.init()
|
||||
if f.mi.needsInitCheck {
|
||||
if f.isLazy && p.Apply(f.offset).AtomicGetPointer().IsNil() {
|
||||
lazy := *p.Apply(mi.lazyOffset).LazyInfoPtr()
|
||||
if !lazy.AllowedPartial() {
|
||||
// Nothing to see here, it was checked on unmarshal
|
||||
continue
|
||||
}
|
||||
mi.lazyUnmarshal(p, f.num)
|
||||
}
|
||||
if err := f.funcs.isInit(p.Apply(f.offset), f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
fptr := p.Apply(f.offset)
|
||||
if f.isPointer && fptr.Elem().IsNil() {
|
||||
if f.isRequired {
|
||||
|
||||
+264
@@ -0,0 +1,264 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
func makeOpaqueMessageFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointerCoderFuncs) {
|
||||
mi := getMessageInfo(ft)
|
||||
if mi == nil {
|
||||
panic(fmt.Sprintf("invalid field: %v: unsupported message type %v", fd.FullName(), ft))
|
||||
}
|
||||
switch fd.Kind() {
|
||||
case protoreflect.MessageKind:
|
||||
return mi, pointerCoderFuncs{
|
||||
size: sizeOpaqueMessage,
|
||||
marshal: appendOpaqueMessage,
|
||||
unmarshal: consumeOpaqueMessage,
|
||||
isInit: isInitOpaqueMessage,
|
||||
merge: mergeOpaqueMessage,
|
||||
}
|
||||
case protoreflect.GroupKind:
|
||||
return mi, pointerCoderFuncs{
|
||||
size: sizeOpaqueGroup,
|
||||
marshal: appendOpaqueGroup,
|
||||
unmarshal: consumeOpaqueGroup,
|
||||
isInit: isInitOpaqueMessage,
|
||||
merge: mergeOpaqueMessage,
|
||||
}
|
||||
}
|
||||
panic("unexpected field kind")
|
||||
}
|
||||
|
||||
func sizeOpaqueMessage(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
|
||||
return protowire.SizeBytes(f.mi.sizePointer(p.AtomicGetPointer(), opts)) + f.tagsize
|
||||
}
|
||||
|
||||
func appendOpaqueMessage(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
|
||||
mp := p.AtomicGetPointer()
|
||||
calculatedSize := f.mi.sizePointer(mp, opts)
|
||||
b = protowire.AppendVarint(b, f.wiretag)
|
||||
b = protowire.AppendVarint(b, uint64(calculatedSize))
|
||||
before := len(b)
|
||||
b, err := f.mi.marshalAppendPointer(b, mp, opts)
|
||||
if measuredSize := len(b) - before; calculatedSize != measuredSize && err == nil {
|
||||
return nil, errors.MismatchedSizeCalculation(calculatedSize, measuredSize)
|
||||
}
|
||||
return b, err
|
||||
}
|
||||
|
||||
func consumeOpaqueMessage(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
|
||||
if wtyp != protowire.BytesType {
|
||||
return out, errUnknown
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, errDecode
|
||||
}
|
||||
mp := p.AtomicGetPointer()
|
||||
if mp.IsNil() {
|
||||
mp = p.AtomicSetPointerIfNil(pointerOfValue(reflect.New(f.mi.GoReflectType.Elem())))
|
||||
}
|
||||
o, err := f.mi.unmarshalPointer(v, mp, 0, opts)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out.n = n
|
||||
out.initialized = o.initialized
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func isInitOpaqueMessage(p pointer, f *coderFieldInfo) error {
|
||||
mp := p.AtomicGetPointer()
|
||||
if mp.IsNil() {
|
||||
return nil
|
||||
}
|
||||
return f.mi.checkInitializedPointer(mp)
|
||||
}
|
||||
|
||||
func mergeOpaqueMessage(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
|
||||
dstmp := dst.AtomicGetPointer()
|
||||
if dstmp.IsNil() {
|
||||
dstmp = dst.AtomicSetPointerIfNil(pointerOfValue(reflect.New(f.mi.GoReflectType.Elem())))
|
||||
}
|
||||
f.mi.mergePointer(dstmp, src.AtomicGetPointer(), opts)
|
||||
}
|
||||
|
||||
func sizeOpaqueGroup(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
|
||||
return 2*f.tagsize + f.mi.sizePointer(p.AtomicGetPointer(), opts)
|
||||
}
|
||||
|
||||
func appendOpaqueGroup(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
|
||||
b = protowire.AppendVarint(b, f.wiretag) // start group
|
||||
b, err := f.mi.marshalAppendPointer(b, p.AtomicGetPointer(), opts)
|
||||
b = protowire.AppendVarint(b, f.wiretag+1) // end group
|
||||
return b, err
|
||||
}
|
||||
|
||||
func consumeOpaqueGroup(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
|
||||
if wtyp != protowire.StartGroupType {
|
||||
return out, errUnknown
|
||||
}
|
||||
mp := p.AtomicGetPointer()
|
||||
if mp.IsNil() {
|
||||
mp = p.AtomicSetPointerIfNil(pointerOfValue(reflect.New(f.mi.GoReflectType.Elem())))
|
||||
}
|
||||
o, e := f.mi.unmarshalPointer(b, mp, f.num, opts)
|
||||
return o, e
|
||||
}
|
||||
|
||||
func makeOpaqueRepeatedMessageFieldCoder(fd protoreflect.FieldDescriptor, ft reflect.Type) (*MessageInfo, pointerCoderFuncs) {
|
||||
if ft.Kind() != reflect.Ptr || ft.Elem().Kind() != reflect.Slice {
|
||||
panic(fmt.Sprintf("invalid field: %v: unsupported type for opaque repeated message: %v", fd.FullName(), ft))
|
||||
}
|
||||
mt := ft.Elem().Elem() // *[]*T -> *T
|
||||
mi := getMessageInfo(mt)
|
||||
if mi == nil {
|
||||
panic(fmt.Sprintf("invalid field: %v: unsupported message type %v", fd.FullName(), mt))
|
||||
}
|
||||
switch fd.Kind() {
|
||||
case protoreflect.MessageKind:
|
||||
return mi, pointerCoderFuncs{
|
||||
size: sizeOpaqueMessageSlice,
|
||||
marshal: appendOpaqueMessageSlice,
|
||||
unmarshal: consumeOpaqueMessageSlice,
|
||||
isInit: isInitOpaqueMessageSlice,
|
||||
merge: mergeOpaqueMessageSlice,
|
||||
}
|
||||
case protoreflect.GroupKind:
|
||||
return mi, pointerCoderFuncs{
|
||||
size: sizeOpaqueGroupSlice,
|
||||
marshal: appendOpaqueGroupSlice,
|
||||
unmarshal: consumeOpaqueGroupSlice,
|
||||
isInit: isInitOpaqueMessageSlice,
|
||||
merge: mergeOpaqueMessageSlice,
|
||||
}
|
||||
}
|
||||
panic("unexpected field kind")
|
||||
}
|
||||
|
||||
func sizeOpaqueMessageSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
|
||||
s := p.AtomicGetPointer().PointerSlice()
|
||||
n := 0
|
||||
for _, v := range s {
|
||||
n += protowire.SizeBytes(f.mi.sizePointer(v, opts)) + f.tagsize
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func appendOpaqueMessageSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
|
||||
s := p.AtomicGetPointer().PointerSlice()
|
||||
var err error
|
||||
for _, v := range s {
|
||||
b = protowire.AppendVarint(b, f.wiretag)
|
||||
siz := f.mi.sizePointer(v, opts)
|
||||
b = protowire.AppendVarint(b, uint64(siz))
|
||||
before := len(b)
|
||||
b, err = f.mi.marshalAppendPointer(b, v, opts)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
if measuredSize := len(b) - before; siz != measuredSize {
|
||||
return nil, errors.MismatchedSizeCalculation(siz, measuredSize)
|
||||
}
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func consumeOpaqueMessageSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
|
||||
if wtyp != protowire.BytesType {
|
||||
return out, errUnknown
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, errDecode
|
||||
}
|
||||
mp := pointerOfValue(reflect.New(f.mi.GoReflectType.Elem()))
|
||||
o, err := f.mi.unmarshalPointer(v, mp, 0, opts)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
sp := p.AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
sp = p.AtomicSetPointerIfNil(pointerOfValue(reflect.New(f.ft.Elem())))
|
||||
}
|
||||
sp.AppendPointerSlice(mp)
|
||||
out.n = n
|
||||
out.initialized = o.initialized
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func isInitOpaqueMessageSlice(p pointer, f *coderFieldInfo) error {
|
||||
sp := p.AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
return nil
|
||||
}
|
||||
s := sp.PointerSlice()
|
||||
for _, v := range s {
|
||||
if err := f.mi.checkInitializedPointer(v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func mergeOpaqueMessageSlice(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
|
||||
ds := dst.AtomicGetPointer()
|
||||
if ds.IsNil() {
|
||||
ds = dst.AtomicSetPointerIfNil(pointerOfValue(reflect.New(f.ft.Elem())))
|
||||
}
|
||||
for _, sp := range src.AtomicGetPointer().PointerSlice() {
|
||||
dm := pointerOfValue(reflect.New(f.mi.GoReflectType.Elem()))
|
||||
f.mi.mergePointer(dm, sp, opts)
|
||||
ds.AppendPointerSlice(dm)
|
||||
}
|
||||
}
|
||||
|
||||
func sizeOpaqueGroupSlice(p pointer, f *coderFieldInfo, opts marshalOptions) (size int) {
|
||||
s := p.AtomicGetPointer().PointerSlice()
|
||||
n := 0
|
||||
for _, v := range s {
|
||||
n += 2*f.tagsize + f.mi.sizePointer(v, opts)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func appendOpaqueGroupSlice(b []byte, p pointer, f *coderFieldInfo, opts marshalOptions) ([]byte, error) {
|
||||
s := p.AtomicGetPointer().PointerSlice()
|
||||
var err error
|
||||
for _, v := range s {
|
||||
b = protowire.AppendVarint(b, f.wiretag) // start group
|
||||
b, err = f.mi.marshalAppendPointer(b, v, opts)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
b = protowire.AppendVarint(b, f.wiretag+1) // end group
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func consumeOpaqueGroupSlice(b []byte, p pointer, wtyp protowire.Type, f *coderFieldInfo, opts unmarshalOptions) (out unmarshalOutput, err error) {
|
||||
if wtyp != protowire.StartGroupType {
|
||||
return out, errUnknown
|
||||
}
|
||||
mp := pointerOfValue(reflect.New(f.mi.GoReflectType.Elem()))
|
||||
out, err = f.mi.unmarshalPointer(b, mp, f.num, opts)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
sp := p.AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
sp = p.AtomicSetPointerIfNil(pointerOfValue(reflect.New(f.ft.Elem())))
|
||||
}
|
||||
sp.AppendPointerSlice(mp)
|
||||
return out, err
|
||||
}
|
||||
+7
-7
@@ -94,7 +94,7 @@ func sizeMap(mapv reflect.Value, mapi *mapInfo, f *coderFieldInfo, opts marshalO
|
||||
return 0
|
||||
}
|
||||
n := 0
|
||||
iter := mapRange(mapv)
|
||||
iter := mapv.MapRange()
|
||||
for iter.Next() {
|
||||
key := mapi.conv.keyConv.PBValueOf(iter.Key()).MapKey()
|
||||
keySize := mapi.keyFuncs.size(key.Value(), mapKeyTagSize, opts)
|
||||
@@ -281,7 +281,7 @@ func appendMap(b []byte, mapv reflect.Value, mapi *mapInfo, f *coderFieldInfo, o
|
||||
if opts.Deterministic() {
|
||||
return appendMapDeterministic(b, mapv, mapi, f, opts)
|
||||
}
|
||||
iter := mapRange(mapv)
|
||||
iter := mapv.MapRange()
|
||||
for iter.Next() {
|
||||
var err error
|
||||
b = protowire.AppendVarint(b, f.wiretag)
|
||||
@@ -328,7 +328,7 @@ func isInitMap(mapv reflect.Value, mapi *mapInfo, f *coderFieldInfo) error {
|
||||
if !mi.needsInitCheck {
|
||||
return nil
|
||||
}
|
||||
iter := mapRange(mapv)
|
||||
iter := mapv.MapRange()
|
||||
for iter.Next() {
|
||||
val := pointerOfValue(iter.Value())
|
||||
if err := mi.checkInitializedPointer(val); err != nil {
|
||||
@@ -336,7 +336,7 @@ func isInitMap(mapv reflect.Value, mapi *mapInfo, f *coderFieldInfo) error {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
iter := mapRange(mapv)
|
||||
iter := mapv.MapRange()
|
||||
for iter.Next() {
|
||||
val := mapi.conv.valConv.PBValueOf(iter.Value())
|
||||
if err := mapi.valFuncs.isInit(val); err != nil {
|
||||
@@ -356,7 +356,7 @@ func mergeMap(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
|
||||
if dstm.IsNil() {
|
||||
dstm.Set(reflect.MakeMap(f.ft))
|
||||
}
|
||||
iter := mapRange(srcm)
|
||||
iter := srcm.MapRange()
|
||||
for iter.Next() {
|
||||
dstm.SetMapIndex(iter.Key(), iter.Value())
|
||||
}
|
||||
@@ -371,7 +371,7 @@ func mergeMapOfBytes(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
|
||||
if dstm.IsNil() {
|
||||
dstm.Set(reflect.MakeMap(f.ft))
|
||||
}
|
||||
iter := mapRange(srcm)
|
||||
iter := srcm.MapRange()
|
||||
for iter.Next() {
|
||||
dstm.SetMapIndex(iter.Key(), reflect.ValueOf(append(emptyBuf[:], iter.Value().Bytes()...)))
|
||||
}
|
||||
@@ -386,7 +386,7 @@ func mergeMapOfMessage(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
|
||||
if dstm.IsNil() {
|
||||
dstm.Set(reflect.MakeMap(f.ft))
|
||||
}
|
||||
iter := mapRange(srcm)
|
||||
iter := srcm.MapRange()
|
||||
for iter.Next() {
|
||||
val := reflect.New(f.ft.Elem().Elem())
|
||||
if f.mi != nil {
|
||||
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !go1.12
|
||||
// +build !go1.12
|
||||
|
||||
package impl
|
||||
|
||||
import "reflect"
|
||||
|
||||
type mapIter struct {
|
||||
v reflect.Value
|
||||
keys []reflect.Value
|
||||
}
|
||||
|
||||
// mapRange provides a less-efficient equivalent to
|
||||
// the Go 1.12 reflect.Value.MapRange method.
|
||||
func mapRange(v reflect.Value) *mapIter {
|
||||
return &mapIter{v: v}
|
||||
}
|
||||
|
||||
func (i *mapIter) Next() bool {
|
||||
if i.keys == nil {
|
||||
i.keys = i.v.MapKeys()
|
||||
} else {
|
||||
i.keys = i.keys[1:]
|
||||
}
|
||||
return len(i.keys) > 0
|
||||
}
|
||||
|
||||
func (i *mapIter) Key() reflect.Value {
|
||||
return i.keys[0]
|
||||
}
|
||||
|
||||
func (i *mapIter) Value() reflect.Value {
|
||||
return i.v.MapIndex(i.keys[0])
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build go1.12
|
||||
// +build go1.12
|
||||
|
||||
package impl
|
||||
|
||||
import "reflect"
|
||||
|
||||
func mapRange(v reflect.Value) *reflect.MapIter { return v.MapRange() }
|
||||
+15
-2
@@ -32,6 +32,10 @@ type coderMessageInfo struct {
|
||||
needsInitCheck bool
|
||||
isMessageSet bool
|
||||
numRequiredFields uint8
|
||||
|
||||
lazyOffset offset
|
||||
presenceOffset offset
|
||||
presenceSize presenceSize
|
||||
}
|
||||
|
||||
type coderFieldInfo struct {
|
||||
@@ -45,12 +49,19 @@ type coderFieldInfo struct {
|
||||
tagsize int // size of the varint-encoded tag
|
||||
isPointer bool // true if IsNil may be called on the struct field
|
||||
isRequired bool // true if field is required
|
||||
|
||||
isLazy bool
|
||||
presenceIndex uint32
|
||||
}
|
||||
|
||||
const noPresence = 0xffffffff
|
||||
|
||||
func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
|
||||
mi.sizecacheOffset = invalidOffset
|
||||
mi.unknownOffset = invalidOffset
|
||||
mi.extensionOffset = invalidOffset
|
||||
mi.lazyOffset = invalidOffset
|
||||
mi.presenceOffset = si.presenceOffset
|
||||
|
||||
if si.sizecacheOffset.IsValid() && si.sizecacheType == sizecacheType {
|
||||
mi.sizecacheOffset = si.sizecacheOffset
|
||||
@@ -107,12 +118,12 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
|
||||
},
|
||||
}
|
||||
case isOneof:
|
||||
fieldOffset = offsetOf(fs, mi.Exporter)
|
||||
fieldOffset = offsetOf(fs)
|
||||
case fd.IsWeak():
|
||||
fieldOffset = si.weakOffset
|
||||
funcs = makeWeakMessageFieldCoder(fd)
|
||||
default:
|
||||
fieldOffset = offsetOf(fs, mi.Exporter)
|
||||
fieldOffset = offsetOf(fs)
|
||||
childMessage, funcs = fieldCoder(fd, ft)
|
||||
}
|
||||
cf := &preallocFields[i]
|
||||
@@ -127,6 +138,8 @@ func (mi *MessageInfo) makeCoderMethods(t reflect.Type, si structInfo) {
|
||||
validation: newFieldValidationInfo(mi, si, fd, ft),
|
||||
isPointer: fd.Cardinality() == protoreflect.Repeated || fd.HasPresence(),
|
||||
isRequired: fd.Cardinality() == protoreflect.Required,
|
||||
|
||||
presenceIndex: noPresence,
|
||||
}
|
||||
mi.orderedCoderFields = append(mi.orderedCoderFields, cf)
|
||||
mi.coderFields[cf.num] = cf
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/encoding/messageset"
|
||||
"google.golang.org/protobuf/internal/order"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
||||
func (mi *MessageInfo) makeOpaqueCoderMethods(t reflect.Type, si opaqueStructInfo) {
|
||||
mi.sizecacheOffset = si.sizecacheOffset
|
||||
mi.unknownOffset = si.unknownOffset
|
||||
mi.unknownPtrKind = si.unknownType.Kind() == reflect.Ptr
|
||||
mi.extensionOffset = si.extensionOffset
|
||||
mi.lazyOffset = si.lazyOffset
|
||||
mi.presenceOffset = si.presenceOffset
|
||||
|
||||
mi.coderFields = make(map[protowire.Number]*coderFieldInfo)
|
||||
fields := mi.Desc.Fields()
|
||||
for i := 0; i < fields.Len(); i++ {
|
||||
fd := fields.Get(i)
|
||||
|
||||
fs := si.fieldsByNumber[fd.Number()]
|
||||
if fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic() {
|
||||
fs = si.oneofsByName[fd.ContainingOneof().Name()]
|
||||
}
|
||||
ft := fs.Type
|
||||
var wiretag uint64
|
||||
if !fd.IsPacked() {
|
||||
wiretag = protowire.EncodeTag(fd.Number(), wireTypes[fd.Kind()])
|
||||
} else {
|
||||
wiretag = protowire.EncodeTag(fd.Number(), protowire.BytesType)
|
||||
}
|
||||
var fieldOffset offset
|
||||
var funcs pointerCoderFuncs
|
||||
var childMessage *MessageInfo
|
||||
switch {
|
||||
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
|
||||
fieldOffset = offsetOf(fs)
|
||||
case fd.IsWeak():
|
||||
fieldOffset = si.weakOffset
|
||||
funcs = makeWeakMessageFieldCoder(fd)
|
||||
case fd.Message() != nil && !fd.IsMap():
|
||||
fieldOffset = offsetOf(fs)
|
||||
if fd.IsList() {
|
||||
childMessage, funcs = makeOpaqueRepeatedMessageFieldCoder(fd, ft)
|
||||
} else {
|
||||
childMessage, funcs = makeOpaqueMessageFieldCoder(fd, ft)
|
||||
}
|
||||
default:
|
||||
fieldOffset = offsetOf(fs)
|
||||
childMessage, funcs = fieldCoder(fd, ft)
|
||||
}
|
||||
cf := &coderFieldInfo{
|
||||
num: fd.Number(),
|
||||
offset: fieldOffset,
|
||||
wiretag: wiretag,
|
||||
ft: ft,
|
||||
tagsize: protowire.SizeVarint(wiretag),
|
||||
funcs: funcs,
|
||||
mi: childMessage,
|
||||
validation: newFieldValidationInfo(mi, si.structInfo, fd, ft),
|
||||
isPointer: (fd.Cardinality() == protoreflect.Repeated ||
|
||||
fd.Kind() == protoreflect.MessageKind ||
|
||||
fd.Kind() == protoreflect.GroupKind),
|
||||
isRequired: fd.Cardinality() == protoreflect.Required,
|
||||
presenceIndex: noPresence,
|
||||
}
|
||||
|
||||
// TODO: Use presence for all fields.
|
||||
//
|
||||
// In some cases, such as maps, presence means only "might be set" rather
|
||||
// than "is definitely set", but every field should have a presence bit to
|
||||
// permit us to skip over definitely-unset fields at marshal time.
|
||||
|
||||
var hasPresence bool
|
||||
hasPresence, cf.isLazy = usePresenceForField(si, fd)
|
||||
|
||||
if hasPresence {
|
||||
cf.presenceIndex, mi.presenceSize = presenceIndex(mi.Desc, fd)
|
||||
}
|
||||
|
||||
mi.orderedCoderFields = append(mi.orderedCoderFields, cf)
|
||||
mi.coderFields[cf.num] = cf
|
||||
}
|
||||
for i, oneofs := 0, mi.Desc.Oneofs(); i < oneofs.Len(); i++ {
|
||||
if od := oneofs.Get(i); !od.IsSynthetic() {
|
||||
mi.initOneofFieldCoders(od, si.structInfo)
|
||||
}
|
||||
}
|
||||
if messageset.IsMessageSet(mi.Desc) {
|
||||
if !mi.extensionOffset.IsValid() {
|
||||
panic(fmt.Sprintf("%v: MessageSet with no extensions field", mi.Desc.FullName()))
|
||||
}
|
||||
if !mi.unknownOffset.IsValid() {
|
||||
panic(fmt.Sprintf("%v: MessageSet with no unknown field", mi.Desc.FullName()))
|
||||
}
|
||||
mi.isMessageSet = true
|
||||
}
|
||||
sort.Slice(mi.orderedCoderFields, func(i, j int) bool {
|
||||
return mi.orderedCoderFields[i].num < mi.orderedCoderFields[j].num
|
||||
})
|
||||
|
||||
var maxDense protoreflect.FieldNumber
|
||||
for _, cf := range mi.orderedCoderFields {
|
||||
if cf.num >= 16 && cf.num >= 2*maxDense {
|
||||
break
|
||||
}
|
||||
maxDense = cf.num
|
||||
}
|
||||
mi.denseCoderFields = make([]*coderFieldInfo, maxDense+1)
|
||||
for _, cf := range mi.orderedCoderFields {
|
||||
if int(cf.num) > len(mi.denseCoderFields) {
|
||||
break
|
||||
}
|
||||
mi.denseCoderFields[cf.num] = cf
|
||||
}
|
||||
|
||||
// To preserve compatibility with historic wire output, marshal oneofs last.
|
||||
if mi.Desc.Oneofs().Len() > 0 {
|
||||
sort.Slice(mi.orderedCoderFields, func(i, j int) bool {
|
||||
fi := fields.ByNumber(mi.orderedCoderFields[i].num)
|
||||
fj := fields.ByNumber(mi.orderedCoderFields[j].num)
|
||||
return order.LegacyFieldOrder(fi, fj)
|
||||
})
|
||||
}
|
||||
|
||||
mi.needsInitCheck = needsInitCheck(mi.Desc)
|
||||
if mi.methods.Marshal == nil && mi.methods.Size == nil {
|
||||
mi.methods.Flags |= piface.SupportMarshalDeterministic
|
||||
mi.methods.Marshal = mi.marshal
|
||||
mi.methods.Size = mi.size
|
||||
}
|
||||
if mi.methods.Unmarshal == nil {
|
||||
mi.methods.Flags |= piface.SupportUnmarshalDiscardUnknown
|
||||
mi.methods.Unmarshal = mi.unmarshal
|
||||
}
|
||||
if mi.methods.CheckInitialized == nil {
|
||||
mi.methods.CheckInitialized = mi.checkInitialized
|
||||
}
|
||||
if mi.methods.Merge == nil {
|
||||
mi.methods.Merge = mi.merge
|
||||
}
|
||||
if mi.methods.Equal == nil {
|
||||
mi.methods.Equal = equal
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -101,7 +101,7 @@ func (ms *mapReflect) Mutable(k protoreflect.MapKey) protoreflect.Value {
|
||||
return v
|
||||
}
|
||||
func (ms *mapReflect) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) {
|
||||
iter := mapRange(ms.v)
|
||||
iter := ms.v.MapRange()
|
||||
for iter.Next() {
|
||||
k := ms.keyConv.PBValueOf(iter.Key()).MapKey()
|
||||
v := ms.valConv.PBValueOf(iter.Value())
|
||||
|
||||
+52
-4
@@ -34,6 +34,8 @@ func (o unmarshalOptions) Options() proto.UnmarshalOptions {
|
||||
AllowPartial: true,
|
||||
DiscardUnknown: o.DiscardUnknown(),
|
||||
Resolver: o.resolver,
|
||||
|
||||
NoLazyDecoding: o.NoLazyDecoding(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,13 +43,26 @@ func (o unmarshalOptions) DiscardUnknown() bool {
|
||||
return o.flags&protoiface.UnmarshalDiscardUnknown != 0
|
||||
}
|
||||
|
||||
func (o unmarshalOptions) IsDefault() bool {
|
||||
return o.flags == 0 && o.resolver == protoregistry.GlobalTypes
|
||||
func (o unmarshalOptions) AliasBuffer() bool { return o.flags&protoiface.UnmarshalAliasBuffer != 0 }
|
||||
func (o unmarshalOptions) Validated() bool { return o.flags&protoiface.UnmarshalValidated != 0 }
|
||||
func (o unmarshalOptions) NoLazyDecoding() bool {
|
||||
return o.flags&protoiface.UnmarshalNoLazyDecoding != 0
|
||||
}
|
||||
|
||||
func (o unmarshalOptions) CanBeLazy() bool {
|
||||
if o.resolver != protoregistry.GlobalTypes {
|
||||
return false
|
||||
}
|
||||
// We ignore the UnmarshalInvalidateSizeCache even though it's not in the default set
|
||||
return (o.flags & ^(protoiface.UnmarshalAliasBuffer | protoiface.UnmarshalValidated | protoiface.UnmarshalCheckRequired)) == 0
|
||||
}
|
||||
|
||||
var lazyUnmarshalOptions = unmarshalOptions{
|
||||
resolver: protoregistry.GlobalTypes,
|
||||
depth: protowire.DefaultRecursionLimit,
|
||||
|
||||
flags: protoiface.UnmarshalAliasBuffer | protoiface.UnmarshalValidated,
|
||||
|
||||
depth: protowire.DefaultRecursionLimit,
|
||||
}
|
||||
|
||||
type unmarshalOutput struct {
|
||||
@@ -94,9 +109,30 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag protowire.
|
||||
if flags.ProtoLegacy && mi.isMessageSet {
|
||||
return unmarshalMessageSet(mi, b, p, opts)
|
||||
}
|
||||
|
||||
lazyDecoding := LazyEnabled() // default
|
||||
if opts.NoLazyDecoding() {
|
||||
lazyDecoding = false // explicitly disabled
|
||||
}
|
||||
if mi.lazyOffset.IsValid() && lazyDecoding {
|
||||
return mi.unmarshalPointerLazy(b, p, groupTag, opts)
|
||||
}
|
||||
return mi.unmarshalPointerEager(b, p, groupTag, opts)
|
||||
}
|
||||
|
||||
// unmarshalPointerEager is the message unmarshalling function for all messages that are not lazy.
|
||||
// The corresponding function for Lazy is in google_lazy.go.
|
||||
func (mi *MessageInfo) unmarshalPointerEager(b []byte, p pointer, groupTag protowire.Number, opts unmarshalOptions) (out unmarshalOutput, err error) {
|
||||
|
||||
initialized := true
|
||||
var requiredMask uint64
|
||||
var exts *map[int32]ExtensionField
|
||||
|
||||
var presence presence
|
||||
if mi.presenceOffset.IsValid() {
|
||||
presence = p.Apply(mi.presenceOffset).PresenceInfo()
|
||||
}
|
||||
|
||||
start := len(b)
|
||||
for len(b) > 0 {
|
||||
// Parse the tag (field number and wire type).
|
||||
@@ -154,6 +190,11 @@ func (mi *MessageInfo) unmarshalPointer(b []byte, p pointer, groupTag protowire.
|
||||
if f.funcs.isInit != nil && !o.initialized {
|
||||
initialized = false
|
||||
}
|
||||
|
||||
if f.presenceIndex != noPresence {
|
||||
presence.SetPresentUnatomic(f.presenceIndex, mi.presenceSize)
|
||||
}
|
||||
|
||||
default:
|
||||
// Possible extension.
|
||||
if exts == nil && mi.extensionOffset.IsValid() {
|
||||
@@ -222,7 +263,7 @@ func (mi *MessageInfo) unmarshalExtension(b []byte, num protowire.Number, wtyp p
|
||||
return out, errUnknown
|
||||
}
|
||||
if flags.LazyUnmarshalExtensions {
|
||||
if opts.IsDefault() && x.canLazy(xt) {
|
||||
if opts.CanBeLazy() && x.canLazy(xt) {
|
||||
out, valid := skipExtension(b, xi, num, wtyp, opts)
|
||||
switch valid {
|
||||
case ValidationValid:
|
||||
@@ -270,6 +311,13 @@ func skipExtension(b []byte, xi *extensionFieldInfo, num protowire.Number, wtyp
|
||||
if n < 0 {
|
||||
return out, ValidationUnknown
|
||||
}
|
||||
|
||||
if opts.Validated() {
|
||||
out.initialized = true
|
||||
out.n = n
|
||||
return out, ValidationValid
|
||||
}
|
||||
|
||||
out, st := xi.validation.mi.validate(v, 0, opts)
|
||||
out.n = n
|
||||
return out, st
|
||||
|
||||
+78
@@ -10,6 +10,7 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"google.golang.org/protobuf/internal/flags"
|
||||
"google.golang.org/protobuf/internal/protolazy"
|
||||
"google.golang.org/protobuf/proto"
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
@@ -71,11 +72,39 @@ func (mi *MessageInfo) sizePointerSlow(p pointer, opts marshalOptions) (size int
|
||||
e := p.Apply(mi.extensionOffset).Extensions()
|
||||
size += mi.sizeExtensions(e, opts)
|
||||
}
|
||||
|
||||
var lazy **protolazy.XXX_lazyUnmarshalInfo
|
||||
var presence presence
|
||||
if mi.presenceOffset.IsValid() {
|
||||
presence = p.Apply(mi.presenceOffset).PresenceInfo()
|
||||
if mi.lazyOffset.IsValid() {
|
||||
lazy = p.Apply(mi.lazyOffset).LazyInfoPtr()
|
||||
}
|
||||
}
|
||||
|
||||
for _, f := range mi.orderedCoderFields {
|
||||
if f.funcs.size == nil {
|
||||
continue
|
||||
}
|
||||
fptr := p.Apply(f.offset)
|
||||
|
||||
if f.presenceIndex != noPresence {
|
||||
if !presence.Present(f.presenceIndex) {
|
||||
continue
|
||||
}
|
||||
|
||||
if f.isLazy && fptr.AtomicGetPointer().IsNil() {
|
||||
if lazyFields(opts) {
|
||||
size += (*lazy).SizeField(uint32(f.num))
|
||||
continue
|
||||
} else {
|
||||
mi.lazyUnmarshal(p, f.num)
|
||||
}
|
||||
}
|
||||
size += f.funcs.size(fptr, f, opts)
|
||||
continue
|
||||
}
|
||||
|
||||
if f.isPointer && fptr.Elem().IsNil() {
|
||||
continue
|
||||
}
|
||||
@@ -134,11 +163,52 @@ func (mi *MessageInfo) marshalAppendPointer(b []byte, p pointer, opts marshalOpt
|
||||
return b, err
|
||||
}
|
||||
}
|
||||
|
||||
var lazy **protolazy.XXX_lazyUnmarshalInfo
|
||||
var presence presence
|
||||
if mi.presenceOffset.IsValid() {
|
||||
presence = p.Apply(mi.presenceOffset).PresenceInfo()
|
||||
if mi.lazyOffset.IsValid() {
|
||||
lazy = p.Apply(mi.lazyOffset).LazyInfoPtr()
|
||||
}
|
||||
}
|
||||
|
||||
for _, f := range mi.orderedCoderFields {
|
||||
if f.funcs.marshal == nil {
|
||||
continue
|
||||
}
|
||||
fptr := p.Apply(f.offset)
|
||||
|
||||
if f.presenceIndex != noPresence {
|
||||
if !presence.Present(f.presenceIndex) {
|
||||
continue
|
||||
}
|
||||
if f.isLazy {
|
||||
// Be careful, this field needs to be read atomically, like for a get
|
||||
if f.isPointer && fptr.AtomicGetPointer().IsNil() {
|
||||
if lazyFields(opts) {
|
||||
b, _ = (*lazy).AppendField(b, uint32(f.num))
|
||||
continue
|
||||
} else {
|
||||
mi.lazyUnmarshal(p, f.num)
|
||||
}
|
||||
}
|
||||
|
||||
b, err = f.funcs.marshal(b, fptr, f, opts)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
continue
|
||||
} else if f.isPointer && fptr.Elem().IsNil() {
|
||||
continue
|
||||
}
|
||||
b, err = f.funcs.marshal(b, fptr, f, opts)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if f.isPointer && fptr.Elem().IsNil() {
|
||||
continue
|
||||
}
|
||||
@@ -163,6 +233,14 @@ func fullyLazyExtensions(opts marshalOptions) bool {
|
||||
return opts.flags&piface.MarshalDeterministic == 0
|
||||
}
|
||||
|
||||
// lazyFields returns true if we should attempt to keep fields lazy over size and marshal.
|
||||
func lazyFields(opts marshalOptions) bool {
|
||||
// When deterministic marshaling is requested, force an unmarshal for lazy
|
||||
// fields to produce a deterministic result, instead of passing through
|
||||
// bytes lazily that may or may not match what Go Protobuf would produce.
|
||||
return opts.flags&piface.MarshalDeterministic == 0
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) sizeExtensions(ext *map[int32]ExtensionField, opts marshalOptions) (n int) {
|
||||
if ext == nil {
|
||||
return 0
|
||||
|
||||
+433
@@ -0,0 +1,433 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync/atomic"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/internal/protolazy"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
preg "google.golang.org/protobuf/reflect/protoregistry"
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
||||
var enableLazy int32 = func() int32 {
|
||||
if os.Getenv("GOPROTODEBUG") == "nolazy" {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}()
|
||||
|
||||
// EnableLazyUnmarshal enables lazy unmarshaling.
|
||||
func EnableLazyUnmarshal(enable bool) {
|
||||
if enable {
|
||||
atomic.StoreInt32(&enableLazy, 1)
|
||||
return
|
||||
}
|
||||
atomic.StoreInt32(&enableLazy, 0)
|
||||
}
|
||||
|
||||
// LazyEnabled reports whether lazy unmarshalling is currently enabled.
|
||||
func LazyEnabled() bool {
|
||||
return atomic.LoadInt32(&enableLazy) != 0
|
||||
}
|
||||
|
||||
// UnmarshalField unmarshals a field in a message.
|
||||
func UnmarshalField(m interface{}, num protowire.Number) {
|
||||
switch m := m.(type) {
|
||||
case *messageState:
|
||||
m.messageInfo().lazyUnmarshal(m.pointer(), num)
|
||||
case *messageReflectWrapper:
|
||||
m.messageInfo().lazyUnmarshal(m.pointer(), num)
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported wrapper type %T", m))
|
||||
}
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) lazyUnmarshal(p pointer, num protoreflect.FieldNumber) {
|
||||
var f *coderFieldInfo
|
||||
if int(num) < len(mi.denseCoderFields) {
|
||||
f = mi.denseCoderFields[num]
|
||||
} else {
|
||||
f = mi.coderFields[num]
|
||||
}
|
||||
if f == nil {
|
||||
panic(fmt.Sprintf("lazyUnmarshal: field info for %v.%v", mi.Desc.FullName(), num))
|
||||
}
|
||||
lazy := *p.Apply(mi.lazyOffset).LazyInfoPtr()
|
||||
start, end, found, _, multipleEntries := lazy.FindFieldInProto(uint32(num))
|
||||
if !found && multipleEntries == nil {
|
||||
panic(fmt.Sprintf("lazyUnmarshal: can't find field data for %v.%v", mi.Desc.FullName(), num))
|
||||
}
|
||||
// The actual pointer in the message can not be set until the whole struct is filled in, otherwise we will have races.
|
||||
// Create another pointer and set it atomically, if we won the race and the pointer in the original message is still nil.
|
||||
fp := pointerOfValue(reflect.New(f.ft))
|
||||
if multipleEntries != nil {
|
||||
for _, entry := range multipleEntries {
|
||||
mi.unmarshalField(lazy.Buffer()[entry.Start:entry.End], fp, f, lazy, lazy.UnmarshalFlags())
|
||||
}
|
||||
} else {
|
||||
mi.unmarshalField(lazy.Buffer()[start:end], fp, f, lazy, lazy.UnmarshalFlags())
|
||||
}
|
||||
p.Apply(f.offset).AtomicSetPointerIfNil(fp.Elem())
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) unmarshalField(b []byte, p pointer, f *coderFieldInfo, lazyInfo *protolazy.XXX_lazyUnmarshalInfo, flags piface.UnmarshalInputFlags) error {
|
||||
opts := lazyUnmarshalOptions
|
||||
opts.flags |= flags
|
||||
for len(b) > 0 {
|
||||
// Parse the tag (field number and wire type).
|
||||
var tag uint64
|
||||
if b[0] < 0x80 {
|
||||
tag = uint64(b[0])
|
||||
b = b[1:]
|
||||
} else if len(b) >= 2 && b[1] < 128 {
|
||||
tag = uint64(b[0]&0x7f) + uint64(b[1])<<7
|
||||
b = b[2:]
|
||||
} else {
|
||||
var n int
|
||||
tag, n = protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return errors.New("invalid wire data")
|
||||
}
|
||||
b = b[n:]
|
||||
}
|
||||
var num protowire.Number
|
||||
if n := tag >> 3; n < uint64(protowire.MinValidNumber) || n > uint64(protowire.MaxValidNumber) {
|
||||
return errors.New("invalid wire data")
|
||||
} else {
|
||||
num = protowire.Number(n)
|
||||
}
|
||||
wtyp := protowire.Type(tag & 7)
|
||||
if num == f.num {
|
||||
o, err := f.funcs.unmarshal(b, p, wtyp, f, opts)
|
||||
if err == nil {
|
||||
b = b[o.n:]
|
||||
continue
|
||||
}
|
||||
if err != errUnknown {
|
||||
return err
|
||||
}
|
||||
}
|
||||
n := protowire.ConsumeFieldValue(num, wtyp, b)
|
||||
if n < 0 {
|
||||
return errors.New("invalid wire data")
|
||||
}
|
||||
b = b[n:]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) skipField(b []byte, f *coderFieldInfo, wtyp protowire.Type, opts unmarshalOptions) (out unmarshalOutput, _ ValidationStatus) {
|
||||
fmi := f.validation.mi
|
||||
if fmi == nil {
|
||||
fd := mi.Desc.Fields().ByNumber(f.num)
|
||||
if fd == nil || !fd.IsWeak() {
|
||||
return out, ValidationUnknown
|
||||
}
|
||||
messageName := fd.Message().FullName()
|
||||
messageType, err := preg.GlobalTypes.FindMessageByName(messageName)
|
||||
if err != nil {
|
||||
return out, ValidationUnknown
|
||||
}
|
||||
var ok bool
|
||||
fmi, ok = messageType.(*MessageInfo)
|
||||
if !ok {
|
||||
return out, ValidationUnknown
|
||||
}
|
||||
}
|
||||
fmi.init()
|
||||
switch f.validation.typ {
|
||||
case validationTypeMessage:
|
||||
if wtyp != protowire.BytesType {
|
||||
return out, ValidationWrongWireType
|
||||
}
|
||||
v, n := protowire.ConsumeBytes(b)
|
||||
if n < 0 {
|
||||
return out, ValidationInvalid
|
||||
}
|
||||
out, st := fmi.validate(v, 0, opts)
|
||||
out.n = n
|
||||
return out, st
|
||||
case validationTypeGroup:
|
||||
if wtyp != protowire.StartGroupType {
|
||||
return out, ValidationWrongWireType
|
||||
}
|
||||
out, st := fmi.validate(b, f.num, opts)
|
||||
return out, st
|
||||
default:
|
||||
return out, ValidationUnknown
|
||||
}
|
||||
}
|
||||
|
||||
// unmarshalPointerLazy is similar to unmarshalPointerEager, but it
|
||||
// specifically handles lazy unmarshalling. it expects lazyOffset and
|
||||
// presenceOffset to both be valid.
|
||||
func (mi *MessageInfo) unmarshalPointerLazy(b []byte, p pointer, groupTag protowire.Number, opts unmarshalOptions) (out unmarshalOutput, err error) {
|
||||
initialized := true
|
||||
var requiredMask uint64
|
||||
var lazy **protolazy.XXX_lazyUnmarshalInfo
|
||||
var presence presence
|
||||
var lazyIndex []protolazy.IndexEntry
|
||||
var lastNum protowire.Number
|
||||
outOfOrder := false
|
||||
lazyDecode := false
|
||||
presence = p.Apply(mi.presenceOffset).PresenceInfo()
|
||||
lazy = p.Apply(mi.lazyOffset).LazyInfoPtr()
|
||||
if !presence.AnyPresent(mi.presenceSize) {
|
||||
if opts.CanBeLazy() {
|
||||
// If the message contains existing data, we need to merge into it.
|
||||
// Lazy unmarshaling doesn't merge, so only enable it when the
|
||||
// message is empty (has no presence bitmap).
|
||||
lazyDecode = true
|
||||
if *lazy == nil {
|
||||
*lazy = &protolazy.XXX_lazyUnmarshalInfo{}
|
||||
}
|
||||
(*lazy).SetUnmarshalFlags(opts.flags)
|
||||
if !opts.AliasBuffer() {
|
||||
// Make a copy of the buffer for lazy unmarshaling.
|
||||
// Set the AliasBuffer flag so recursive unmarshal
|
||||
// operations reuse the copy.
|
||||
b = append([]byte{}, b...)
|
||||
opts.flags |= piface.UnmarshalAliasBuffer
|
||||
}
|
||||
(*lazy).SetBuffer(b)
|
||||
}
|
||||
}
|
||||
// Track special handling of lazy fields.
|
||||
//
|
||||
// In the common case, all fields are lazyValidateOnly (and lazyFields remains nil).
|
||||
// In the event that validation for a field fails, this map tracks handling of the field.
|
||||
type lazyAction uint8
|
||||
const (
|
||||
lazyValidateOnly lazyAction = iota // validate the field only
|
||||
lazyUnmarshalNow // eagerly unmarshal the field
|
||||
lazyUnmarshalLater // unmarshal the field after the message is fully processed
|
||||
)
|
||||
var lazyFields map[*coderFieldInfo]lazyAction
|
||||
var exts *map[int32]ExtensionField
|
||||
start := len(b)
|
||||
pos := 0
|
||||
for len(b) > 0 {
|
||||
// Parse the tag (field number and wire type).
|
||||
var tag uint64
|
||||
if b[0] < 0x80 {
|
||||
tag = uint64(b[0])
|
||||
b = b[1:]
|
||||
} else if len(b) >= 2 && b[1] < 128 {
|
||||
tag = uint64(b[0]&0x7f) + uint64(b[1])<<7
|
||||
b = b[2:]
|
||||
} else {
|
||||
var n int
|
||||
tag, n = protowire.ConsumeVarint(b)
|
||||
if n < 0 {
|
||||
return out, errDecode
|
||||
}
|
||||
b = b[n:]
|
||||
}
|
||||
var num protowire.Number
|
||||
if n := tag >> 3; n < uint64(protowire.MinValidNumber) || n > uint64(protowire.MaxValidNumber) {
|
||||
return out, errors.New("invalid field number")
|
||||
} else {
|
||||
num = protowire.Number(n)
|
||||
}
|
||||
wtyp := protowire.Type(tag & 7)
|
||||
|
||||
if wtyp == protowire.EndGroupType {
|
||||
if num != groupTag {
|
||||
return out, errors.New("mismatching end group marker")
|
||||
}
|
||||
groupTag = 0
|
||||
break
|
||||
}
|
||||
|
||||
var f *coderFieldInfo
|
||||
if int(num) < len(mi.denseCoderFields) {
|
||||
f = mi.denseCoderFields[num]
|
||||
} else {
|
||||
f = mi.coderFields[num]
|
||||
}
|
||||
var n int
|
||||
err := errUnknown
|
||||
discardUnknown := false
|
||||
Field:
|
||||
switch {
|
||||
case f != nil:
|
||||
if f.funcs.unmarshal == nil {
|
||||
break
|
||||
}
|
||||
if f.isLazy && lazyDecode {
|
||||
switch {
|
||||
case lazyFields == nil || lazyFields[f] == lazyValidateOnly:
|
||||
// Attempt to validate this field and leave it for later lazy unmarshaling.
|
||||
o, valid := mi.skipField(b, f, wtyp, opts)
|
||||
switch valid {
|
||||
case ValidationValid:
|
||||
// Skip over the valid field and continue.
|
||||
err = nil
|
||||
presence.SetPresentUnatomic(f.presenceIndex, mi.presenceSize)
|
||||
requiredMask |= f.validation.requiredBit
|
||||
if !o.initialized {
|
||||
initialized = false
|
||||
}
|
||||
n = o.n
|
||||
break Field
|
||||
case ValidationInvalid:
|
||||
return out, errors.New("invalid proto wire format")
|
||||
case ValidationWrongWireType:
|
||||
break Field
|
||||
case ValidationUnknown:
|
||||
if lazyFields == nil {
|
||||
lazyFields = make(map[*coderFieldInfo]lazyAction)
|
||||
}
|
||||
if presence.Present(f.presenceIndex) {
|
||||
// We were unable to determine if the field is valid or not,
|
||||
// and we've already skipped over at least one instance of this
|
||||
// field. Clear the presence bit (so if we stop decoding early,
|
||||
// we don't leave a partially-initialized field around) and flag
|
||||
// the field for unmarshaling before we return.
|
||||
presence.ClearPresent(f.presenceIndex)
|
||||
lazyFields[f] = lazyUnmarshalLater
|
||||
discardUnknown = true
|
||||
break Field
|
||||
} else {
|
||||
// We were unable to determine if the field is valid or not,
|
||||
// but this is the first time we've seen it. Flag it as needing
|
||||
// eager unmarshaling and fall through to the eager unmarshal case below.
|
||||
lazyFields[f] = lazyUnmarshalNow
|
||||
}
|
||||
}
|
||||
case lazyFields[f] == lazyUnmarshalLater:
|
||||
// This field will be unmarshaled in a separate pass below.
|
||||
// Skip over it here.
|
||||
discardUnknown = true
|
||||
break Field
|
||||
default:
|
||||
// Eagerly unmarshal the field.
|
||||
}
|
||||
}
|
||||
if f.isLazy && !lazyDecode && presence.Present(f.presenceIndex) {
|
||||
if p.Apply(f.offset).AtomicGetPointer().IsNil() {
|
||||
mi.lazyUnmarshal(p, f.num)
|
||||
}
|
||||
}
|
||||
var o unmarshalOutput
|
||||
o, err = f.funcs.unmarshal(b, p.Apply(f.offset), wtyp, f, opts)
|
||||
n = o.n
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
requiredMask |= f.validation.requiredBit
|
||||
if f.funcs.isInit != nil && !o.initialized {
|
||||
initialized = false
|
||||
}
|
||||
if f.presenceIndex != noPresence {
|
||||
presence.SetPresentUnatomic(f.presenceIndex, mi.presenceSize)
|
||||
}
|
||||
default:
|
||||
// Possible extension.
|
||||
if exts == nil && mi.extensionOffset.IsValid() {
|
||||
exts = p.Apply(mi.extensionOffset).Extensions()
|
||||
if *exts == nil {
|
||||
*exts = make(map[int32]ExtensionField)
|
||||
}
|
||||
}
|
||||
if exts == nil {
|
||||
break
|
||||
}
|
||||
var o unmarshalOutput
|
||||
o, err = mi.unmarshalExtension(b, num, wtyp, *exts, opts)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
n = o.n
|
||||
if !o.initialized {
|
||||
initialized = false
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
if err != errUnknown {
|
||||
return out, err
|
||||
}
|
||||
n = protowire.ConsumeFieldValue(num, wtyp, b)
|
||||
if n < 0 {
|
||||
return out, errDecode
|
||||
}
|
||||
if !discardUnknown && !opts.DiscardUnknown() && mi.unknownOffset.IsValid() {
|
||||
u := mi.mutableUnknownBytes(p)
|
||||
*u = protowire.AppendTag(*u, num, wtyp)
|
||||
*u = append(*u, b[:n]...)
|
||||
}
|
||||
}
|
||||
b = b[n:]
|
||||
end := start - len(b)
|
||||
if lazyDecode && f != nil && f.isLazy {
|
||||
if num != lastNum {
|
||||
lazyIndex = append(lazyIndex, protolazy.IndexEntry{
|
||||
FieldNum: uint32(num),
|
||||
Start: uint32(pos),
|
||||
End: uint32(end),
|
||||
})
|
||||
} else {
|
||||
i := len(lazyIndex) - 1
|
||||
lazyIndex[i].End = uint32(end)
|
||||
lazyIndex[i].MultipleContiguous = true
|
||||
}
|
||||
}
|
||||
if num < lastNum {
|
||||
outOfOrder = true
|
||||
}
|
||||
pos = end
|
||||
lastNum = num
|
||||
}
|
||||
if groupTag != 0 {
|
||||
return out, errors.New("missing end group marker")
|
||||
}
|
||||
if lazyFields != nil {
|
||||
// Some fields failed validation, and now need to be unmarshaled.
|
||||
for f, action := range lazyFields {
|
||||
if action != lazyUnmarshalLater {
|
||||
continue
|
||||
}
|
||||
initialized = false
|
||||
if *lazy == nil {
|
||||
*lazy = &protolazy.XXX_lazyUnmarshalInfo{}
|
||||
}
|
||||
if err := mi.unmarshalField((*lazy).Buffer(), p.Apply(f.offset), f, *lazy, opts.flags); err != nil {
|
||||
return out, err
|
||||
}
|
||||
presence.SetPresentUnatomic(f.presenceIndex, mi.presenceSize)
|
||||
}
|
||||
}
|
||||
if lazyDecode {
|
||||
if outOfOrder {
|
||||
sort.Slice(lazyIndex, func(i, j int) bool {
|
||||
return lazyIndex[i].FieldNum < lazyIndex[j].FieldNum ||
|
||||
(lazyIndex[i].FieldNum == lazyIndex[j].FieldNum &&
|
||||
lazyIndex[i].Start < lazyIndex[j].Start)
|
||||
})
|
||||
}
|
||||
if *lazy == nil {
|
||||
*lazy = &protolazy.XXX_lazyUnmarshalInfo{}
|
||||
}
|
||||
|
||||
(*lazy).SetIndex(lazyIndex)
|
||||
}
|
||||
if mi.numRequiredFields > 0 && bits.OnesCount64(requiredMask) != int(mi.numRequiredFields) {
|
||||
initialized = false
|
||||
}
|
||||
if initialized {
|
||||
out.initialized = true
|
||||
}
|
||||
out.n = start - len(b)
|
||||
return out, nil
|
||||
}
|
||||
+27
@@ -41,11 +41,38 @@ func (mi *MessageInfo) mergePointer(dst, src pointer, opts mergeOptions) {
|
||||
if src.IsNil() {
|
||||
return
|
||||
}
|
||||
|
||||
var presenceSrc presence
|
||||
var presenceDst presence
|
||||
if mi.presenceOffset.IsValid() {
|
||||
presenceSrc = src.Apply(mi.presenceOffset).PresenceInfo()
|
||||
presenceDst = dst.Apply(mi.presenceOffset).PresenceInfo()
|
||||
}
|
||||
|
||||
for _, f := range mi.orderedCoderFields {
|
||||
if f.funcs.merge == nil {
|
||||
continue
|
||||
}
|
||||
sfptr := src.Apply(f.offset)
|
||||
|
||||
if f.presenceIndex != noPresence {
|
||||
if !presenceSrc.Present(f.presenceIndex) {
|
||||
continue
|
||||
}
|
||||
dfptr := dst.Apply(f.offset)
|
||||
if f.isLazy {
|
||||
if sfptr.AtomicGetPointer().IsNil() {
|
||||
mi.lazyUnmarshal(src, f.num)
|
||||
}
|
||||
if presenceDst.Present(f.presenceIndex) && dfptr.AtomicGetPointer().IsNil() {
|
||||
mi.lazyUnmarshal(dst, f.num)
|
||||
}
|
||||
}
|
||||
f.funcs.merge(dst.Apply(f.offset), sfptr, f, opts)
|
||||
presenceDst.SetPresentUnatomic(f.presenceIndex, mi.presenceSize)
|
||||
continue
|
||||
}
|
||||
|
||||
if f.isPointer && sfptr.Elem().IsNil() {
|
||||
continue
|
||||
}
|
||||
|
||||
+16
-4
@@ -79,6 +79,9 @@ func (mi *MessageInfo) initOnce() {
|
||||
if mi.initDone == 1 {
|
||||
return
|
||||
}
|
||||
if opaqueInitHook(mi) {
|
||||
return
|
||||
}
|
||||
|
||||
t := mi.GoReflectType
|
||||
if t.Kind() != reflect.Ptr && t.Elem().Kind() != reflect.Struct {
|
||||
@@ -133,6 +136,9 @@ type structInfo struct {
|
||||
extensionOffset offset
|
||||
extensionType reflect.Type
|
||||
|
||||
lazyOffset offset
|
||||
presenceOffset offset
|
||||
|
||||
fieldsByNumber map[protoreflect.FieldNumber]reflect.StructField
|
||||
oneofsByName map[protoreflect.Name]reflect.StructField
|
||||
oneofWrappersByType map[reflect.Type]protoreflect.FieldNumber
|
||||
@@ -145,6 +151,8 @@ func (mi *MessageInfo) makeStructInfo(t reflect.Type) structInfo {
|
||||
weakOffset: invalidOffset,
|
||||
unknownOffset: invalidOffset,
|
||||
extensionOffset: invalidOffset,
|
||||
lazyOffset: invalidOffset,
|
||||
presenceOffset: invalidOffset,
|
||||
|
||||
fieldsByNumber: map[protoreflect.FieldNumber]reflect.StructField{},
|
||||
oneofsByName: map[protoreflect.Name]reflect.StructField{},
|
||||
@@ -157,24 +165,28 @@ fieldLoop:
|
||||
switch f := t.Field(i); f.Name {
|
||||
case genid.SizeCache_goname, genid.SizeCacheA_goname:
|
||||
if f.Type == sizecacheType {
|
||||
si.sizecacheOffset = offsetOf(f, mi.Exporter)
|
||||
si.sizecacheOffset = offsetOf(f)
|
||||
si.sizecacheType = f.Type
|
||||
}
|
||||
case genid.WeakFields_goname, genid.WeakFieldsA_goname:
|
||||
if f.Type == weakFieldsType {
|
||||
si.weakOffset = offsetOf(f, mi.Exporter)
|
||||
si.weakOffset = offsetOf(f)
|
||||
si.weakType = f.Type
|
||||
}
|
||||
case genid.UnknownFields_goname, genid.UnknownFieldsA_goname:
|
||||
if f.Type == unknownFieldsAType || f.Type == unknownFieldsBType {
|
||||
si.unknownOffset = offsetOf(f, mi.Exporter)
|
||||
si.unknownOffset = offsetOf(f)
|
||||
si.unknownType = f.Type
|
||||
}
|
||||
case genid.ExtensionFields_goname, genid.ExtensionFieldsA_goname, genid.ExtensionFieldsB_goname:
|
||||
if f.Type == extensionFieldsType {
|
||||
si.extensionOffset = offsetOf(f, mi.Exporter)
|
||||
si.extensionOffset = offsetOf(f)
|
||||
si.extensionType = f.Type
|
||||
}
|
||||
case "lazyFields", "XXX_lazyUnmarshalInfo":
|
||||
si.lazyOffset = offsetOf(f)
|
||||
case "XXX_presence":
|
||||
si.presenceOffset = offsetOf(f)
|
||||
default:
|
||||
for _, s := range strings.Split(f.Tag.Get("protobuf"), ",") {
|
||||
if len(s) > 0 && strings.Trim(s, "0123456789") == "" {
|
||||
|
||||
+632
@@ -0,0 +1,632 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
type opaqueStructInfo struct {
|
||||
structInfo
|
||||
}
|
||||
|
||||
// isOpaque determines whether a protobuf message type is on the Opaque API. It
|
||||
// checks whether the type is a Go struct that protoc-gen-go would generate.
|
||||
//
|
||||
// This function only detects newly generated messages from the v2
|
||||
// implementation of protoc-gen-go. It is unable to classify generated messages
|
||||
// that are too old or those that are generated by a different generator
|
||||
// such as protoc-gen-gogo.
|
||||
func isOpaque(t reflect.Type) bool {
|
||||
// The current detection mechanism is to simply check the first field
|
||||
// for a struct tag with the "protogen" key.
|
||||
if t.Kind() == reflect.Struct && t.NumField() > 0 {
|
||||
pgt := t.Field(0).Tag.Get("protogen")
|
||||
return strings.HasPrefix(pgt, "opaque.")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func opaqueInitHook(mi *MessageInfo) bool {
|
||||
mt := mi.GoReflectType.Elem()
|
||||
si := opaqueStructInfo{
|
||||
structInfo: mi.makeStructInfo(mt),
|
||||
}
|
||||
|
||||
if !isOpaque(mt) {
|
||||
return false
|
||||
}
|
||||
|
||||
defer atomic.StoreUint32(&mi.initDone, 1)
|
||||
|
||||
mi.fields = map[protoreflect.FieldNumber]*fieldInfo{}
|
||||
fds := mi.Desc.Fields()
|
||||
for i := 0; i < fds.Len(); i++ {
|
||||
fd := fds.Get(i)
|
||||
fs := si.fieldsByNumber[fd.Number()]
|
||||
var fi fieldInfo
|
||||
usePresence, _ := usePresenceForField(si, fd)
|
||||
|
||||
switch {
|
||||
case fd.IsWeak():
|
||||
// Weak fields are no different for opaque.
|
||||
fi = fieldInfoForWeakMessage(fd, si.weakOffset)
|
||||
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
|
||||
// Oneofs are no different for opaque.
|
||||
fi = fieldInfoForOneof(fd, si.oneofsByName[fd.ContainingOneof().Name()], mi.Exporter, si.oneofWrappersByNumber[fd.Number()])
|
||||
case fd.IsMap():
|
||||
fi = mi.fieldInfoForMapOpaque(si, fd, fs)
|
||||
case fd.IsList() && fd.Message() == nil && usePresence:
|
||||
fi = mi.fieldInfoForScalarListOpaque(si, fd, fs)
|
||||
case fd.IsList() && fd.Message() == nil:
|
||||
// Proto3 lists without presence can use same access methods as open
|
||||
fi = fieldInfoForList(fd, fs, mi.Exporter)
|
||||
case fd.IsList() && usePresence:
|
||||
fi = mi.fieldInfoForMessageListOpaque(si, fd, fs)
|
||||
case fd.IsList():
|
||||
// Proto3 opaque messages that does not need presence bitmap.
|
||||
// Different representation than open struct, but same logic
|
||||
fi = mi.fieldInfoForMessageListOpaqueNoPresence(si, fd, fs)
|
||||
case fd.Message() != nil && usePresence:
|
||||
fi = mi.fieldInfoForMessageOpaque(si, fd, fs)
|
||||
case fd.Message() != nil:
|
||||
// Proto3 messages without presence can use same access methods as open
|
||||
fi = fieldInfoForMessage(fd, fs, mi.Exporter)
|
||||
default:
|
||||
fi = mi.fieldInfoForScalarOpaque(si, fd, fs)
|
||||
}
|
||||
mi.fields[fd.Number()] = &fi
|
||||
}
|
||||
mi.oneofs = map[protoreflect.Name]*oneofInfo{}
|
||||
for i := 0; i < mi.Desc.Oneofs().Len(); i++ {
|
||||
od := mi.Desc.Oneofs().Get(i)
|
||||
mi.oneofs[od.Name()] = makeOneofInfoOpaque(mi, od, si.structInfo, mi.Exporter)
|
||||
}
|
||||
|
||||
mi.denseFields = make([]*fieldInfo, fds.Len()*2)
|
||||
for i := 0; i < fds.Len(); i++ {
|
||||
if fd := fds.Get(i); int(fd.Number()) < len(mi.denseFields) {
|
||||
mi.denseFields[fd.Number()] = mi.fields[fd.Number()]
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < fds.Len(); {
|
||||
fd := fds.Get(i)
|
||||
if od := fd.ContainingOneof(); od != nil && !fd.ContainingOneof().IsSynthetic() {
|
||||
mi.rangeInfos = append(mi.rangeInfos, mi.oneofs[od.Name()])
|
||||
i += od.Fields().Len()
|
||||
} else {
|
||||
mi.rangeInfos = append(mi.rangeInfos, mi.fields[fd.Number()])
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
mi.makeExtensionFieldsFunc(mt, si.structInfo)
|
||||
mi.makeUnknownFieldsFunc(mt, si.structInfo)
|
||||
mi.makeOpaqueCoderMethods(mt, si)
|
||||
mi.makeFieldTypes(si.structInfo)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func makeOneofInfoOpaque(mi *MessageInfo, od protoreflect.OneofDescriptor, si structInfo, x exporter) *oneofInfo {
|
||||
oi := &oneofInfo{oneofDesc: od}
|
||||
if od.IsSynthetic() {
|
||||
fd := od.Fields().Get(0)
|
||||
index, _ := presenceIndex(mi.Desc, fd)
|
||||
oi.which = func(p pointer) protoreflect.FieldNumber {
|
||||
if p.IsNil() {
|
||||
return 0
|
||||
}
|
||||
if !mi.present(p, index) {
|
||||
return 0
|
||||
}
|
||||
return od.Fields().Get(0).Number()
|
||||
}
|
||||
return oi
|
||||
}
|
||||
// Dispatch to non-opaque oneof implementation for non-synthetic oneofs.
|
||||
return makeOneofInfo(od, si, x)
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) fieldInfoForMapOpaque(si opaqueStructInfo, fd protoreflect.FieldDescriptor, fs reflect.StructField) fieldInfo {
|
||||
ft := fs.Type
|
||||
if ft.Kind() != reflect.Map {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want map kind", ft))
|
||||
}
|
||||
fieldOffset := offsetOf(fs)
|
||||
conv := NewConverter(ft, fd)
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
// Don't bother checking presence bits, since we need to
|
||||
// look at the map length even if the presence bit is set.
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
return rv.Len() > 0
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
rv.Set(reflect.Zero(rv.Type()))
|
||||
},
|
||||
get: func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if rv.Len() == 0 {
|
||||
return conv.Zero()
|
||||
}
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
set: func(p pointer, v protoreflect.Value) {
|
||||
pv := conv.GoValueOf(v)
|
||||
if pv.IsNil() {
|
||||
panic(fmt.Sprintf("invalid value: setting map field to read-only value"))
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
rv.Set(pv)
|
||||
},
|
||||
mutable: func(p pointer) protoreflect.Value {
|
||||
v := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if v.IsNil() {
|
||||
v.Set(reflect.MakeMap(fs.Type))
|
||||
}
|
||||
return conv.PBValueOf(v)
|
||||
},
|
||||
newField: func() protoreflect.Value {
|
||||
return conv.New()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) fieldInfoForScalarListOpaque(si opaqueStructInfo, fd protoreflect.FieldDescriptor, fs reflect.StructField) fieldInfo {
|
||||
ft := fs.Type
|
||||
if ft.Kind() != reflect.Slice {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want slice kind", ft))
|
||||
}
|
||||
conv := NewConverter(reflect.PtrTo(ft), fd)
|
||||
fieldOffset := offsetOf(fs)
|
||||
index, _ := presenceIndex(mi.Desc, fd)
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
return rv.Len() > 0
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
rv.Set(reflect.Zero(rv.Type()))
|
||||
},
|
||||
get: func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type)
|
||||
if rv.Elem().Len() == 0 {
|
||||
return conv.Zero()
|
||||
}
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
set: func(p pointer, v protoreflect.Value) {
|
||||
pv := conv.GoValueOf(v)
|
||||
if pv.IsNil() {
|
||||
panic(fmt.Sprintf("invalid value: setting repeated field to read-only value"))
|
||||
}
|
||||
mi.setPresent(p, index)
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
rv.Set(pv.Elem())
|
||||
},
|
||||
mutable: func(p pointer) protoreflect.Value {
|
||||
mi.setPresent(p, index)
|
||||
return conv.PBValueOf(p.Apply(fieldOffset).AsValueOf(fs.Type))
|
||||
},
|
||||
newField: func() protoreflect.Value {
|
||||
return conv.New()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) fieldInfoForMessageListOpaque(si opaqueStructInfo, fd protoreflect.FieldDescriptor, fs reflect.StructField) fieldInfo {
|
||||
ft := fs.Type
|
||||
if ft.Kind() != reflect.Ptr || ft.Elem().Kind() != reflect.Slice {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want slice kind", ft))
|
||||
}
|
||||
conv := NewConverter(ft, fd)
|
||||
fieldOffset := offsetOf(fs)
|
||||
index, _ := presenceIndex(mi.Desc, fd)
|
||||
fieldNumber := fd.Number()
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
if !mi.present(p, index) {
|
||||
return false
|
||||
}
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
// Lazily unmarshal this field.
|
||||
mi.lazyUnmarshal(p, fieldNumber)
|
||||
sp = p.Apply(fieldOffset).AtomicGetPointer()
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
return rv.Elem().Len() > 0
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
fp := p.Apply(fieldOffset)
|
||||
sp := fp.AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
sp = fp.AtomicSetPointerIfNil(pointerOfValue(reflect.New(fs.Type.Elem())))
|
||||
mi.setPresent(p, index)
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
rv.Elem().Set(reflect.Zero(rv.Type().Elem()))
|
||||
},
|
||||
get: func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
if !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
// Lazily unmarshal this field.
|
||||
mi.lazyUnmarshal(p, fieldNumber)
|
||||
sp = p.Apply(fieldOffset).AtomicGetPointer()
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
if rv.Elem().Len() == 0 {
|
||||
return conv.Zero()
|
||||
}
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
set: func(p pointer, v protoreflect.Value) {
|
||||
fp := p.Apply(fieldOffset)
|
||||
sp := fp.AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
sp = fp.AtomicSetPointerIfNil(pointerOfValue(reflect.New(fs.Type.Elem())))
|
||||
mi.setPresent(p, index)
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
val := conv.GoValueOf(v)
|
||||
if val.IsNil() {
|
||||
panic(fmt.Sprintf("invalid value: setting repeated field to read-only value"))
|
||||
} else {
|
||||
rv.Elem().Set(val.Elem())
|
||||
}
|
||||
},
|
||||
mutable: func(p pointer) protoreflect.Value {
|
||||
fp := p.Apply(fieldOffset)
|
||||
sp := fp.AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
if mi.present(p, index) {
|
||||
// Lazily unmarshal this field.
|
||||
mi.lazyUnmarshal(p, fieldNumber)
|
||||
sp = p.Apply(fieldOffset).AtomicGetPointer()
|
||||
} else {
|
||||
sp = fp.AtomicSetPointerIfNil(pointerOfValue(reflect.New(fs.Type.Elem())))
|
||||
mi.setPresent(p, index)
|
||||
}
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
newField: func() protoreflect.Value {
|
||||
return conv.New()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) fieldInfoForMessageListOpaqueNoPresence(si opaqueStructInfo, fd protoreflect.FieldDescriptor, fs reflect.StructField) fieldInfo {
|
||||
ft := fs.Type
|
||||
if ft.Kind() != reflect.Ptr || ft.Elem().Kind() != reflect.Slice {
|
||||
panic(fmt.Sprintf("invalid type: got %v, want slice kind", ft))
|
||||
}
|
||||
conv := NewConverter(ft, fd)
|
||||
fieldOffset := offsetOf(fs)
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
return false
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
return rv.Elem().Len() > 0
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if !sp.IsNil() {
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
rv.Elem().Set(reflect.Zero(rv.Type().Elem()))
|
||||
}
|
||||
},
|
||||
get: func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
sp := p.Apply(fieldOffset).AtomicGetPointer()
|
||||
if sp.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := sp.AsValueOf(fs.Type.Elem())
|
||||
if rv.Elem().Len() == 0 {
|
||||
return conv.Zero()
|
||||
}
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
set: func(p pointer, v protoreflect.Value) {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if rv.IsNil() {
|
||||
rv.Set(reflect.New(fs.Type.Elem()))
|
||||
}
|
||||
val := conv.GoValueOf(v)
|
||||
if val.IsNil() {
|
||||
panic(fmt.Sprintf("invalid value: setting repeated field to read-only value"))
|
||||
} else {
|
||||
rv.Elem().Set(val.Elem())
|
||||
}
|
||||
},
|
||||
mutable: func(p pointer) protoreflect.Value {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if rv.IsNil() {
|
||||
rv.Set(reflect.New(fs.Type.Elem()))
|
||||
}
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
newField: func() protoreflect.Value {
|
||||
return conv.New()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) fieldInfoForScalarOpaque(si opaqueStructInfo, fd protoreflect.FieldDescriptor, fs reflect.StructField) fieldInfo {
|
||||
ft := fs.Type
|
||||
nullable := fd.HasPresence()
|
||||
if oneof := fd.ContainingOneof(); oneof != nil && oneof.IsSynthetic() {
|
||||
nullable = true
|
||||
}
|
||||
deref := false
|
||||
if nullable && ft.Kind() == reflect.Ptr {
|
||||
ft = ft.Elem()
|
||||
deref = true
|
||||
}
|
||||
conv := NewConverter(ft, fd)
|
||||
fieldOffset := offsetOf(fs)
|
||||
index, _ := presenceIndex(mi.Desc, fd)
|
||||
var getter func(p pointer) protoreflect.Value
|
||||
if !nullable {
|
||||
getter = getterForDirectScalar(fd, fs, conv, fieldOffset)
|
||||
} else {
|
||||
getter = getterForOpaqueNullableScalar(mi, index, fd, fs, conv, fieldOffset)
|
||||
}
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
if nullable {
|
||||
return mi.present(p, index)
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
switch rv.Kind() {
|
||||
case reflect.Bool:
|
||||
return rv.Bool()
|
||||
case reflect.Int32, reflect.Int64:
|
||||
return rv.Int() != 0
|
||||
case reflect.Uint32, reflect.Uint64:
|
||||
return rv.Uint() != 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return rv.Float() != 0 || math.Signbit(rv.Float())
|
||||
case reflect.String, reflect.Slice:
|
||||
return rv.Len() > 0
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid type: %v", rv.Type())) // should never happen
|
||||
}
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
if nullable {
|
||||
mi.clearPresent(p, index)
|
||||
}
|
||||
// This is only valuable for bytes and strings, but we do it unconditionally.
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
rv.Set(reflect.Zero(rv.Type()))
|
||||
},
|
||||
get: getter,
|
||||
// TODO: Implement unsafe fast path for set?
|
||||
set: func(p pointer, v protoreflect.Value) {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if deref {
|
||||
if rv.IsNil() {
|
||||
rv.Set(reflect.New(ft))
|
||||
}
|
||||
rv = rv.Elem()
|
||||
}
|
||||
|
||||
rv.Set(conv.GoValueOf(v))
|
||||
if nullable && rv.Kind() == reflect.Slice && rv.IsNil() {
|
||||
rv.Set(emptyBytes)
|
||||
}
|
||||
if nullable {
|
||||
mi.setPresent(p, index)
|
||||
}
|
||||
},
|
||||
newField: func() protoreflect.Value {
|
||||
return conv.New()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) fieldInfoForMessageOpaque(si opaqueStructInfo, fd protoreflect.FieldDescriptor, fs reflect.StructField) fieldInfo {
|
||||
ft := fs.Type
|
||||
conv := NewConverter(ft, fd)
|
||||
fieldOffset := offsetOf(fs)
|
||||
index, _ := presenceIndex(mi.Desc, fd)
|
||||
fieldNumber := fd.Number()
|
||||
elemType := fs.Type.Elem()
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
return mi.present(p, index)
|
||||
},
|
||||
clear: func(p pointer) {
|
||||
mi.clearPresent(p, index)
|
||||
p.Apply(fieldOffset).AtomicSetNilPointer()
|
||||
},
|
||||
get: func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
fp := p.Apply(fieldOffset)
|
||||
mp := fp.AtomicGetPointer()
|
||||
if mp.IsNil() {
|
||||
// Lazily unmarshal this field.
|
||||
mi.lazyUnmarshal(p, fieldNumber)
|
||||
mp = fp.AtomicGetPointer()
|
||||
}
|
||||
rv := mp.AsValueOf(elemType)
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
set: func(p pointer, v protoreflect.Value) {
|
||||
val := pointerOfValue(conv.GoValueOf(v))
|
||||
if val.IsNil() {
|
||||
panic("invalid nil pointer")
|
||||
}
|
||||
p.Apply(fieldOffset).AtomicSetPointer(val)
|
||||
mi.setPresent(p, index)
|
||||
},
|
||||
mutable: func(p pointer) protoreflect.Value {
|
||||
fp := p.Apply(fieldOffset)
|
||||
mp := fp.AtomicGetPointer()
|
||||
if mp.IsNil() {
|
||||
if mi.present(p, index) {
|
||||
// Lazily unmarshal this field.
|
||||
mi.lazyUnmarshal(p, fieldNumber)
|
||||
mp = fp.AtomicGetPointer()
|
||||
} else {
|
||||
mp = pointerOfValue(conv.GoValueOf(conv.New()))
|
||||
fp.AtomicSetPointer(mp)
|
||||
mi.setPresent(p, index)
|
||||
}
|
||||
}
|
||||
return conv.PBValueOf(mp.AsValueOf(fs.Type.Elem()))
|
||||
},
|
||||
newMessage: func() protoreflect.Message {
|
||||
return conv.New().Message()
|
||||
},
|
||||
newField: func() protoreflect.Value {
|
||||
return conv.New()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// A presenceList wraps a List, updating presence bits as necessary when the
|
||||
// list contents change.
|
||||
type presenceList struct {
|
||||
pvalueList
|
||||
setPresence func(bool)
|
||||
}
|
||||
type pvalueList interface {
|
||||
protoreflect.List
|
||||
//Unwrapper
|
||||
}
|
||||
|
||||
func (list presenceList) Append(v protoreflect.Value) {
|
||||
list.pvalueList.Append(v)
|
||||
list.setPresence(true)
|
||||
}
|
||||
func (list presenceList) Truncate(i int) {
|
||||
list.pvalueList.Truncate(i)
|
||||
list.setPresence(i > 0)
|
||||
}
|
||||
|
||||
// presenceIndex returns the index to pass to presence functions.
|
||||
//
|
||||
// TODO: field.Desc.Index() would be simpler, and would give space to record the presence of oneof fields.
|
||||
func presenceIndex(md protoreflect.MessageDescriptor, fd protoreflect.FieldDescriptor) (uint32, presenceSize) {
|
||||
found := false
|
||||
var index, numIndices uint32
|
||||
for i := 0; i < md.Fields().Len(); i++ {
|
||||
f := md.Fields().Get(i)
|
||||
if f == fd {
|
||||
found = true
|
||||
index = numIndices
|
||||
}
|
||||
if f.ContainingOneof() == nil || isLastOneofField(f) {
|
||||
numIndices++
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
panic(fmt.Sprintf("BUG: %v not in %v", fd.Name(), md.FullName()))
|
||||
}
|
||||
return index, presenceSize(numIndices)
|
||||
}
|
||||
|
||||
func isLastOneofField(fd protoreflect.FieldDescriptor) bool {
|
||||
fields := fd.ContainingOneof().Fields()
|
||||
return fields.Get(fields.Len()-1) == fd
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) setPresent(p pointer, index uint32) {
|
||||
p.Apply(mi.presenceOffset).PresenceInfo().SetPresent(index, mi.presenceSize)
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) clearPresent(p pointer, index uint32) {
|
||||
p.Apply(mi.presenceOffset).PresenceInfo().ClearPresent(index)
|
||||
}
|
||||
|
||||
func (mi *MessageInfo) present(p pointer, index uint32) bool {
|
||||
return p.Apply(mi.presenceOffset).PresenceInfo().Present(index)
|
||||
}
|
||||
|
||||
// usePresenceForField implements the somewhat intricate logic of when
|
||||
// the presence bitmap is used for a field. The main logic is that a
|
||||
// field that is optional or that can be lazy will use the presence
|
||||
// bit, but for proto2, also maps have a presence bit. It also records
|
||||
// if the field can ever be lazy, which is true if we have a
|
||||
// lazyOffset and the field is a message or a slice of messages. A
|
||||
// field that is lazy will always need a presence bit. Oneofs are not
|
||||
// lazy and do not use presence, unless they are a synthetic oneof,
|
||||
// which is a proto3 optional field. For proto3 optionals, we use the
|
||||
// presence and they can also be lazy when applicable (a message).
|
||||
func usePresenceForField(si opaqueStructInfo, fd protoreflect.FieldDescriptor) (usePresence, canBeLazy bool) {
|
||||
hasLazyField := fd.(interface{ IsLazy() bool }).IsLazy()
|
||||
|
||||
// Non-oneof scalar fields with explicit field presence use the presence array.
|
||||
usesPresenceArray := fd.HasPresence() && fd.Message() == nil && (fd.ContainingOneof() == nil || fd.ContainingOneof().IsSynthetic())
|
||||
switch {
|
||||
case fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic():
|
||||
return false, false
|
||||
case fd.IsWeak():
|
||||
return false, false
|
||||
case fd.IsMap():
|
||||
return false, false
|
||||
case fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind:
|
||||
return hasLazyField, hasLazyField
|
||||
default:
|
||||
return usesPresenceArray || (hasLazyField && fd.HasPresence()), false
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Code generated by generate-types. DO NOT EDIT.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
func getterForOpaqueNullableScalar(mi *MessageInfo, index uint32, fd protoreflect.FieldDescriptor, fs reflect.StructField, conv Converter, fieldOffset offset) func(p pointer) protoreflect.Value {
|
||||
ft := fs.Type
|
||||
if ft.Kind() == reflect.Ptr {
|
||||
ft = ft.Elem()
|
||||
}
|
||||
if fd.Kind() == protoreflect.EnumKind {
|
||||
// Enums for nullable opaque types.
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
return conv.PBValueOf(rv)
|
||||
}
|
||||
}
|
||||
switch ft.Kind() {
|
||||
case reflect.Bool:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bool()
|
||||
return protoreflect.ValueOfBool(*x)
|
||||
}
|
||||
case reflect.Int32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Int32()
|
||||
return protoreflect.ValueOfInt32(*x)
|
||||
}
|
||||
case reflect.Uint32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Uint32()
|
||||
return protoreflect.ValueOfUint32(*x)
|
||||
}
|
||||
case reflect.Int64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Int64()
|
||||
return protoreflect.ValueOfInt64(*x)
|
||||
}
|
||||
case reflect.Uint64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Uint64()
|
||||
return protoreflect.ValueOfUint64(*x)
|
||||
}
|
||||
case reflect.Float32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Float32()
|
||||
return protoreflect.ValueOfFloat32(*x)
|
||||
}
|
||||
case reflect.Float64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Float64()
|
||||
return protoreflect.ValueOfFloat64(*x)
|
||||
}
|
||||
case reflect.String:
|
||||
if fd.Kind() == protoreflect.BytesKind {
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).StringPtr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
if len(**x) == 0 {
|
||||
return protoreflect.ValueOfBytes(nil)
|
||||
}
|
||||
return protoreflect.ValueOfBytes([]byte(**x))
|
||||
}
|
||||
}
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).StringPtr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfString(**x)
|
||||
}
|
||||
case reflect.Slice:
|
||||
if fd.Kind() == protoreflect.StringKind {
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bytes()
|
||||
return protoreflect.ValueOfString(string(*x))
|
||||
}
|
||||
}
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() || !mi.present(p, index) {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bytes()
|
||||
return protoreflect.ValueOfBytes(*x)
|
||||
}
|
||||
}
|
||||
panic("unexpected protobuf kind: " + ft.Kind().String())
|
||||
}
|
||||
+5
@@ -205,6 +205,11 @@ func (mi *MessageInfo) makeFieldTypes(si structInfo) {
|
||||
case fd.IsList():
|
||||
if fd.Enum() != nil || fd.Message() != nil {
|
||||
ft = fs.Type.Elem()
|
||||
|
||||
if ft.Kind() == reflect.Slice {
|
||||
ft = ft.Elem()
|
||||
}
|
||||
|
||||
}
|
||||
isMessage = fd.Message() != nil
|
||||
case fd.Enum() != nil:
|
||||
|
||||
+21
-65
@@ -76,7 +76,7 @@ func fieldInfoForOneof(fd protoreflect.FieldDescriptor, fs reflect.StructField,
|
||||
isMessage := fd.Message() != nil
|
||||
|
||||
// TODO: Implement unsafe fast path?
|
||||
fieldOffset := offsetOf(fs, x)
|
||||
fieldOffset := offsetOf(fs)
|
||||
return fieldInfo{
|
||||
// NOTE: The logic below intentionally assumes that oneof fields are
|
||||
// well-formatted. That is, the oneof interface never contains a
|
||||
@@ -152,7 +152,7 @@ func fieldInfoForMap(fd protoreflect.FieldDescriptor, fs reflect.StructField, x
|
||||
conv := NewConverter(ft, fd)
|
||||
|
||||
// TODO: Implement unsafe fast path?
|
||||
fieldOffset := offsetOf(fs, x)
|
||||
fieldOffset := offsetOf(fs)
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
@@ -205,7 +205,7 @@ func fieldInfoForList(fd protoreflect.FieldDescriptor, fs reflect.StructField, x
|
||||
conv := NewConverter(reflect.PtrTo(ft), fd)
|
||||
|
||||
// TODO: Implement unsafe fast path?
|
||||
fieldOffset := offsetOf(fs, x)
|
||||
fieldOffset := offsetOf(fs)
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
@@ -256,6 +256,7 @@ func fieldInfoForScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField,
|
||||
ft := fs.Type
|
||||
nullable := fd.HasPresence()
|
||||
isBytes := ft.Kind() == reflect.Slice && ft.Elem().Kind() == reflect.Uint8
|
||||
var getter func(p pointer) protoreflect.Value
|
||||
if nullable {
|
||||
if ft.Kind() != reflect.Ptr && ft.Kind() != reflect.Slice {
|
||||
// This never occurs for generated message types.
|
||||
@@ -268,19 +269,25 @@ func fieldInfoForScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField,
|
||||
}
|
||||
}
|
||||
conv := NewConverter(ft, fd)
|
||||
fieldOffset := offsetOf(fs)
|
||||
|
||||
// Generate specialized getter functions to avoid going through reflect.Value
|
||||
if nullable {
|
||||
getter = getterForNullableScalar(fd, fs, conv, fieldOffset)
|
||||
} else {
|
||||
getter = getterForDirectScalar(fd, fs, conv, fieldOffset)
|
||||
}
|
||||
|
||||
// TODO: Implement unsafe fast path?
|
||||
fieldOffset := offsetOf(fs, x)
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
if p.IsNil() {
|
||||
return false
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if nullable {
|
||||
return !rv.IsNil()
|
||||
return !p.Apply(fieldOffset).Elem().IsNil()
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
switch rv.Kind() {
|
||||
case reflect.Bool:
|
||||
return rv.Bool()
|
||||
@@ -300,21 +307,8 @@ func fieldInfoForScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField,
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
rv.Set(reflect.Zero(rv.Type()))
|
||||
},
|
||||
get: func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if nullable {
|
||||
if rv.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
if rv.Kind() == reflect.Ptr {
|
||||
rv = rv.Elem()
|
||||
}
|
||||
}
|
||||
return conv.PBValueOf(rv)
|
||||
},
|
||||
get: getter,
|
||||
// TODO: Implement unsafe fast path for set?
|
||||
set: func(p pointer, v protoreflect.Value) {
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if nullable && rv.Kind() == reflect.Ptr {
|
||||
@@ -339,7 +333,7 @@ func fieldInfoForScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField,
|
||||
}
|
||||
|
||||
func fieldInfoForWeakMessage(fd protoreflect.FieldDescriptor, weakOffset offset) fieldInfo {
|
||||
if !flags.ProtoLegacy {
|
||||
if !flags.ProtoLegacyWeak {
|
||||
panic("no support for proto1 weak fields")
|
||||
}
|
||||
|
||||
@@ -416,7 +410,7 @@ func fieldInfoForMessage(fd protoreflect.FieldDescriptor, fs reflect.StructField
|
||||
conv := NewConverter(ft, fd)
|
||||
|
||||
// TODO: Implement unsafe fast path?
|
||||
fieldOffset := offsetOf(fs, x)
|
||||
fieldOffset := offsetOf(fs)
|
||||
return fieldInfo{
|
||||
fieldDesc: fd,
|
||||
has: func(p pointer) bool {
|
||||
@@ -425,7 +419,7 @@ func fieldInfoForMessage(fd protoreflect.FieldDescriptor, fs reflect.StructField
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
if fs.Type.Kind() != reflect.Ptr {
|
||||
return !isZero(rv)
|
||||
return !rv.IsZero()
|
||||
}
|
||||
return !rv.IsNil()
|
||||
},
|
||||
@@ -472,7 +466,7 @@ func makeOneofInfo(od protoreflect.OneofDescriptor, si structInfo, x exporter) *
|
||||
oi := &oneofInfo{oneofDesc: od}
|
||||
if od.IsSynthetic() {
|
||||
fs := si.fieldsByNumber[od.Fields().Get(0).Number()]
|
||||
fieldOffset := offsetOf(fs, x)
|
||||
fieldOffset := offsetOf(fs)
|
||||
oi.which = func(p pointer) protoreflect.FieldNumber {
|
||||
if p.IsNil() {
|
||||
return 0
|
||||
@@ -485,7 +479,7 @@ func makeOneofInfo(od protoreflect.OneofDescriptor, si structInfo, x exporter) *
|
||||
}
|
||||
} else {
|
||||
fs := si.oneofsByName[od.Name()]
|
||||
fieldOffset := offsetOf(fs, x)
|
||||
fieldOffset := offsetOf(fs)
|
||||
oi.which = func(p pointer) protoreflect.FieldNumber {
|
||||
if p.IsNil() {
|
||||
return 0
|
||||
@@ -503,41 +497,3 @@ func makeOneofInfo(od protoreflect.OneofDescriptor, si structInfo, x exporter) *
|
||||
}
|
||||
return oi
|
||||
}
|
||||
|
||||
// isZero is identical to reflect.Value.IsZero.
|
||||
// TODO: Remove this when Go1.13 is the minimally supported Go version.
|
||||
func isZero(v reflect.Value) bool {
|
||||
switch v.Kind() {
|
||||
case reflect.Bool:
|
||||
return !v.Bool()
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return v.Int() == 0
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return v.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return math.Float64bits(v.Float()) == 0
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
c := v.Complex()
|
||||
return math.Float64bits(real(c)) == 0 && math.Float64bits(imag(c)) == 0
|
||||
case reflect.Array:
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
if !isZero(v.Index(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice, reflect.UnsafePointer:
|
||||
return v.IsNil()
|
||||
case reflect.String:
|
||||
return v.Len() == 0
|
||||
case reflect.Struct:
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
if !isZero(v.Field(i)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
default:
|
||||
panic(&reflect.ValueError{Method: "reflect.Value.IsZero", Kind: v.Kind()})
|
||||
}
|
||||
}
|
||||
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Code generated by generate-types. DO NOT EDIT.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
func getterForNullableScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField, conv Converter, fieldOffset offset) func(p pointer) protoreflect.Value {
|
||||
ft := fs.Type
|
||||
if ft.Kind() == reflect.Ptr {
|
||||
ft = ft.Elem()
|
||||
}
|
||||
if fd.Kind() == protoreflect.EnumKind {
|
||||
elemType := fs.Type.Elem()
|
||||
// Enums for nullable types.
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := p.Apply(fieldOffset).Elem().AsValueOf(elemType)
|
||||
if rv.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
return conv.PBValueOf(rv.Elem())
|
||||
}
|
||||
}
|
||||
switch ft.Kind() {
|
||||
case reflect.Bool:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).BoolPtr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfBool(**x)
|
||||
}
|
||||
case reflect.Int32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Int32Ptr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfInt32(**x)
|
||||
}
|
||||
case reflect.Uint32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Uint32Ptr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfUint32(**x)
|
||||
}
|
||||
case reflect.Int64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Int64Ptr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfInt64(**x)
|
||||
}
|
||||
case reflect.Uint64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Uint64Ptr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfUint64(**x)
|
||||
}
|
||||
case reflect.Float32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Float32Ptr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfFloat32(**x)
|
||||
}
|
||||
case reflect.Float64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Float64Ptr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfFloat64(**x)
|
||||
}
|
||||
case reflect.String:
|
||||
if fd.Kind() == protoreflect.BytesKind {
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).StringPtr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
if len(**x) == 0 {
|
||||
return protoreflect.ValueOfBytes(nil)
|
||||
}
|
||||
return protoreflect.ValueOfBytes([]byte(**x))
|
||||
}
|
||||
}
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).StringPtr()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfString(**x)
|
||||
}
|
||||
case reflect.Slice:
|
||||
if fd.Kind() == protoreflect.StringKind {
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bytes()
|
||||
if len(*x) == 0 {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfString(string(*x))
|
||||
}
|
||||
}
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bytes()
|
||||
if *x == nil {
|
||||
return conv.Zero()
|
||||
}
|
||||
return protoreflect.ValueOfBytes(*x)
|
||||
}
|
||||
}
|
||||
panic("unexpected protobuf kind: " + ft.Kind().String())
|
||||
}
|
||||
|
||||
func getterForDirectScalar(fd protoreflect.FieldDescriptor, fs reflect.StructField, conv Converter, fieldOffset offset) func(p pointer) protoreflect.Value {
|
||||
ft := fs.Type
|
||||
if fd.Kind() == protoreflect.EnumKind {
|
||||
// Enums for non nullable types.
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
rv := p.Apply(fieldOffset).AsValueOf(fs.Type).Elem()
|
||||
return conv.PBValueOf(rv)
|
||||
}
|
||||
}
|
||||
switch ft.Kind() {
|
||||
case reflect.Bool:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bool()
|
||||
return protoreflect.ValueOfBool(*x)
|
||||
}
|
||||
case reflect.Int32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Int32()
|
||||
return protoreflect.ValueOfInt32(*x)
|
||||
}
|
||||
case reflect.Uint32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Uint32()
|
||||
return protoreflect.ValueOfUint32(*x)
|
||||
}
|
||||
case reflect.Int64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Int64()
|
||||
return protoreflect.ValueOfInt64(*x)
|
||||
}
|
||||
case reflect.Uint64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Uint64()
|
||||
return protoreflect.ValueOfUint64(*x)
|
||||
}
|
||||
case reflect.Float32:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Float32()
|
||||
return protoreflect.ValueOfFloat32(*x)
|
||||
}
|
||||
case reflect.Float64:
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Float64()
|
||||
return protoreflect.ValueOfFloat64(*x)
|
||||
}
|
||||
case reflect.String:
|
||||
if fd.Kind() == protoreflect.BytesKind {
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).String()
|
||||
if len(*x) == 0 {
|
||||
return protoreflect.ValueOfBytes(nil)
|
||||
}
|
||||
return protoreflect.ValueOfBytes([]byte(*x))
|
||||
}
|
||||
}
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).String()
|
||||
return protoreflect.ValueOfString(*x)
|
||||
}
|
||||
case reflect.Slice:
|
||||
if fd.Kind() == protoreflect.StringKind {
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bytes()
|
||||
return protoreflect.ValueOfString(string(*x))
|
||||
}
|
||||
}
|
||||
return func(p pointer) protoreflect.Value {
|
||||
if p.IsNil() {
|
||||
return conv.Zero()
|
||||
}
|
||||
x := p.Apply(fieldOffset).Bytes()
|
||||
return protoreflect.ValueOfBytes(*x)
|
||||
}
|
||||
}
|
||||
panic("unexpected protobuf kind: " + ft.Kind().String())
|
||||
}
|
||||
+10
-1
@@ -8,6 +8,8 @@ import (
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"google.golang.org/protobuf/internal/protolazy"
|
||||
)
|
||||
|
||||
const UnsafeEnabled = true
|
||||
@@ -20,7 +22,7 @@ type Pointer unsafe.Pointer
|
||||
type offset uintptr
|
||||
|
||||
// offsetOf returns a field offset for the struct field.
|
||||
func offsetOf(f reflect.StructField, x exporter) offset {
|
||||
func offsetOf(f reflect.StructField) offset {
|
||||
return offset(f.Offset)
|
||||
}
|
||||
|
||||
@@ -111,6 +113,13 @@ func (p pointer) BytesPtr() **[]byte { return (**[]byte)(p.p)
|
||||
func (p pointer) BytesSlice() *[][]byte { return (*[][]byte)(p.p) }
|
||||
func (p pointer) WeakFields() *weakFields { return (*weakFields)(p.p) }
|
||||
func (p pointer) Extensions() *map[int32]ExtensionField { return (*map[int32]ExtensionField)(p.p) }
|
||||
func (p pointer) LazyInfoPtr() **protolazy.XXX_lazyUnmarshalInfo {
|
||||
return (**protolazy.XXX_lazyUnmarshalInfo)(p.p)
|
||||
}
|
||||
|
||||
func (p pointer) PresenceInfo() presence {
|
||||
return presence{P: p.p}
|
||||
}
|
||||
|
||||
func (p pointer) Elem() pointer {
|
||||
return pointer{p: *(*unsafe.Pointer)(p.p)}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (p pointer) AtomicGetPointer() pointer {
|
||||
return pointer{p: atomic.LoadPointer((*unsafe.Pointer)(p.p))}
|
||||
}
|
||||
|
||||
func (p pointer) AtomicSetPointer(v pointer) {
|
||||
atomic.StorePointer((*unsafe.Pointer)(p.p), v.p)
|
||||
}
|
||||
|
||||
func (p pointer) AtomicSetNilPointer() {
|
||||
atomic.StorePointer((*unsafe.Pointer)(p.p), unsafe.Pointer(nil))
|
||||
}
|
||||
|
||||
func (p pointer) AtomicSetPointerIfNil(v pointer) pointer {
|
||||
if atomic.CompareAndSwapPointer((*unsafe.Pointer)(p.p), unsafe.Pointer(nil), v.p) {
|
||||
return v
|
||||
}
|
||||
return pointer{p: atomic.LoadPointer((*unsafe.Pointer)(p.p))}
|
||||
}
|
||||
|
||||
type atomicV1MessageInfo struct{ p Pointer }
|
||||
|
||||
func (mi *atomicV1MessageInfo) Get() Pointer {
|
||||
return Pointer(atomic.LoadPointer((*unsafe.Pointer)(&mi.p)))
|
||||
}
|
||||
|
||||
func (mi *atomicV1MessageInfo) SetIfNil(p Pointer) Pointer {
|
||||
if atomic.CompareAndSwapPointer((*unsafe.Pointer)(&mi.p), nil, unsafe.Pointer(p)) {
|
||||
return p
|
||||
}
|
||||
return mi.Get()
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package impl
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// presenceSize represents the size of a presence set, which should be the largest index of the set+1
|
||||
type presenceSize uint32
|
||||
|
||||
// presence is the internal representation of the bitmap array in a generated protobuf
|
||||
type presence struct {
|
||||
// This is a pointer to the beginning of an array of uint32
|
||||
P unsafe.Pointer
|
||||
}
|
||||
|
||||
func (p presence) toElem(num uint32) (ret *uint32) {
|
||||
const (
|
||||
bitsPerByte = 8
|
||||
siz = unsafe.Sizeof(*ret)
|
||||
)
|
||||
// p.P points to an array of uint32, num is the bit in this array that the
|
||||
// caller wants to check/manipulate. Calculate the index in the array that
|
||||
// contains this specific bit. E.g.: 76 / 32 = 2 (integer division).
|
||||
offset := uintptr(num) / (siz * bitsPerByte) * siz
|
||||
return (*uint32)(unsafe.Pointer(uintptr(p.P) + offset))
|
||||
}
|
||||
|
||||
// Present checks for the presence of a specific field number in a presence set.
|
||||
func (p presence) Present(num uint32) bool {
|
||||
if p.P == nil {
|
||||
return false
|
||||
}
|
||||
return Export{}.Present(p.toElem(num), num)
|
||||
}
|
||||
|
||||
// SetPresent adds presence for a specific field number in a presence set.
|
||||
func (p presence) SetPresent(num uint32, size presenceSize) {
|
||||
Export{}.SetPresent(p.toElem(num), num, uint32(size))
|
||||
}
|
||||
|
||||
// SetPresentUnatomic adds presence for a specific field number in a presence set without using
|
||||
// atomic operations. Only to be called during unmarshaling.
|
||||
func (p presence) SetPresentUnatomic(num uint32, size presenceSize) {
|
||||
Export{}.SetPresentNonAtomic(p.toElem(num), num, uint32(size))
|
||||
}
|
||||
|
||||
// ClearPresent removes presence for a specific field number in a presence set.
|
||||
func (p presence) ClearPresent(num uint32) {
|
||||
Export{}.ClearPresent(p.toElem(num), num)
|
||||
}
|
||||
|
||||
// LoadPresenceCache (together with PresentInCache) allows for a
|
||||
// cached version of checking for presence without re-reading the word
|
||||
// for every field. It is optimized for efficiency and assumes no
|
||||
// simltaneous mutation of the presence set (or at least does not have
|
||||
// a problem with simultaneous mutation giving inconsistent results).
|
||||
func (p presence) LoadPresenceCache() (current uint32) {
|
||||
if p.P == nil {
|
||||
return 0
|
||||
}
|
||||
return atomic.LoadUint32((*uint32)(p.P))
|
||||
}
|
||||
|
||||
// PresentInCache reads presence from a cached word in the presence
|
||||
// bitmap. It caches up a new word if the bit is outside the
|
||||
// word. This is for really fast iteration through bitmaps in cases
|
||||
// where we either know that the bitmap will not be altered, or we
|
||||
// don't care about inconsistencies caused by simultaneous writes.
|
||||
func (p presence) PresentInCache(num uint32, cachedElement *uint32, current *uint32) bool {
|
||||
if num/32 != *cachedElement {
|
||||
o := uintptr(num/32) * unsafe.Sizeof(uint32(0))
|
||||
q := (*uint32)(unsafe.Pointer(uintptr(p.P) + o))
|
||||
*current = atomic.LoadUint32(q)
|
||||
*cachedElement = num / 32
|
||||
}
|
||||
return (*current & (1 << (num % 32))) > 0
|
||||
}
|
||||
|
||||
// AnyPresent checks if any field is marked as present in the bitmap.
|
||||
func (p presence) AnyPresent(size presenceSize) bool {
|
||||
n := uintptr((size + 31) / 32)
|
||||
for j := uintptr(0); j < n; j++ {
|
||||
o := j * unsafe.Sizeof(uint32(0))
|
||||
q := (*uint32)(unsafe.Pointer(uintptr(p.P) + o))
|
||||
b := atomic.LoadUint32(q)
|
||||
if b > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// toRaceDetectData finds the preceding RaceDetectHookData in a
|
||||
// message by using pointer arithmetic. As the type of the presence
|
||||
// set (bitmap) varies with the number of fields in the protobuf, we
|
||||
// can not have a struct type containing the array and the
|
||||
// RaceDetectHookData. instead the RaceDetectHookData is placed
|
||||
// immediately before the bitmap array, and we find it by walking
|
||||
// backwards in the struct.
|
||||
//
|
||||
// This method is only called from the race-detect version of the code,
|
||||
// so RaceDetectHookData is never an empty struct.
|
||||
func (p presence) toRaceDetectData() *RaceDetectHookData {
|
||||
var template struct {
|
||||
d RaceDetectHookData
|
||||
a [1]uint32
|
||||
}
|
||||
o := (uintptr(unsafe.Pointer(&template.a)) - uintptr(unsafe.Pointer(&template.d)))
|
||||
return (*RaceDetectHookData)(unsafe.Pointer(uintptr(p.P) - o))
|
||||
}
|
||||
|
||||
func atomicLoadShadowPresence(p **[]byte) *[]byte {
|
||||
return (*[]byte)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||
}
|
||||
func atomicStoreShadowPresence(p **[]byte, v *[]byte) {
|
||||
atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(p)), nil, unsafe.Pointer(v))
|
||||
}
|
||||
|
||||
// findPointerToRaceDetectData finds the preceding RaceDetectHookData
|
||||
// in a message by using pointer arithmetic. For the methods called
|
||||
// directy from generated code, we don't have a pointer to the
|
||||
// beginning of the presence set, but a pointer inside the array. As
|
||||
// we know the index of the bit we're manipulating (num), we can
|
||||
// calculate which element of the array ptr is pointing to. With that
|
||||
// information we find the preceding RaceDetectHookData and can
|
||||
// manipulate the shadow bitmap.
|
||||
//
|
||||
// This method is only called from the race-detect version of the
|
||||
// code, so RaceDetectHookData is never an empty struct.
|
||||
func findPointerToRaceDetectData(ptr *uint32, num uint32) *RaceDetectHookData {
|
||||
var template struct {
|
||||
d RaceDetectHookData
|
||||
a [1]uint32
|
||||
}
|
||||
o := (uintptr(unsafe.Pointer(&template.a)) - uintptr(unsafe.Pointer(&template.d))) + uintptr(num/32)*unsafe.Sizeof(uint32(0))
|
||||
return (*RaceDetectHookData)(unsafe.Pointer(uintptr(unsafe.Pointer(ptr)) - o))
|
||||
}
|
||||
+16
@@ -37,6 +37,10 @@ const (
|
||||
|
||||
// ValidationValid indicates that unmarshaling the message will succeed.
|
||||
ValidationValid
|
||||
|
||||
// ValidationWrongWireType indicates that a validated field does not have
|
||||
// the expected wire type.
|
||||
ValidationWrongWireType
|
||||
)
|
||||
|
||||
func (v ValidationStatus) String() string {
|
||||
@@ -149,11 +153,23 @@ func newValidationInfo(fd protoreflect.FieldDescriptor, ft reflect.Type) validat
|
||||
switch fd.Kind() {
|
||||
case protoreflect.MessageKind:
|
||||
vi.typ = validationTypeMessage
|
||||
|
||||
if ft.Kind() == reflect.Ptr {
|
||||
// Repeated opaque message fields are *[]*T.
|
||||
ft = ft.Elem()
|
||||
}
|
||||
|
||||
if ft.Kind() == reflect.Slice {
|
||||
vi.mi = getMessageInfo(ft.Elem())
|
||||
}
|
||||
case protoreflect.GroupKind:
|
||||
vi.typ = validationTypeGroup
|
||||
|
||||
if ft.Kind() == reflect.Ptr {
|
||||
// Repeated opaque message fields are *[]*T.
|
||||
ft = ft.Elem()
|
||||
}
|
||||
|
||||
if ft.Kind() == reflect.Slice {
|
||||
vi.mi = getMessageInfo(ft.Elem())
|
||||
}
|
||||
|
||||
+364
@@ -0,0 +1,364 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Helper code for parsing a protocol buffer
|
||||
|
||||
package protolazy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
)
|
||||
|
||||
// BufferReader is a structure encapsulating a protobuf and a current position
|
||||
type BufferReader struct {
|
||||
Buf []byte
|
||||
Pos int
|
||||
}
|
||||
|
||||
// NewBufferReader creates a new BufferRead from a protobuf
|
||||
func NewBufferReader(buf []byte) BufferReader {
|
||||
return BufferReader{Buf: buf, Pos: 0}
|
||||
}
|
||||
|
||||
var errOutOfBounds = errors.New("protobuf decoding: out of bounds")
|
||||
var errOverflow = errors.New("proto: integer overflow")
|
||||
|
||||
func (b *BufferReader) DecodeVarintSlow() (x uint64, err error) {
|
||||
i := b.Pos
|
||||
l := len(b.Buf)
|
||||
|
||||
for shift := uint(0); shift < 64; shift += 7 {
|
||||
if i >= l {
|
||||
err = io.ErrUnexpectedEOF
|
||||
return
|
||||
}
|
||||
v := b.Buf[i]
|
||||
i++
|
||||
x |= (uint64(v) & 0x7F) << shift
|
||||
if v < 0x80 {
|
||||
b.Pos = i
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// The number is too large to represent in a 64-bit value.
|
||||
err = errOverflow
|
||||
return
|
||||
}
|
||||
|
||||
// decodeVarint decodes a varint at the current position
|
||||
func (b *BufferReader) DecodeVarint() (x uint64, err error) {
|
||||
i := b.Pos
|
||||
buf := b.Buf
|
||||
|
||||
if i >= len(buf) {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
} else if buf[i] < 0x80 {
|
||||
b.Pos++
|
||||
return uint64(buf[i]), nil
|
||||
} else if len(buf)-i < 10 {
|
||||
return b.DecodeVarintSlow()
|
||||
}
|
||||
|
||||
var v uint64
|
||||
// we already checked the first byte
|
||||
x = uint64(buf[i]) & 127
|
||||
i++
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 7
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 14
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 21
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 28
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 35
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 42
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 49
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 56
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint64(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 63
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
return 0, errOverflow
|
||||
|
||||
done:
|
||||
b.Pos = i
|
||||
return
|
||||
}
|
||||
|
||||
// decodeVarint32 decodes a varint32 at the current position
|
||||
func (b *BufferReader) DecodeVarint32() (x uint32, err error) {
|
||||
i := b.Pos
|
||||
buf := b.Buf
|
||||
|
||||
if i >= len(buf) {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
} else if buf[i] < 0x80 {
|
||||
b.Pos++
|
||||
return uint32(buf[i]), nil
|
||||
} else if len(buf)-i < 5 {
|
||||
v, err := b.DecodeVarintSlow()
|
||||
return uint32(v), err
|
||||
}
|
||||
|
||||
var v uint32
|
||||
// we already checked the first byte
|
||||
x = uint32(buf[i]) & 127
|
||||
i++
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 7
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 14
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 21
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
x |= (v & 127) << 28
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
return 0, errOverflow
|
||||
|
||||
done:
|
||||
b.Pos = i
|
||||
return
|
||||
}
|
||||
|
||||
// skipValue skips a value in the protobuf, based on the specified tag
|
||||
func (b *BufferReader) SkipValue(tag uint32) (err error) {
|
||||
wireType := tag & 0x7
|
||||
switch protowire.Type(wireType) {
|
||||
case protowire.VarintType:
|
||||
err = b.SkipVarint()
|
||||
case protowire.Fixed64Type:
|
||||
err = b.SkipFixed64()
|
||||
case protowire.BytesType:
|
||||
var n uint32
|
||||
n, err = b.DecodeVarint32()
|
||||
if err == nil {
|
||||
err = b.Skip(int(n))
|
||||
}
|
||||
case protowire.StartGroupType:
|
||||
err = b.SkipGroup(tag)
|
||||
case protowire.Fixed32Type:
|
||||
err = b.SkipFixed32()
|
||||
default:
|
||||
err = fmt.Errorf("Unexpected wire type (%d)", wireType)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// skipGroup skips a group with the specified tag. It executes efficiently using a tag stack
|
||||
func (b *BufferReader) SkipGroup(tag uint32) (err error) {
|
||||
tagStack := make([]uint32, 0, 16)
|
||||
tagStack = append(tagStack, tag)
|
||||
var n uint32
|
||||
for len(tagStack) > 0 {
|
||||
tag, err = b.DecodeVarint32()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch protowire.Type(tag & 0x7) {
|
||||
case protowire.VarintType:
|
||||
err = b.SkipVarint()
|
||||
case protowire.Fixed64Type:
|
||||
err = b.Skip(8)
|
||||
case protowire.BytesType:
|
||||
n, err = b.DecodeVarint32()
|
||||
if err == nil {
|
||||
err = b.Skip(int(n))
|
||||
}
|
||||
case protowire.StartGroupType:
|
||||
tagStack = append(tagStack, tag)
|
||||
case protowire.Fixed32Type:
|
||||
err = b.SkipFixed32()
|
||||
case protowire.EndGroupType:
|
||||
if protoFieldNumber(tagStack[len(tagStack)-1]) == protoFieldNumber(tag) {
|
||||
tagStack = tagStack[:len(tagStack)-1]
|
||||
} else {
|
||||
err = fmt.Errorf("end group tag %d does not match begin group tag %d at pos %d",
|
||||
protoFieldNumber(tag), protoFieldNumber(tagStack[len(tagStack)-1]), b.Pos)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// skipVarint effiently skips a varint
|
||||
func (b *BufferReader) SkipVarint() (err error) {
|
||||
i := b.Pos
|
||||
|
||||
if len(b.Buf)-i < 10 {
|
||||
// Use DecodeVarintSlow() to check for buffer overflow, but ignore result
|
||||
if _, err := b.DecodeVarintSlow(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if b.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
return errOverflow
|
||||
|
||||
out:
|
||||
b.Pos = i + 1
|
||||
return nil
|
||||
}
|
||||
|
||||
// skip skips the specified number of bytes
|
||||
func (b *BufferReader) Skip(n int) (err error) {
|
||||
if len(b.Buf) < b.Pos+n {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b.Pos += n
|
||||
return
|
||||
}
|
||||
|
||||
// skipFixed64 skips a fixed64
|
||||
func (b *BufferReader) SkipFixed64() (err error) {
|
||||
return b.Skip(8)
|
||||
}
|
||||
|
||||
// skipFixed32 skips a fixed32
|
||||
func (b *BufferReader) SkipFixed32() (err error) {
|
||||
return b.Skip(4)
|
||||
}
|
||||
|
||||
// skipBytes skips a set of bytes
|
||||
func (b *BufferReader) SkipBytes() (err error) {
|
||||
n, err := b.DecodeVarint32()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.Skip(int(n))
|
||||
}
|
||||
|
||||
// Done returns whether we are at the end of the protobuf
|
||||
func (b *BufferReader) Done() bool {
|
||||
return b.Pos == len(b.Buf)
|
||||
}
|
||||
|
||||
// Remaining returns how many bytes remain
|
||||
func (b *BufferReader) Remaining() int {
|
||||
return len(b.Buf) - b.Pos
|
||||
}
|
||||
+359
@@ -0,0 +1,359 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package protolazy contains internal data structures for lazy message decoding.
|
||||
package protolazy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
piface "google.golang.org/protobuf/runtime/protoiface"
|
||||
)
|
||||
|
||||
// IndexEntry is the structure for an index of the fields in a message of a
|
||||
// proto (not descending to sub-messages)
|
||||
type IndexEntry struct {
|
||||
FieldNum uint32
|
||||
// first byte of this tag/field
|
||||
Start uint32
|
||||
// first byte after a contiguous sequence of bytes for this tag/field, which could
|
||||
// include a single encoding of the field, or multiple encodings for the field
|
||||
End uint32
|
||||
// True if this protobuf segment includes multiple encodings of the field
|
||||
MultipleContiguous bool
|
||||
}
|
||||
|
||||
// XXX_lazyUnmarshalInfo has information about a particular lazily decoded message
|
||||
//
|
||||
// Deprecated: Do not use. This will be deleted in the near future.
|
||||
type XXX_lazyUnmarshalInfo struct {
|
||||
// Index of fields and their positions in the protobuf for this
|
||||
// message. Make index be a pointer to a slice so it can be updated
|
||||
// atomically. The index pointer is only set once (lazily when/if
|
||||
// the index is first needed), and must always be SET and LOADED
|
||||
// ATOMICALLY.
|
||||
index *[]IndexEntry
|
||||
// The protobuf associated with this lazily decoded message. It is
|
||||
// only set during proto.Unmarshal(). It doesn't need to be set and
|
||||
// loaded atomically, since any simultaneous set (Unmarshal) and read
|
||||
// (during a get) would already be a race in the app code.
|
||||
Protobuf []byte
|
||||
// The flags present when Unmarshal was originally called for this particular message
|
||||
unmarshalFlags piface.UnmarshalInputFlags
|
||||
}
|
||||
|
||||
// The Buffer and SetBuffer methods let v2/internal/impl interact with
|
||||
// XXX_lazyUnmarshalInfo via an interface, to avoid an import cycle.
|
||||
|
||||
// Buffer returns the lazy unmarshal buffer.
|
||||
//
|
||||
// Deprecated: Do not use. This will be deleted in the near future.
|
||||
func (lazy *XXX_lazyUnmarshalInfo) Buffer() []byte {
|
||||
return lazy.Protobuf
|
||||
}
|
||||
|
||||
// SetBuffer sets the lazy unmarshal buffer.
|
||||
//
|
||||
// Deprecated: Do not use. This will be deleted in the near future.
|
||||
func (lazy *XXX_lazyUnmarshalInfo) SetBuffer(b []byte) {
|
||||
lazy.Protobuf = b
|
||||
}
|
||||
|
||||
// SetUnmarshalFlags is called to set a copy of the original unmarshalInputFlags.
|
||||
// The flags should reflect how Unmarshal was called.
|
||||
func (lazy *XXX_lazyUnmarshalInfo) SetUnmarshalFlags(f piface.UnmarshalInputFlags) {
|
||||
lazy.unmarshalFlags = f
|
||||
}
|
||||
|
||||
// UnmarshalFlags returns the original unmarshalInputFlags.
|
||||
func (lazy *XXX_lazyUnmarshalInfo) UnmarshalFlags() piface.UnmarshalInputFlags {
|
||||
return lazy.unmarshalFlags
|
||||
}
|
||||
|
||||
// AllowedPartial returns true if the user originally unmarshalled this message with
|
||||
// AllowPartial set to true
|
||||
func (lazy *XXX_lazyUnmarshalInfo) AllowedPartial() bool {
|
||||
return (lazy.unmarshalFlags & piface.UnmarshalCheckRequired) == 0
|
||||
}
|
||||
|
||||
func protoFieldNumber(tag uint32) uint32 {
|
||||
return tag >> 3
|
||||
}
|
||||
|
||||
// buildIndex builds an index of the specified protobuf, return the index
|
||||
// array and an error.
|
||||
func buildIndex(buf []byte) ([]IndexEntry, error) {
|
||||
index := make([]IndexEntry, 0, 16)
|
||||
var lastProtoFieldNum uint32
|
||||
var outOfOrder bool
|
||||
|
||||
var r BufferReader = NewBufferReader(buf)
|
||||
|
||||
for !r.Done() {
|
||||
var tag uint32
|
||||
var err error
|
||||
var curPos = r.Pos
|
||||
// INLINED: tag, err = r.DecodeVarint32()
|
||||
{
|
||||
i := r.Pos
|
||||
buf := r.Buf
|
||||
|
||||
if i >= len(buf) {
|
||||
return nil, errOutOfBounds
|
||||
} else if buf[i] < 0x80 {
|
||||
r.Pos++
|
||||
tag = uint32(buf[i])
|
||||
} else if r.Remaining() < 5 {
|
||||
var v uint64
|
||||
v, err = r.DecodeVarintSlow()
|
||||
tag = uint32(v)
|
||||
} else {
|
||||
var v uint32
|
||||
// we already checked the first byte
|
||||
tag = uint32(buf[i]) & 127
|
||||
i++
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
tag |= (v & 127) << 7
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
tag |= (v & 127) << 14
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
tag |= (v & 127) << 21
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
v = uint32(buf[i])
|
||||
i++
|
||||
tag |= (v & 127) << 28
|
||||
if v < 128 {
|
||||
goto done
|
||||
}
|
||||
|
||||
return nil, errOutOfBounds
|
||||
|
||||
done:
|
||||
r.Pos = i
|
||||
}
|
||||
}
|
||||
// DONE: tag, err = r.DecodeVarint32()
|
||||
|
||||
fieldNum := protoFieldNumber(tag)
|
||||
if fieldNum < lastProtoFieldNum {
|
||||
outOfOrder = true
|
||||
}
|
||||
|
||||
// Skip the current value -- will skip over an entire group as well.
|
||||
// INLINED: err = r.SkipValue(tag)
|
||||
wireType := tag & 0x7
|
||||
switch protowire.Type(wireType) {
|
||||
case protowire.VarintType:
|
||||
// INLINED: err = r.SkipVarint()
|
||||
i := r.Pos
|
||||
|
||||
if len(r.Buf)-i < 10 {
|
||||
// Use DecodeVarintSlow() to skip while
|
||||
// checking for buffer overflow, but ignore result
|
||||
_, err = r.DecodeVarintSlow()
|
||||
goto out2
|
||||
}
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
i++
|
||||
|
||||
if r.Buf[i] < 0x80 {
|
||||
goto out
|
||||
}
|
||||
return nil, errOverflow
|
||||
out:
|
||||
r.Pos = i + 1
|
||||
// DONE: err = r.SkipVarint()
|
||||
case protowire.Fixed64Type:
|
||||
err = r.SkipFixed64()
|
||||
case protowire.BytesType:
|
||||
var n uint32
|
||||
n, err = r.DecodeVarint32()
|
||||
if err == nil {
|
||||
err = r.Skip(int(n))
|
||||
}
|
||||
case protowire.StartGroupType:
|
||||
err = r.SkipGroup(tag)
|
||||
case protowire.Fixed32Type:
|
||||
err = r.SkipFixed32()
|
||||
default:
|
||||
err = fmt.Errorf("Unexpected wire type (%d)", wireType)
|
||||
}
|
||||
// DONE: err = r.SkipValue(tag)
|
||||
|
||||
out2:
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fieldNum != lastProtoFieldNum {
|
||||
index = append(index, IndexEntry{FieldNum: fieldNum,
|
||||
Start: uint32(curPos),
|
||||
End: uint32(r.Pos)},
|
||||
)
|
||||
} else {
|
||||
index[len(index)-1].End = uint32(r.Pos)
|
||||
index[len(index)-1].MultipleContiguous = true
|
||||
}
|
||||
lastProtoFieldNum = fieldNum
|
||||
}
|
||||
if outOfOrder {
|
||||
sort.Slice(index, func(i, j int) bool {
|
||||
return index[i].FieldNum < index[j].FieldNum ||
|
||||
(index[i].FieldNum == index[j].FieldNum &&
|
||||
index[i].Start < index[j].Start)
|
||||
})
|
||||
}
|
||||
return index, nil
|
||||
}
|
||||
|
||||
func (lazy *XXX_lazyUnmarshalInfo) SizeField(num uint32) (size int) {
|
||||
start, end, found, _, multipleEntries := lazy.FindFieldInProto(num)
|
||||
if multipleEntries != nil {
|
||||
for _, entry := range multipleEntries {
|
||||
size += int(entry.End - entry.Start)
|
||||
}
|
||||
return size
|
||||
}
|
||||
if !found {
|
||||
return 0
|
||||
}
|
||||
return int(end - start)
|
||||
}
|
||||
|
||||
func (lazy *XXX_lazyUnmarshalInfo) AppendField(b []byte, num uint32) ([]byte, bool) {
|
||||
start, end, found, _, multipleEntries := lazy.FindFieldInProto(num)
|
||||
if multipleEntries != nil {
|
||||
for _, entry := range multipleEntries {
|
||||
b = append(b, lazy.Protobuf[entry.Start:entry.End]...)
|
||||
}
|
||||
return b, true
|
||||
}
|
||||
if !found {
|
||||
return nil, false
|
||||
}
|
||||
b = append(b, lazy.Protobuf[start:end]...)
|
||||
return b, true
|
||||
}
|
||||
|
||||
func (lazy *XXX_lazyUnmarshalInfo) SetIndex(index []IndexEntry) {
|
||||
atomicStoreIndex(&lazy.index, &index)
|
||||
}
|
||||
|
||||
// FindFieldInProto looks for field fieldNum in lazyUnmarshalInfo information
|
||||
// (including protobuf), returns startOffset/endOffset/found.
|
||||
func (lazy *XXX_lazyUnmarshalInfo) FindFieldInProto(fieldNum uint32) (start, end uint32, found, multipleContiguous bool, multipleEntries []IndexEntry) {
|
||||
if lazy.Protobuf == nil {
|
||||
// There is no backing protobuf for this message -- it was made from a builder
|
||||
return 0, 0, false, false, nil
|
||||
}
|
||||
index := atomicLoadIndex(&lazy.index)
|
||||
if index == nil {
|
||||
r, err := buildIndex(lazy.Protobuf)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("findFieldInfo: error building index when looking for field %d: %v", fieldNum, err))
|
||||
}
|
||||
// lazy.index is a pointer to the slice returned by BuildIndex
|
||||
index = &r
|
||||
atomicStoreIndex(&lazy.index, index)
|
||||
}
|
||||
return lookupField(index, fieldNum)
|
||||
}
|
||||
|
||||
// lookupField returns the offset at which the indicated field starts using
|
||||
// the index, offset immediately after field ends (including all instances of
|
||||
// a repeated field), and bools indicating if field was found and if there
|
||||
// are multiple encodings of the field in the byte range.
|
||||
//
|
||||
// To hande the uncommon case where there are repeated encodings for the same
|
||||
// field which are not consecutive in the protobuf (so we need to returns
|
||||
// multiple start/end offsets), we also return a slice multipleEntries. If
|
||||
// multipleEntries is non-nil, then multiple entries were found, and the
|
||||
// values in the slice should be used, rather than start/end/found.
|
||||
func lookupField(indexp *[]IndexEntry, fieldNum uint32) (start, end uint32, found bool, multipleContiguous bool, multipleEntries []IndexEntry) {
|
||||
// The pointer indexp to the index was already loaded atomically.
|
||||
// The slice is uniquely associated with the pointer, so it doesn't
|
||||
// need to be loaded atomically.
|
||||
index := *indexp
|
||||
for i, entry := range index {
|
||||
if fieldNum == entry.FieldNum {
|
||||
if i < len(index)-1 && entry.FieldNum == index[i+1].FieldNum {
|
||||
// Handle the uncommon case where there are
|
||||
// repeated entries for the same field which
|
||||
// are not contiguous in the protobuf.
|
||||
multiple := make([]IndexEntry, 1, 2)
|
||||
multiple[0] = IndexEntry{fieldNum, entry.Start, entry.End, entry.MultipleContiguous}
|
||||
i++
|
||||
for i < len(index) && index[i].FieldNum == fieldNum {
|
||||
multiple = append(multiple, IndexEntry{fieldNum, index[i].Start, index[i].End, index[i].MultipleContiguous})
|
||||
i++
|
||||
}
|
||||
return 0, 0, false, false, multiple
|
||||
|
||||
}
|
||||
return entry.Start, entry.End, true, entry.MultipleContiguous, nil
|
||||
}
|
||||
if fieldNum < entry.FieldNum {
|
||||
return 0, 0, false, false, nil
|
||||
}
|
||||
}
|
||||
return 0, 0, false, false, nil
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package protolazy
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func atomicLoadIndex(p **[]IndexEntry) *[]IndexEntry {
|
||||
return (*[]IndexEntry)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||
}
|
||||
func atomicStoreIndex(p **[]IndexEntry, v *[]IndexEntry) {
|
||||
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||
}
|
||||
+2
-2
@@ -51,8 +51,8 @@ import (
|
||||
// 10. Send out the CL for review and submit it.
|
||||
const (
|
||||
Major = 1
|
||||
Minor = 35
|
||||
Patch = 2
|
||||
Minor = 36
|
||||
Patch = 3
|
||||
PreRelease = ""
|
||||
)
|
||||
|
||||
|
||||
+17
-1
@@ -47,6 +47,12 @@ type UnmarshalOptions struct {
|
||||
// RecursionLimit limits how deeply messages may be nested.
|
||||
// If zero, a default limit is applied.
|
||||
RecursionLimit int
|
||||
|
||||
//
|
||||
// NoLazyDecoding turns off lazy decoding, which otherwise is enabled by
|
||||
// default. Lazy decoding only affects submessages (annotated with [lazy =
|
||||
// true] in the .proto file) within messages that use the Opaque API.
|
||||
NoLazyDecoding bool
|
||||
}
|
||||
|
||||
// Unmarshal parses the wire-format message in b and places the result in m.
|
||||
@@ -104,6 +110,16 @@ func (o UnmarshalOptions) unmarshal(b []byte, m protoreflect.Message) (out proto
|
||||
if o.DiscardUnknown {
|
||||
in.Flags |= protoiface.UnmarshalDiscardUnknown
|
||||
}
|
||||
|
||||
if !allowPartial {
|
||||
// This does not affect how current unmarshal functions work, it just allows them
|
||||
// to record this for lazy the decoding case.
|
||||
in.Flags |= protoiface.UnmarshalCheckRequired
|
||||
}
|
||||
if o.NoLazyDecoding {
|
||||
in.Flags |= protoiface.UnmarshalNoLazyDecoding
|
||||
}
|
||||
|
||||
out, err = methods.Unmarshal(in)
|
||||
} else {
|
||||
o.RecursionLimit--
|
||||
@@ -156,7 +172,7 @@ func (o UnmarshalOptions) unmarshalMessageSlow(b []byte, m protoreflect.Message)
|
||||
var err error
|
||||
if fd == nil {
|
||||
err = errUnknown
|
||||
} else if flags.ProtoLegacy {
|
||||
} else if flags.ProtoLegacyWeak {
|
||||
if fd.IsWeak() && fd.Message().IsPlaceholder() {
|
||||
err = errUnknown // weak referent is not linked in
|
||||
}
|
||||
|
||||
+2
-1
@@ -63,7 +63,8 @@ type MarshalOptions struct {
|
||||
// options (except for UseCachedSize itself).
|
||||
//
|
||||
// 2. The message and all its submessages have not changed in any
|
||||
// way since the Size call.
|
||||
// way since the Size call. For lazily decoded messages, accessing
|
||||
// a message results in decoding the message, which is a change.
|
||||
//
|
||||
// If either of these invariants is violated,
|
||||
// the results are undefined and may include panics or corrupted output.
|
||||
|
||||
+8
@@ -12,11 +12,19 @@ import (
|
||||
)
|
||||
|
||||
// Size returns the size in bytes of the wire-format encoding of m.
|
||||
//
|
||||
// Note that Size might return more bytes than Marshal will write in the case of
|
||||
// lazily decoded messages that arrive in non-minimal wire format: see
|
||||
// https://protobuf.dev/reference/go/size/ for more details.
|
||||
func Size(m Message) int {
|
||||
return MarshalOptions{}.Size(m)
|
||||
}
|
||||
|
||||
// Size returns the size in bytes of the wire-format encoding of m.
|
||||
//
|
||||
// Note that Size might return more bytes than Marshal will write in the case of
|
||||
// lazily decoded messages that arrive in non-minimal wire format: see
|
||||
// https://protobuf.dev/reference/go/size/ for more details.
|
||||
func (o MarshalOptions) Size(m Message) int {
|
||||
// Treat a nil message interface as an empty message; nothing to output.
|
||||
if m == nil {
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
// Copyright 2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package proto
|
||||
|
||||
// ValueOrNil returns nil if has is false, or a pointer to a new variable
|
||||
// containing the value returned by the specified getter.
|
||||
//
|
||||
// This function is similar to the wrappers (proto.Int32(), proto.String(),
|
||||
// etc.), but is generic (works for any field type) and works with the hasser
|
||||
// and getter of a field, as opposed to a value.
|
||||
//
|
||||
// This is convenient when populating builder fields.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// hop := attr.GetDirectHop()
|
||||
// injectedRoute := ripb.InjectedRoute_builder{
|
||||
// Prefixes: route.GetPrefixes(),
|
||||
// NextHop: proto.ValueOrNil(hop.HasAddress(), hop.GetAddress),
|
||||
// }
|
||||
func ValueOrNil[T any](has bool, getter func() T) *T {
|
||||
if !has {
|
||||
return nil
|
||||
}
|
||||
v := getter()
|
||||
return &v
|
||||
}
|
||||
|
||||
// ValueOrDefault returns the protobuf message val if val is not nil, otherwise
|
||||
// it returns a pointer to an empty val message.
|
||||
//
|
||||
// This function allows for translating code from the old Open Struct API to the
|
||||
// new Opaque API.
|
||||
//
|
||||
// The old Open Struct API represented oneof fields with a wrapper struct:
|
||||
//
|
||||
// var signedImg *accountpb.SignedImage
|
||||
// profile := &accountpb.Profile{
|
||||
// // The Avatar oneof will be set, with an empty SignedImage.
|
||||
// Avatar: &accountpb.Profile_SignedImage{signedImg},
|
||||
// }
|
||||
//
|
||||
// The new Opaque API treats oneof fields like regular fields, there are no more
|
||||
// wrapper structs:
|
||||
//
|
||||
// var signedImg *accountpb.SignedImage
|
||||
// profile := &accountpb.Profile{}
|
||||
// profile.SetSignedImage(signedImg)
|
||||
//
|
||||
// For convenience, the Opaque API also offers Builders, which allow for a
|
||||
// direct translation of struct initialization. However, because Builders use
|
||||
// nilness to represent field presence (but there is no non-nil wrapper struct
|
||||
// anymore), Builders cannot distinguish between an unset oneof and a set oneof
|
||||
// with nil message. The above code would need to be translated with help of the
|
||||
// ValueOrDefault function to retain the same behavior:
|
||||
//
|
||||
// var signedImg *accountpb.SignedImage
|
||||
// return &accountpb.Profile_builder{
|
||||
// SignedImage: proto.ValueOrDefault(signedImg),
|
||||
// }.Build()
|
||||
func ValueOrDefault[T interface {
|
||||
*P
|
||||
Message
|
||||
}, P any](val T) T {
|
||||
if val == nil {
|
||||
return T(new(P))
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
// ValueOrDefaultBytes is like ValueOrDefault but for working with fields of
|
||||
// type []byte.
|
||||
func ValueOrDefaultBytes(val []byte) []byte {
|
||||
if val == nil {
|
||||
return []byte{}
|
||||
}
|
||||
return val
|
||||
}
|
||||
+1
-1
@@ -149,7 +149,7 @@ func validateMessageDeclarations(file *filedesc.File, ms []filedesc.Message, mds
|
||||
return errors.New("message field %q under proto3 optional semantics must be within a single element oneof", f.FullName())
|
||||
}
|
||||
}
|
||||
if f.IsWeak() && !flags.ProtoLegacy {
|
||||
if f.IsWeak() && !flags.ProtoLegacyWeak {
|
||||
return errors.New("message field %q is a weak field, which is a legacy proto1 feature that is no longer supported", f.FullName())
|
||||
}
|
||||
if f.IsWeak() && (!f.HasPresence() || !isOptionalMessage(f) || f.ContainingOneof() != nil) {
|
||||
|
||||
+21
-7
@@ -125,13 +125,27 @@ func mergeEditionFeatures(parentDesc protoreflect.Descriptor, child *descriptorp
|
||||
parentFS.IsJSONCompliant = *jf == descriptorpb.FeatureSet_ALLOW
|
||||
}
|
||||
|
||||
if goFeatures, ok := proto.GetExtension(child, gofeaturespb.E_Go).(*gofeaturespb.GoFeatures); ok && goFeatures != nil {
|
||||
if luje := goFeatures.LegacyUnmarshalJsonEnum; luje != nil {
|
||||
parentFS.GenerateLegacyUnmarshalJSON = *luje
|
||||
}
|
||||
if sep := goFeatures.StripEnumPrefix; sep != nil {
|
||||
parentFS.StripEnumPrefix = int(*sep)
|
||||
}
|
||||
// We must not use proto.GetExtension(child, gofeaturespb.E_Go)
|
||||
// because that only works for messages we generated, but not for
|
||||
// dynamicpb messages. See golang/protobuf#1669.
|
||||
goFeatures := child.ProtoReflect().Get(gofeaturespb.E_Go.TypeDescriptor())
|
||||
if !goFeatures.IsValid() {
|
||||
return parentFS
|
||||
}
|
||||
// gf.Interface() could be *dynamicpb.Message or *gofeaturespb.GoFeatures.
|
||||
gf := goFeatures.Message()
|
||||
fields := gf.Descriptor().Fields()
|
||||
|
||||
if fd := fields.ByName("legacy_unmarshal_json_enum"); gf.Has(fd) {
|
||||
parentFS.GenerateLegacyUnmarshalJSON = gf.Get(fd).Bool()
|
||||
}
|
||||
|
||||
if fd := fields.ByName("strip_enum_prefix"); gf.Has(fd) {
|
||||
parentFS.StripEnumPrefix = int(gf.Get(fd).Enum())
|
||||
}
|
||||
|
||||
if fd := fields.ByName("api_level"); gf.Has(fd) {
|
||||
parentFS.APILevel = int(gf.Get(fd).Enum())
|
||||
}
|
||||
|
||||
return parentFS
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ type Message interface {
|
||||
// This method may return nil.
|
||||
//
|
||||
// The returned methods type is identical to
|
||||
// google.golang.org/protobuf/runtime/protoiface.Methods.
|
||||
// [google.golang.org/protobuf/runtime/protoiface.Methods].
|
||||
// Consult the protoiface package documentation for details.
|
||||
ProtoMethods() *methods
|
||||
}
|
||||
|
||||
+16
@@ -122,6 +122,22 @@ type UnmarshalInputFlags = uint8
|
||||
|
||||
const (
|
||||
UnmarshalDiscardUnknown UnmarshalInputFlags = 1 << iota
|
||||
|
||||
// UnmarshalAliasBuffer permits unmarshal operations to alias the input buffer.
|
||||
// The unmarshaller must not modify the contents of the buffer.
|
||||
UnmarshalAliasBuffer
|
||||
|
||||
// UnmarshalValidated indicates that validation has already been
|
||||
// performed on the input buffer.
|
||||
UnmarshalValidated
|
||||
|
||||
// UnmarshalCheckRequired is set if this unmarshal operation ultimately will care if required fields are
|
||||
// initialized.
|
||||
UnmarshalCheckRequired
|
||||
|
||||
// UnmarshalNoLazyDecoding is set if this unmarshal operation should not use
|
||||
// lazy decoding, even when otherwise available.
|
||||
UnmarshalNoLazyDecoding
|
||||
)
|
||||
|
||||
// UnmarshalOutputFlags are output from the Unmarshal method.
|
||||
|
||||
+4
@@ -15,6 +15,7 @@ import (
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/internal/filetype"
|
||||
"google.golang.org/protobuf/internal/impl"
|
||||
"google.golang.org/protobuf/internal/protolazy"
|
||||
)
|
||||
|
||||
// UnsafeEnabled specifies whether package unsafe can be used.
|
||||
@@ -39,6 +40,9 @@ type (
|
||||
ExtensionFieldV1 = impl.ExtensionField
|
||||
|
||||
Pointer = impl.Pointer
|
||||
|
||||
LazyUnmarshalInfo = *protolazy.XXX_lazyUnmarshalInfo
|
||||
RaceDetectHookData = impl.RaceDetectHookData
|
||||
)
|
||||
|
||||
var X impl.Export
|
||||
|
||||
+874
-905
File diff suppressed because it is too large
Load Diff
+136
-47
@@ -18,6 +18,71 @@ import (
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
type GoFeatures_APILevel int32
|
||||
|
||||
const (
|
||||
// API_LEVEL_UNSPECIFIED results in selecting the OPEN API,
|
||||
// but needs to be a separate value to distinguish between
|
||||
// an explicitly set api level or a missing api level.
|
||||
GoFeatures_API_LEVEL_UNSPECIFIED GoFeatures_APILevel = 0
|
||||
GoFeatures_API_OPEN GoFeatures_APILevel = 1
|
||||
GoFeatures_API_HYBRID GoFeatures_APILevel = 2
|
||||
GoFeatures_API_OPAQUE GoFeatures_APILevel = 3
|
||||
)
|
||||
|
||||
// Enum value maps for GoFeatures_APILevel.
|
||||
var (
|
||||
GoFeatures_APILevel_name = map[int32]string{
|
||||
0: "API_LEVEL_UNSPECIFIED",
|
||||
1: "API_OPEN",
|
||||
2: "API_HYBRID",
|
||||
3: "API_OPAQUE",
|
||||
}
|
||||
GoFeatures_APILevel_value = map[string]int32{
|
||||
"API_LEVEL_UNSPECIFIED": 0,
|
||||
"API_OPEN": 1,
|
||||
"API_HYBRID": 2,
|
||||
"API_OPAQUE": 3,
|
||||
}
|
||||
)
|
||||
|
||||
func (x GoFeatures_APILevel) Enum() *GoFeatures_APILevel {
|
||||
p := new(GoFeatures_APILevel)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x GoFeatures_APILevel) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (GoFeatures_APILevel) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_google_protobuf_go_features_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (GoFeatures_APILevel) Type() protoreflect.EnumType {
|
||||
return &file_google_protobuf_go_features_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x GoFeatures_APILevel) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Do not use.
|
||||
func (x *GoFeatures_APILevel) UnmarshalJSON(b []byte) error {
|
||||
num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*x = GoFeatures_APILevel(num)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deprecated: Use GoFeatures_APILevel.Descriptor instead.
|
||||
func (GoFeatures_APILevel) EnumDescriptor() ([]byte, []int) {
|
||||
return file_google_protobuf_go_features_proto_rawDescGZIP(), []int{0, 0}
|
||||
}
|
||||
|
||||
type GoFeatures_StripEnumPrefix int32
|
||||
|
||||
const (
|
||||
@@ -54,11 +119,11 @@ func (x GoFeatures_StripEnumPrefix) String() string {
|
||||
}
|
||||
|
||||
func (GoFeatures_StripEnumPrefix) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_google_protobuf_go_features_proto_enumTypes[0].Descriptor()
|
||||
return file_google_protobuf_go_features_proto_enumTypes[1].Descriptor()
|
||||
}
|
||||
|
||||
func (GoFeatures_StripEnumPrefix) Type() protoreflect.EnumType {
|
||||
return &file_google_protobuf_go_features_proto_enumTypes[0]
|
||||
return &file_google_protobuf_go_features_proto_enumTypes[1]
|
||||
}
|
||||
|
||||
func (x GoFeatures_StripEnumPrefix) Number() protoreflect.EnumNumber {
|
||||
@@ -77,17 +142,19 @@ func (x *GoFeatures_StripEnumPrefix) UnmarshalJSON(b []byte) error {
|
||||
|
||||
// Deprecated: Use GoFeatures_StripEnumPrefix.Descriptor instead.
|
||||
func (GoFeatures_StripEnumPrefix) EnumDescriptor() ([]byte, []int) {
|
||||
return file_google_protobuf_go_features_proto_rawDescGZIP(), []int{0, 0}
|
||||
return file_google_protobuf_go_features_proto_rawDescGZIP(), []int{0, 1}
|
||||
}
|
||||
|
||||
type GoFeatures struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Whether or not to generate the deprecated UnmarshalJSON method for enums.
|
||||
LegacyUnmarshalJsonEnum *bool `protobuf:"varint,1,opt,name=legacy_unmarshal_json_enum,json=legacyUnmarshalJsonEnum" json:"legacy_unmarshal_json_enum,omitempty"`
|
||||
StripEnumPrefix *GoFeatures_StripEnumPrefix `protobuf:"varint,3,opt,name=strip_enum_prefix,json=stripEnumPrefix,enum=pb.GoFeatures_StripEnumPrefix" json:"strip_enum_prefix,omitempty"`
|
||||
// Can only be true for proto using the Open Struct api.
|
||||
LegacyUnmarshalJsonEnum *bool `protobuf:"varint,1,opt,name=legacy_unmarshal_json_enum,json=legacyUnmarshalJsonEnum" json:"legacy_unmarshal_json_enum,omitempty"`
|
||||
// One of OPEN, HYBRID or OPAQUE.
|
||||
ApiLevel *GoFeatures_APILevel `protobuf:"varint,2,opt,name=api_level,json=apiLevel,enum=pb.GoFeatures_APILevel" json:"api_level,omitempty"`
|
||||
StripEnumPrefix *GoFeatures_StripEnumPrefix `protobuf:"varint,3,opt,name=strip_enum_prefix,json=stripEnumPrefix,enum=pb.GoFeatures_StripEnumPrefix" json:"strip_enum_prefix,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GoFeatures) Reset() {
|
||||
@@ -127,6 +194,13 @@ func (x *GoFeatures) GetLegacyUnmarshalJsonEnum() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *GoFeatures) GetApiLevel() GoFeatures_APILevel {
|
||||
if x != nil && x.ApiLevel != nil {
|
||||
return *x.ApiLevel
|
||||
}
|
||||
return GoFeatures_API_LEVEL_UNSPECIFIED
|
||||
}
|
||||
|
||||
func (x *GoFeatures) GetStripEnumPrefix() GoFeatures_StripEnumPrefix {
|
||||
if x != nil && x.StripEnumPrefix != nil {
|
||||
return *x.StripEnumPrefix
|
||||
@@ -158,7 +232,7 @@ var file_google_protobuf_go_features_proto_rawDesc = []byte{
|
||||
0x66, 0x2f, 0x67, 0x6f, 0x5f, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70,
|
||||
0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe0, 0x03, 0x0a, 0x0a, 0x47, 0x6f,
|
||||
0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xab, 0x05, 0x0a, 0x0a, 0x47, 0x6f,
|
||||
0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x12, 0xbe, 0x01, 0x0a, 0x1a, 0x6c, 0x65, 0x67,
|
||||
0x61, 0x63, 0x79, 0x5f, 0x75, 0x6e, 0x6d, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6c, 0x5f, 0x6a, 0x73,
|
||||
0x6f, 0x6e, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x42, 0x80, 0x01,
|
||||
@@ -171,31 +245,44 @@ var file_google_protobuf_go_features_proto_rawDesc = []byte{
|
||||
0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x61,
|
||||
0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x20, 0x65, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e,
|
||||
0x52, 0x17, 0x6c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x55, 0x6e, 0x6d, 0x61, 0x72, 0x73, 0x68, 0x61,
|
||||
0x6c, 0x4a, 0x73, 0x6f, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x7c, 0x0a, 0x11, 0x73, 0x74, 0x72,
|
||||
0x69, 0x70, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x6f, 0x46, 0x65, 0x61, 0x74,
|
||||
0x75, 0x72, 0x65, 0x73, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x70, 0x45, 0x6e, 0x75, 0x6d, 0x50, 0x72,
|
||||
0x65, 0x66, 0x69, 0x78, 0x42, 0x30, 0x88, 0x01, 0x01, 0x98, 0x01, 0x06, 0x98, 0x01, 0x07, 0x98,
|
||||
0x01, 0x01, 0xa2, 0x01, 0x1b, 0x12, 0x16, 0x53, 0x54, 0x52, 0x49, 0x50, 0x5f, 0x45, 0x4e, 0x55,
|
||||
0x4d, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f, 0x4b, 0x45, 0x45, 0x50, 0x18, 0x84, 0x07,
|
||||
0xb2, 0x01, 0x03, 0x08, 0xe9, 0x07, 0x52, 0x0f, 0x73, 0x74, 0x72, 0x69, 0x70, 0x45, 0x6e, 0x75,
|
||||
0x6d, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x22, 0x92, 0x01, 0x0a, 0x0f, 0x53, 0x74, 0x72, 0x69,
|
||||
0x70, 0x45, 0x6e, 0x75, 0x6d, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x21, 0x0a, 0x1d, 0x53,
|
||||
0x54, 0x52, 0x49, 0x50, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58,
|
||||
0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1a,
|
||||
0x0a, 0x16, 0x53, 0x54, 0x52, 0x49, 0x50, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52, 0x45,
|
||||
0x46, 0x49, 0x58, 0x5f, 0x4b, 0x45, 0x45, 0x50, 0x10, 0x01, 0x12, 0x23, 0x0a, 0x1f, 0x53, 0x54,
|
||||
0x6c, 0x4a, 0x73, 0x6f, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x74, 0x0a, 0x09, 0x61, 0x70, 0x69,
|
||||
0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x70,
|
||||
0x62, 0x2e, 0x47, 0x6f, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x41, 0x50, 0x49,
|
||||
0x4c, 0x65, 0x76, 0x65, 0x6c, 0x42, 0x3e, 0x88, 0x01, 0x01, 0x98, 0x01, 0x03, 0x98, 0x01, 0x01,
|
||||
0xa2, 0x01, 0x1a, 0x12, 0x15, 0x41, 0x50, 0x49, 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x55,
|
||||
0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x18, 0x84, 0x07, 0xa2, 0x01, 0x0f,
|
||||
0x12, 0x0a, 0x41, 0x50, 0x49, 0x5f, 0x4f, 0x50, 0x41, 0x51, 0x55, 0x45, 0x18, 0xe9, 0x07, 0xb2,
|
||||
0x01, 0x03, 0x08, 0xe8, 0x07, 0x52, 0x08, 0x61, 0x70, 0x69, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12,
|
||||
0x7c, 0x0a, 0x11, 0x73, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x65, 0x6e, 0x75, 0x6d, 0x5f, 0x70, 0x72,
|
||||
0x65, 0x66, 0x69, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x70, 0x62, 0x2e,
|
||||
0x47, 0x6f, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x70,
|
||||
0x45, 0x6e, 0x75, 0x6d, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x42, 0x30, 0x88, 0x01, 0x01, 0x98,
|
||||
0x01, 0x06, 0x98, 0x01, 0x07, 0x98, 0x01, 0x01, 0xa2, 0x01, 0x1b, 0x12, 0x16, 0x53, 0x54, 0x52,
|
||||
0x49, 0x50, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f, 0x4b,
|
||||
0x45, 0x45, 0x50, 0x18, 0x84, 0x07, 0xb2, 0x01, 0x03, 0x08, 0xe9, 0x07, 0x52, 0x0f, 0x73, 0x74,
|
||||
0x72, 0x69, 0x70, 0x45, 0x6e, 0x75, 0x6d, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x22, 0x53, 0x0a,
|
||||
0x08, 0x41, 0x50, 0x49, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x19, 0x0a, 0x15, 0x41, 0x50, 0x49,
|
||||
0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49,
|
||||
0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x50, 0x49, 0x5f, 0x4f, 0x50, 0x45, 0x4e,
|
||||
0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x41, 0x50, 0x49, 0x5f, 0x48, 0x59, 0x42, 0x52, 0x49, 0x44,
|
||||
0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x41, 0x50, 0x49, 0x5f, 0x4f, 0x50, 0x41, 0x51, 0x55, 0x45,
|
||||
0x10, 0x03, 0x22, 0x92, 0x01, 0x0a, 0x0f, 0x53, 0x74, 0x72, 0x69, 0x70, 0x45, 0x6e, 0x75, 0x6d,
|
||||
0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x21, 0x0a, 0x1d, 0x53, 0x54, 0x52, 0x49, 0x50, 0x5f,
|
||||
0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f, 0x55, 0x4e, 0x53, 0x50,
|
||||
0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x16, 0x53, 0x54, 0x52,
|
||||
0x49, 0x50, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f, 0x4b,
|
||||
0x45, 0x45, 0x50, 0x10, 0x01, 0x12, 0x23, 0x0a, 0x1f, 0x53, 0x54, 0x52, 0x49, 0x50, 0x5f, 0x45,
|
||||
0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f, 0x47, 0x45, 0x4e, 0x45, 0x52,
|
||||
0x41, 0x54, 0x45, 0x5f, 0x42, 0x4f, 0x54, 0x48, 0x10, 0x02, 0x12, 0x1b, 0x0a, 0x17, 0x53, 0x54,
|
||||
0x52, 0x49, 0x50, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f,
|
||||
0x47, 0x45, 0x4e, 0x45, 0x52, 0x41, 0x54, 0x45, 0x5f, 0x42, 0x4f, 0x54, 0x48, 0x10, 0x02, 0x12,
|
||||
0x1b, 0x0a, 0x17, 0x53, 0x54, 0x52, 0x49, 0x50, 0x5f, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x50, 0x52,
|
||||
0x45, 0x46, 0x49, 0x58, 0x5f, 0x53, 0x54, 0x52, 0x49, 0x50, 0x10, 0x03, 0x3a, 0x3c, 0x0a, 0x02,
|
||||
0x67, 0x6f, 0x12, 0x1b, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x53, 0x65, 0x74, 0x18,
|
||||
0xea, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x6f, 0x46, 0x65,
|
||||
0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x52, 0x02, 0x67, 0x6f, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x67,
|
||||
0x6f, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x70, 0x62,
|
||||
0x53, 0x54, 0x52, 0x49, 0x50, 0x10, 0x03, 0x3a, 0x3c, 0x0a, 0x02, 0x67, 0x6f, 0x12, 0x1b, 0x2e,
|
||||
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
|
||||
0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x53, 0x65, 0x74, 0x18, 0xea, 0x07, 0x20, 0x01, 0x28,
|
||||
0x0b, 0x32, 0x0e, 0x2e, 0x70, 0x62, 0x2e, 0x47, 0x6f, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65,
|
||||
0x73, 0x52, 0x02, 0x67, 0x6f, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
|
||||
0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x62, 0x75, 0x66, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x67, 0x6f, 0x66, 0x65, 0x61, 0x74,
|
||||
0x75, 0x72, 0x65, 0x73, 0x70, 0x62,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -210,22 +297,24 @@ func file_google_protobuf_go_features_proto_rawDescGZIP() []byte {
|
||||
return file_google_protobuf_go_features_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_google_protobuf_go_features_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_google_protobuf_go_features_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
|
||||
var file_google_protobuf_go_features_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_google_protobuf_go_features_proto_goTypes = []any{
|
||||
(GoFeatures_StripEnumPrefix)(0), // 0: pb.GoFeatures.StripEnumPrefix
|
||||
(*GoFeatures)(nil), // 1: pb.GoFeatures
|
||||
(*descriptorpb.FeatureSet)(nil), // 2: google.protobuf.FeatureSet
|
||||
(GoFeatures_APILevel)(0), // 0: pb.GoFeatures.APILevel
|
||||
(GoFeatures_StripEnumPrefix)(0), // 1: pb.GoFeatures.StripEnumPrefix
|
||||
(*GoFeatures)(nil), // 2: pb.GoFeatures
|
||||
(*descriptorpb.FeatureSet)(nil), // 3: google.protobuf.FeatureSet
|
||||
}
|
||||
var file_google_protobuf_go_features_proto_depIdxs = []int32{
|
||||
0, // 0: pb.GoFeatures.strip_enum_prefix:type_name -> pb.GoFeatures.StripEnumPrefix
|
||||
2, // 1: pb.go:extendee -> google.protobuf.FeatureSet
|
||||
1, // 2: pb.go:type_name -> pb.GoFeatures
|
||||
3, // [3:3] is the sub-list for method output_type
|
||||
3, // [3:3] is the sub-list for method input_type
|
||||
2, // [2:3] is the sub-list for extension type_name
|
||||
1, // [1:2] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
0, // 0: pb.GoFeatures.api_level:type_name -> pb.GoFeatures.APILevel
|
||||
1, // 1: pb.GoFeatures.strip_enum_prefix:type_name -> pb.GoFeatures.StripEnumPrefix
|
||||
3, // 2: pb.go:extendee -> google.protobuf.FeatureSet
|
||||
2, // 3: pb.go:type_name -> pb.GoFeatures
|
||||
4, // [4:4] is the sub-list for method output_type
|
||||
4, // [4:4] is the sub-list for method input_type
|
||||
3, // [3:4] is the sub-list for extension type_name
|
||||
2, // [2:3] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_google_protobuf_go_features_proto_init() }
|
||||
@@ -238,7 +327,7 @@ func file_google_protobuf_go_features_proto_init() {
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_google_protobuf_go_features_proto_rawDesc,
|
||||
NumEnums: 1,
|
||||
NumEnums: 2,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 1,
|
||||
NumServices: 0,
|
||||
|
||||
+4
-5
@@ -210,10 +210,7 @@ import (
|
||||
// "value": "1.212s"
|
||||
// }
|
||||
type Any struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// A URL/resource name that uniquely identifies the type of the serialized
|
||||
// protocol buffer message. This string must contain at least
|
||||
// one "/" character. The last segment of the URL's path must represent
|
||||
@@ -244,7 +241,9 @@ type Any struct {
|
||||
// used with implementation specific semantics.
|
||||
TypeUrl string `protobuf:"bytes,1,opt,name=type_url,json=typeUrl,proto3" json:"type_url,omitempty"`
|
||||
// Must be a valid serialized protocol buffer of the above specified type.
|
||||
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// New marshals src into a new Any instance.
|
||||
|
||||
+4
-5
@@ -141,10 +141,7 @@ import (
|
||||
// be expressed in JSON format as "3.000000001s", and 3 seconds and 1
|
||||
// microsecond should be expressed in JSON format as "3.000001s".
|
||||
type Duration struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Signed seconds of the span of time. Must be from -315,576,000,000
|
||||
// to +315,576,000,000 inclusive. Note: these bounds are computed from:
|
||||
// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
|
||||
@@ -155,7 +152,9 @@ type Duration struct {
|
||||
// of one second or more, a non-zero value for the `nanos` field must be
|
||||
// of the same sign as the `seconds` field. Must be from -999,999,999
|
||||
// to +999,999,999 inclusive.
|
||||
Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
|
||||
Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// New constructs a new Duration from the provided time.Duration.
|
||||
|
||||
+4
-5
@@ -284,12 +284,11 @@ import (
|
||||
// request should verify the included field paths, and return an
|
||||
// `INVALID_ARGUMENT` error if any path is unmappable.
|
||||
type FieldMask struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The set of field mask paths.
|
||||
Paths []string `protobuf:"bytes,1,rep,name=paths,proto3" json:"paths,omitempty"`
|
||||
Paths []string `protobuf:"bytes,1,rep,name=paths,proto3" json:"paths,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// New constructs a field mask from a list of paths and verifies that
|
||||
|
||||
+40
-31
@@ -187,12 +187,11 @@ func (NullValue) EnumDescriptor() ([]byte, []int) {
|
||||
//
|
||||
// The JSON representation for `Struct` is JSON object.
|
||||
type Struct struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Unordered map of dynamically typed values.
|
||||
Fields map[string]*Value `protobuf:"bytes,1,rep,name=fields,proto3" json:"fields,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
Fields map[string]*Value `protobuf:"bytes,1,rep,name=fields,proto3" json:"fields,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// NewStruct constructs a Struct from a general-purpose Go map.
|
||||
@@ -276,13 +275,10 @@ func (x *Struct) GetFields() map[string]*Value {
|
||||
//
|
||||
// The JSON representation for `Value` is JSON value.
|
||||
type Value struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The kind of value.
|
||||
//
|
||||
// Types that are assignable to Kind:
|
||||
// Types that are valid to be assigned to Kind:
|
||||
//
|
||||
// *Value_NullValue
|
||||
// *Value_NumberValue
|
||||
@@ -290,7 +286,9 @@ type Value struct {
|
||||
// *Value_BoolValue
|
||||
// *Value_StructValue
|
||||
// *Value_ListValue
|
||||
Kind isValue_Kind `protobuf_oneof:"kind"`
|
||||
Kind isValue_Kind `protobuf_oneof:"kind"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// NewValue constructs a Value from a general-purpose Go interface.
|
||||
@@ -483,51 +481,63 @@ func (*Value) Descriptor() ([]byte, []int) {
|
||||
return file_google_protobuf_struct_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (m *Value) GetKind() isValue_Kind {
|
||||
if m != nil {
|
||||
return m.Kind
|
||||
func (x *Value) GetKind() isValue_Kind {
|
||||
if x != nil {
|
||||
return x.Kind
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Value) GetNullValue() NullValue {
|
||||
if x, ok := x.GetKind().(*Value_NullValue); ok {
|
||||
return x.NullValue
|
||||
if x != nil {
|
||||
if x, ok := x.Kind.(*Value_NullValue); ok {
|
||||
return x.NullValue
|
||||
}
|
||||
}
|
||||
return NullValue_NULL_VALUE
|
||||
}
|
||||
|
||||
func (x *Value) GetNumberValue() float64 {
|
||||
if x, ok := x.GetKind().(*Value_NumberValue); ok {
|
||||
return x.NumberValue
|
||||
if x != nil {
|
||||
if x, ok := x.Kind.(*Value_NumberValue); ok {
|
||||
return x.NumberValue
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Value) GetStringValue() string {
|
||||
if x, ok := x.GetKind().(*Value_StringValue); ok {
|
||||
return x.StringValue
|
||||
if x != nil {
|
||||
if x, ok := x.Kind.(*Value_StringValue); ok {
|
||||
return x.StringValue
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Value) GetBoolValue() bool {
|
||||
if x, ok := x.GetKind().(*Value_BoolValue); ok {
|
||||
return x.BoolValue
|
||||
if x != nil {
|
||||
if x, ok := x.Kind.(*Value_BoolValue); ok {
|
||||
return x.BoolValue
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Value) GetStructValue() *Struct {
|
||||
if x, ok := x.GetKind().(*Value_StructValue); ok {
|
||||
return x.StructValue
|
||||
if x != nil {
|
||||
if x, ok := x.Kind.(*Value_StructValue); ok {
|
||||
return x.StructValue
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Value) GetListValue() *ListValue {
|
||||
if x, ok := x.GetKind().(*Value_ListValue); ok {
|
||||
return x.ListValue
|
||||
if x != nil {
|
||||
if x, ok := x.Kind.(*Value_ListValue); ok {
|
||||
return x.ListValue
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -582,12 +592,11 @@ func (*Value_ListValue) isValue_Kind() {}
|
||||
//
|
||||
// The JSON representation for `ListValue` is JSON array.
|
||||
type ListValue struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Repeated field of dynamically typed values.
|
||||
Values []*Value `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"`
|
||||
Values []*Value `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// NewList constructs a ListValue from a general-purpose Go slice.
|
||||
|
||||
+4
-5
@@ -170,10 +170,7 @@ import (
|
||||
// http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
|
||||
// ) to obtain a formatter capable of generating timestamps in this format.
|
||||
type Timestamp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Represents seconds of UTC time since Unix epoch
|
||||
// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
||||
// 9999-12-31T23:59:59Z inclusive.
|
||||
@@ -182,7 +179,9 @@ type Timestamp struct {
|
||||
// second values with fractions must still have non-negative nanos values
|
||||
// that count forward in time. Must be from 0 to 999,999,999
|
||||
// inclusive.
|
||||
Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
|
||||
Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// Now constructs a new Timestamp from the current time.
|
||||
|
||||
+36
-45
@@ -54,12 +54,11 @@ import (
|
||||
//
|
||||
// The JSON representation for `DoubleValue` is JSON number.
|
||||
type DoubleValue struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The double value.
|
||||
Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// Double stores v in a new DoubleValue and returns a pointer to it.
|
||||
@@ -108,12 +107,11 @@ func (x *DoubleValue) GetValue() float64 {
|
||||
//
|
||||
// The JSON representation for `FloatValue` is JSON number.
|
||||
type FloatValue struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The float value.
|
||||
Value float32 `protobuf:"fixed32,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value float32 `protobuf:"fixed32,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// Float stores v in a new FloatValue and returns a pointer to it.
|
||||
@@ -162,12 +160,11 @@ func (x *FloatValue) GetValue() float32 {
|
||||
//
|
||||
// The JSON representation for `Int64Value` is JSON string.
|
||||
type Int64Value struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The int64 value.
|
||||
Value int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// Int64 stores v in a new Int64Value and returns a pointer to it.
|
||||
@@ -216,12 +213,11 @@ func (x *Int64Value) GetValue() int64 {
|
||||
//
|
||||
// The JSON representation for `UInt64Value` is JSON string.
|
||||
type UInt64Value struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The uint64 value.
|
||||
Value uint64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value uint64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// UInt64 stores v in a new UInt64Value and returns a pointer to it.
|
||||
@@ -270,12 +266,11 @@ func (x *UInt64Value) GetValue() uint64 {
|
||||
//
|
||||
// The JSON representation for `Int32Value` is JSON number.
|
||||
type Int32Value struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The int32 value.
|
||||
Value int32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value int32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// Int32 stores v in a new Int32Value and returns a pointer to it.
|
||||
@@ -324,12 +319,11 @@ func (x *Int32Value) GetValue() int32 {
|
||||
//
|
||||
// The JSON representation for `UInt32Value` is JSON number.
|
||||
type UInt32Value struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The uint32 value.
|
||||
Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// UInt32 stores v in a new UInt32Value and returns a pointer to it.
|
||||
@@ -378,12 +372,11 @@ func (x *UInt32Value) GetValue() uint32 {
|
||||
//
|
||||
// The JSON representation for `BoolValue` is JSON `true` and `false`.
|
||||
type BoolValue struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The bool value.
|
||||
Value bool `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value bool `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// Bool stores v in a new BoolValue and returns a pointer to it.
|
||||
@@ -432,12 +425,11 @@ func (x *BoolValue) GetValue() bool {
|
||||
//
|
||||
// The JSON representation for `StringValue` is JSON string.
|
||||
type StringValue struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The string value.
|
||||
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// String stores v in a new StringValue and returns a pointer to it.
|
||||
@@ -486,12 +478,11 @@ func (x *StringValue) GetValue() string {
|
||||
//
|
||||
// The JSON representation for `BytesValue` is JSON string.
|
||||
type BytesValue struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// The bytes value.
|
||||
Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
// Bytes stores v in a new BytesValue and returns a pointer to it.
|
||||
|
||||
Vendored
+19
-18
@@ -134,8 +134,8 @@ github.com/google/uuid
|
||||
# github.com/gorilla/mux v1.8.1
|
||||
## explicit; go 1.20
|
||||
github.com/gorilla/mux
|
||||
# github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0
|
||||
## explicit; go 1.22.7
|
||||
# github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1
|
||||
## explicit; go 1.22.0
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2/runtime
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2/utilities
|
||||
@@ -319,13 +319,13 @@ go.opencensus.io/trace/tracestate
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/auto/sdk
|
||||
go.opentelemetry.io/auto/sdk/internal/telemetry
|
||||
# go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0
|
||||
# go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconvutil
|
||||
# go.opentelemetry.io/otel v1.33.0
|
||||
# go.opentelemetry.io/otel v1.34.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/otel
|
||||
go.opentelemetry.io/otel/attribute
|
||||
@@ -341,23 +341,23 @@ go.opentelemetry.io/otel/semconv/v1.20.0
|
||||
go.opentelemetry.io/otel/semconv/v1.21.0
|
||||
go.opentelemetry.io/otel/semconv/v1.26.0
|
||||
go.opentelemetry.io/otel/semconv/v1.7.0
|
||||
# go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0
|
||||
## explicit; go 1.22.7
|
||||
# go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform
|
||||
# go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0
|
||||
## explicit; go 1.22.7
|
||||
# go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/envconfig
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/retry
|
||||
# go.opentelemetry.io/otel/metric v1.33.0
|
||||
# go.opentelemetry.io/otel/metric v1.34.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/otel/metric
|
||||
go.opentelemetry.io/otel/metric/embedded
|
||||
go.opentelemetry.io/otel/metric/noop
|
||||
# go.opentelemetry.io/otel/sdk v1.33.0
|
||||
# go.opentelemetry.io/otel/sdk v1.34.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/otel/sdk
|
||||
go.opentelemetry.io/otel/sdk/instrumentation
|
||||
@@ -366,13 +366,13 @@ go.opentelemetry.io/otel/sdk/internal/x
|
||||
go.opentelemetry.io/otel/sdk/resource
|
||||
go.opentelemetry.io/otel/sdk/trace
|
||||
go.opentelemetry.io/otel/sdk/trace/tracetest
|
||||
# go.opentelemetry.io/otel/trace v1.33.0
|
||||
# go.opentelemetry.io/otel/trace v1.34.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/otel/trace
|
||||
go.opentelemetry.io/otel/trace/embedded
|
||||
go.opentelemetry.io/otel/trace/noop
|
||||
# go.opentelemetry.io/proto/otlp v1.4.0
|
||||
## explicit; go 1.22.7
|
||||
# go.opentelemetry.io/proto/otlp v1.5.0
|
||||
## explicit; go 1.22.0
|
||||
go.opentelemetry.io/proto/otlp/collector/trace/v1
|
||||
go.opentelemetry.io/proto/otlp/common/v1
|
||||
go.opentelemetry.io/proto/otlp/resource/v1
|
||||
@@ -455,11 +455,11 @@ golang.org/x/tools/internal/stdlib
|
||||
golang.org/x/tools/internal/tokeninternal
|
||||
golang.org/x/tools/internal/typesinternal
|
||||
golang.org/x/tools/internal/versions
|
||||
# google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576
|
||||
## explicit; go 1.21
|
||||
# google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f
|
||||
## explicit; go 1.22
|
||||
google.golang.org/genproto/googleapis/api/httpbody
|
||||
# google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576
|
||||
## explicit; go 1.21
|
||||
# google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f
|
||||
## explicit; go 1.22
|
||||
google.golang.org/genproto/googleapis/rpc/errdetails
|
||||
google.golang.org/genproto/googleapis/rpc/status
|
||||
# google.golang.org/grpc v1.69.4
|
||||
@@ -523,7 +523,7 @@ google.golang.org/grpc/serviceconfig
|
||||
google.golang.org/grpc/stats
|
||||
google.golang.org/grpc/status
|
||||
google.golang.org/grpc/tap
|
||||
# google.golang.org/protobuf v1.35.2
|
||||
# google.golang.org/protobuf v1.36.3
|
||||
## explicit; go 1.21
|
||||
google.golang.org/protobuf/encoding/protodelim
|
||||
google.golang.org/protobuf/encoding/protojson
|
||||
@@ -547,6 +547,7 @@ google.golang.org/protobuf/internal/genid
|
||||
google.golang.org/protobuf/internal/impl
|
||||
google.golang.org/protobuf/internal/order
|
||||
google.golang.org/protobuf/internal/pragma
|
||||
google.golang.org/protobuf/internal/protolazy
|
||||
google.golang.org/protobuf/internal/set
|
||||
google.golang.org/protobuf/internal/strs
|
||||
google.golang.org/protobuf/internal/version
|
||||
|
||||
Reference in New Issue
Block a user