Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

77 changed files with 786 additions and 585 deletions

View file

@ -13,7 +13,7 @@ jobs:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '1.23' go-version: '1.21'
- name: Run commit format checker - name: Run commit format checker
uses: https://git.frostfs.info/TrueCloudLab/dco-go@v3 uses: https://git.frostfs.info/TrueCloudLab/dco-go@v3

View file

@ -11,7 +11,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '1.23' go-version: '1.20'
cache: true cache: true
- name: golangci-lint - name: golangci-lint
@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
go_versions: [ '1.22', '1.23' ] go_versions: [ '1.19', '1.20' ]
fail-fast: false fail-fast: false
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -47,7 +47,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: '1.23' go-version: '1.20'
cache: true cache: true
- name: Run tests - name: Run tests

View file

@ -50,7 +50,7 @@ linters:
- bidichk - bidichk
- durationcheck - durationcheck
- exhaustive - exhaustive
- copyloopvar - exportloopref
- gofmt - gofmt
- goimports - goimports
- misspell - misspell

View file

@ -37,6 +37,6 @@ repos:
language: system language: system
- repo: https://github.com/golangci/golangci-lint - repo: https://github.com/golangci/golangci-lint
rev: v1.60.3 rev: v1.56.2
hooks: hooks:
- id: golangci-lint - id: golangci-lint

View file

@ -47,4 +47,4 @@ Initial public release.
This project is a fork of [NeoFS](https://github.com/nspcc-dev/neofs-api-go) from version v2.14.0. This project is a fork of [NeoFS](https://github.com/nspcc-dev/neofs-api-go) from version v2.14.0.
To see CHANGELOG for older versions, refer to https://github.com/nspcc-dev/neofs-api-go/blob/master/CHANGELOG.md. To see CHANGELOG for older versions, refer to https://github.com/nspcc-dev/neofs-api-go/blob/master/CHANGELOG.md.
[Unreleased]: https://git.frostfs.info/TrueCloudLab/frostfs-api-go/compare/v2.16.0...master [Unreleased]: https://github.com/TrueCloudLab/compare/v2.15.0...master

View file

@ -3,8 +3,8 @@
First, thank you for contributing! We love and encourage pull requests from First, thank you for contributing! We love and encourage pull requests from
everyone. Please follow the guidelines: everyone. Please follow the guidelines:
- Check the open [issues](https://git.frostfs.info/TrueCloudLab/frostfs-api-go/issues) and - Check the open [issues](https://github.com/TrueCloudLab/frostfs-api-go/issues) and
[pull requests](https://git.frostfs.info/TrueCloudLab/frostfs-api-go/pulls) for existing [pull requests](https://github.com/TrueCloudLab/frostfs-api-go/pulls) for existing
discussions. discussions.
- Open an issue first, to discuss a new feature or enhancement. - Open an issue first, to discuss a new feature or enhancement.
@ -26,18 +26,18 @@ send a pull request. We encourage pull requests to discuss code changes. Here
are the steps in details: are the steps in details:
### Set up your GitHub Repository ### Set up your GitHub Repository
Fork [FrostFS node upstream](https://git.frostfs.info/TrueCloudLab/frostfs-api-go/fork) source Fork [FrostFS node upstream](https://github.com/TrueCloudLab/frostfs-api-go/fork) source
repository to your own personal repository. Copy the URL of your fork (you will repository to your own personal repository. Copy the URL of your fork (you will
need it for the `git clone` command below). need it for the `git clone` command below).
```sh ```sh
$ git clone https://git.frostfs.info/TrueCloudLab/frostfs-api-go $ git clone https://github.com/TrueCloudLab/frostfs-api-go
``` ```
### Set up git remote as ``upstream`` ### Set up git remote as ``upstream``
```sh ```sh
$ cd frostfs-api-go $ cd frostfs-api-go
$ git remote add upstream https://git.frostfs.info/TrueCloudLab/frostfs-api-go $ git remote add upstream https://github.com/TrueCloudLab/frostfs-api-go
$ git fetch upstream $ git fetch upstream
$ git merge upstream/master $ git merge upstream/master
... ...

View file

@ -79,7 +79,6 @@ $(BIN)/protogen:
protoc-test: protoc $(BIN)/protogen protoc-test: protoc $(BIN)/protogen
@$(PROTOC_DIR)/bin/protoc \ @$(PROTOC_DIR)/bin/protoc \
--go_out=. --go_opt=paths=source_relative \
--plugin=protoc-gen-go-frostfs=$(abspath $(BIN)/protogen) \ --plugin=protoc-gen-go-frostfs=$(abspath $(BIN)/protogen) \
--go-frostfs_opt=Mutil/proto/test/test.proto=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/test/custom \ --go-frostfs_opt=Mutil/proto/test/test.proto=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/test/custom \
--go-frostfs_opt=module=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 \ --go-frostfs_opt=module=git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 \

View file

@ -6,20 +6,22 @@
</p> </p>
--- ---
![Tests](https://git.frostfs.info/TrueCloudLab/frostfs-api-go/badges/workflows/tests.yml/badge.svg) ![Tests](https://github.com/TrueCloudLab/frostfs-api-go/workflows/frostfs-api-go%20tests/badge.svg)
[![Report](https://goreportcard.com/badge/git.frostfs.info/TrueCloudLab/frostfs-api-go)](https://goreportcard.com/report/git.frostfs.info/TrueCloudLab/frostfs-api-go) [![codecov](https://codecov.io/gh/TrueCloudLab/frostfs-api-go/branch/master/graph/badge.svg)](https://codecov.io/gh/TrueCloudLab/frostfs-api-go)
[![Release](https://git.frostfs.info/TrueCloudLab/frostfs-api-go/badges/release.svg)](https://git.frostfs.info/TrueCloudLab/frostfs-api-go) [![Report](https://goreportcard.com/badge/github.com/TrueCloudLab/frostfs-api-go)](https://goreportcard.com/report/github.com/TrueCloudLab/frostfs-api-go)
[![GitHub release](https://img.shields.io/github/release/TrueCloudLab/frostfs-api-go.svg)](https://github.com/TrueCloudLab/frostfs-api-go)
![GitHub license](https://img.shields.io/github/license/TrueCloudLab/frostfs-api-go.svg?style=popout)
# Overview # Overview
Go implementation of recent [FrostFS API](https://git.frostfs.info/TrueCloudLab/frostfs-api) Go implementation of recent [FrostFS API](https://github.com/TrueCloudLab/frostfs-api)
versions. For a more high-level SDK see [FrostFS SDK](https://git.frostfs.info/TrueCloudLab/frostfs-sdk-go). versions. For a more high-level SDK see [FrostFS SDK](https://github.com/TrueCloudLab/frostfs-sdk-go).
## Frostfs-Api compatibility ## Frostfs-Api compatibility
|frostfs-api-go version|supported frostfs-api versions| |frostfs-api-go version|supported frostfs-api versions|
|:------------------:|:--------------------------:| |:------------------:|:--------------------------:|
|v2.14.x|[v2.14.0](https://git.frostfs.info/TrueCloudLab/frostfs-api/releases/tag/v2.14.0)| |v2.14.x|[v2.14.0](https://github.com/TrueCloudLab/frostfs-api/releases/tag/v2.14.0)|
## Contributing ## Contributing

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -32,7 +32,7 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) {
b.Run("to grpc message", func(b *testing.B) { b.Run("to grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
raw := tb.ToGRPCMessage() raw := tb.ToGRPCMessage()
if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) { if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) {
b.FailNow() b.FailNow()
@ -41,7 +41,7 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) {
}) })
b.Run("from grpc message", func(b *testing.B) { b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
tb := new(acl.Table) tb := new(acl.Table)
if tb.FromGRPCMessage(raw) != nil { if tb.FromGRPCMessage(raw) != nil {
b.FailNow() b.FailNow()

View file

@ -187,26 +187,28 @@ func (f *HeaderFilter) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func HeaderFiltersToGRPC(fs []HeaderFilter) (res []acl.EACLRecord_Filter) { func HeaderFiltersToGRPC(fs []HeaderFilter) (res []*acl.EACLRecord_Filter) {
if fs != nil { if fs != nil {
res = make([]acl.EACLRecord_Filter, 0, len(fs)) res = make([]*acl.EACLRecord_Filter, 0, len(fs))
for i := range fs { for i := range fs {
res = append(res, *fs[i].ToGRPCMessage().(*acl.EACLRecord_Filter)) res = append(res, fs[i].ToGRPCMessage().(*acl.EACLRecord_Filter))
} }
} }
return return
} }
func HeaderFiltersFromGRPC(fs []acl.EACLRecord_Filter) (res []HeaderFilter, err error) { func HeaderFiltersFromGRPC(fs []*acl.EACLRecord_Filter) (res []HeaderFilter, err error) {
if fs != nil { if fs != nil {
res = make([]HeaderFilter, len(fs)) res = make([]HeaderFilter, len(fs))
for i := range fs { for i := range fs {
err = res[i].FromGRPCMessage(&fs[i]) if fs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(fs[i])
return if err != nil {
return
}
} }
} }
} }
@ -239,26 +241,28 @@ func (t *Target) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func TargetsToGRPC(ts []Target) (res []acl.EACLRecord_Target) { func TargetsToGRPC(ts []Target) (res []*acl.EACLRecord_Target) {
if ts != nil { if ts != nil {
res = make([]acl.EACLRecord_Target, 0, len(ts)) res = make([]*acl.EACLRecord_Target, 0, len(ts))
for i := range ts { for i := range ts {
res = append(res, *ts[i].ToGRPCMessage().(*acl.EACLRecord_Target)) res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord_Target))
} }
} }
return return
} }
func TargetsFromGRPC(fs []acl.EACLRecord_Target) (res []Target, err error) { func TargetsFromGRPC(fs []*acl.EACLRecord_Target) (res []Target, err error) {
if fs != nil { if fs != nil {
res = make([]Target, len(fs)) res = make([]Target, len(fs))
for i := range fs { for i := range fs {
err = res[i].FromGRPCMessage(&fs[i]) if fs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(fs[i])
return if err != nil {
return
}
} }
} }
} }
@ -305,26 +309,28 @@ func (r *Record) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func RecordsToGRPC(ts []Record) (res []acl.EACLRecord) { func RecordsToGRPC(ts []Record) (res []*acl.EACLRecord) {
if ts != nil { if ts != nil {
res = make([]acl.EACLRecord, 0, len(ts)) res = make([]*acl.EACLRecord, 0, len(ts))
for i := range ts { for i := range ts {
res = append(res, *ts[i].ToGRPCMessage().(*acl.EACLRecord)) res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord))
} }
} }
return return
} }
func RecordsFromGRPC(fs []acl.EACLRecord) (res []Record, err error) { func RecordsFromGRPC(fs []*acl.EACLRecord) (res []Record, err error) {
if fs != nil { if fs != nil {
res = make([]Record, len(fs)) res = make([]Record, len(fs))
for i := range fs { for i := range fs {
err = res[i].FromGRPCMessage(&fs[i]) if fs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(fs[i])
return if err != nil {
return
}
} }
} }
} }
@ -423,9 +429,9 @@ func (c *APEOverride) ToGRPCMessage() grpc.Message {
m.SetTarget(c.target.ToGRPCMessage().(*apeGRPC.ChainTarget)) m.SetTarget(c.target.ToGRPCMessage().(*apeGRPC.ChainTarget))
if len(c.chains) > 0 { if len(c.chains) > 0 {
apeChains := make([]apeGRPC.Chain, len(c.chains)) apeChains := make([]*apeGRPC.Chain, len(c.chains))
for i := range c.chains { for i := range c.chains {
apeChains[i] = *c.chains[i].ToGRPCMessage().(*apeGRPC.Chain) apeChains[i] = c.chains[i].ToGRPCMessage().(*apeGRPC.Chain)
} }
m.SetChains(apeChains) m.SetChains(apeChains)
} }
@ -453,7 +459,7 @@ func (c *APEOverride) FromGRPCMessage(m grpc.Message) error {
c.chains = make([]*ape.Chain, len(apeChains)) c.chains = make([]*ape.Chain, len(apeChains))
for i := range apeChains { for i := range apeChains {
c.chains[i] = new(ape.Chain) c.chains[i] = new(ape.Chain)
if err := c.chains[i].FromGRPCMessage(&apeChains[i]); err != nil { if err := c.chains[i].FromGRPCMessage(apeChains[i]); err != nil {
return err return err
} }
} }

Binary file not shown.

View file

@ -330,18 +330,10 @@ func (bt *BearerTokenBody) SetEACL(v *Table) {
} }
func (t *APEOverride) GetTarget() *ape.ChainTarget { func (t *APEOverride) GetTarget() *ape.ChainTarget {
if t == nil {
return nil
}
return t.target return t.target
} }
func (t *APEOverride) GetChains() []*ape.Chain { func (t *APEOverride) GetChains() []*ape.Chain {
if t == nil {
return nil
}
return t.chains return t.chains
} }

Binary file not shown.

View file

@ -53,10 +53,6 @@ func (c *Chain) SetKind(kind chainKind) {
} }
func (c *Chain) GetKind() chainKind { func (c *Chain) GetKind() chainKind {
if c == nil {
return nil
}
return c.kind return c.kind
} }
@ -71,9 +67,5 @@ func (c *ChainRaw) SetRaw(raw []byte) {
} }
func (c *ChainRaw) GetRaw() []byte { func (c *ChainRaw) GetRaw() []byte {
if c == nil {
return nil
}
return c.Raw return c.Raw
} }

View file

@ -296,9 +296,9 @@ func (respBody *ListChainsResponseBody) ToGRPCMessage() grpc.Message {
if respBody != nil { if respBody != nil {
respBodygrpc = new(apemanager.ListChainsResponse_Body) respBodygrpc = new(apemanager.ListChainsResponse_Body)
chainsgrpc := make([]apeGRPC.Chain, 0, len(respBody.GetChains())) chainsgrpc := make([]*apeGRPC.Chain, 0, len(respBody.GetChains()))
for _, chain := range respBody.GetChains() { for _, chain := range respBody.GetChains() {
chainsgrpc = append(chainsgrpc, *chain.ToGRPCMessage().(*apeGRPC.Chain)) chainsgrpc = append(chainsgrpc, chain.ToGRPCMessage().(*apeGRPC.Chain))
} }
respBodygrpc.SetChains(chainsgrpc) respBodygrpc.SetChains(chainsgrpc)
@ -317,7 +317,7 @@ func (respBody *ListChainsResponseBody) FromGRPCMessage(m grpc.Message) error {
for _, chaingrpc := range respBodygrpc.GetChains() { for _, chaingrpc := range respBodygrpc.GetChains() {
chain := new(ape.Chain) chain := new(ape.Chain)
if err := chain.FromGRPCMessage(&chaingrpc); err != nil { if err := chain.FromGRPCMessage(chaingrpc); err != nil {
return err return err
} }
chains = append(chains, chain) chains = append(chains, chain)

Binary file not shown.

View file

@ -16,10 +16,6 @@ func (r *AddChainRequest) SetBody(body *AddChainRequestBody) {
} }
func (r *AddChainRequest) GetBody() *AddChainRequestBody { func (r *AddChainRequest) GetBody() *AddChainRequestBody {
if r == nil {
return nil
}
return r.body return r.body
} }
@ -34,10 +30,6 @@ func (rb *AddChainRequestBody) SetTarget(target *ape.ChainTarget) {
} }
func (rb *AddChainRequestBody) GetTarget() *ape.ChainTarget { func (rb *AddChainRequestBody) GetTarget() *ape.ChainTarget {
if rb == nil {
return nil
}
return rb.target return rb.target
} }
@ -46,10 +38,6 @@ func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) {
} }
func (rb *AddChainRequestBody) GetChain() *ape.Chain { func (rb *AddChainRequestBody) GetChain() *ape.Chain {
if rb == nil {
return nil
}
return rb.chain return rb.chain
} }
@ -64,10 +52,6 @@ func (r *AddChainResponse) SetBody(body *AddChainResponseBody) {
} }
func (r *AddChainResponse) GetBody() *AddChainResponseBody { func (r *AddChainResponse) GetBody() *AddChainResponseBody {
if r == nil {
return nil
}
return r.body return r.body
} }
@ -80,10 +64,6 @@ func (rb *AddChainResponseBody) SetChainID(chainID []byte) {
} }
func (rb *AddChainResponseBody) GetChainID() []byte { func (rb *AddChainResponseBody) GetChainID() []byte {
if rb == nil {
return nil
}
return rb.chainID return rb.chainID
} }
@ -98,10 +78,6 @@ func (r *RemoveChainRequest) SetBody(body *RemoveChainRequestBody) {
} }
func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody { func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody {
if r == nil {
return nil
}
return r.body return r.body
} }
@ -116,10 +92,6 @@ func (rb *RemoveChainRequestBody) SetTarget(target *ape.ChainTarget) {
} }
func (rb *RemoveChainRequestBody) GetTarget() *ape.ChainTarget { func (rb *RemoveChainRequestBody) GetTarget() *ape.ChainTarget {
if rb == nil {
return nil
}
return rb.target return rb.target
} }
@ -128,10 +100,6 @@ func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) {
} }
func (rb *RemoveChainRequestBody) GetChainID() []byte { func (rb *RemoveChainRequestBody) GetChainID() []byte {
if rb == nil {
return nil
}
return rb.chainID return rb.chainID
} }
@ -148,10 +116,6 @@ func (r *RemoveChainResponse) SetBody(body *RemoveChainResponseBody) {
} }
func (r *RemoveChainResponse) GetBody() *RemoveChainResponseBody { func (r *RemoveChainResponse) GetBody() *RemoveChainResponseBody {
if r == nil {
return nil
}
return r.body return r.body
} }
@ -166,10 +130,6 @@ func (r *ListChainsRequest) SetBody(body *ListChainsRequestBody) {
} }
func (r *ListChainsRequest) GetBody() *ListChainsRequestBody { func (r *ListChainsRequest) GetBody() *ListChainsRequestBody {
if r == nil {
return nil
}
return r.body return r.body
} }
@ -182,10 +142,6 @@ func (rb *ListChainsRequestBody) SetTarget(target *ape.ChainTarget) {
} }
func (rb *ListChainsRequestBody) GetTarget() *ape.ChainTarget { func (rb *ListChainsRequestBody) GetTarget() *ape.ChainTarget {
if rb == nil {
return nil
}
return rb.target return rb.target
} }
@ -200,10 +156,6 @@ func (r *ListChainsResponse) SetBody(body *ListChainsResponseBody) {
} }
func (r *ListChainsResponse) GetBody() *ListChainsResponseBody { func (r *ListChainsResponse) GetBody() *ListChainsResponseBody {
if r == nil {
return nil
}
return r.body return r.body
} }
@ -218,9 +170,5 @@ func (r *ListChainsResponseBody) SetChains(chains []*ape.Chain) {
} }
func (r *ListChainsResponseBody) GetChains() []*ape.Chain { func (r *ListChainsResponseBody) GetChains() []*ape.Chain {
if r == nil {
return nil
}
return r.chains return r.chains
} }

View file

@ -1,6 +1,8 @@
package container package container
import ( import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl"
aclGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc" container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
netmapGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc" netmapGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
@ -37,26 +39,28 @@ func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func AttributesToGRPC(xs []Attribute) (res []container.Container_Attribute) { func AttributesToGRPC(xs []Attribute) (res []*container.Container_Attribute) {
if xs != nil { if xs != nil {
res = make([]container.Container_Attribute, 0, len(xs)) res = make([]*container.Container_Attribute, 0, len(xs))
for i := range xs { for i := range xs {
res = append(res, *xs[i].ToGRPCMessage().(*container.Container_Attribute)) res = append(res, xs[i].ToGRPCMessage().(*container.Container_Attribute))
} }
} }
return return
} }
func AttributesFromGRPC(xs []container.Container_Attribute) (res []Attribute, err error) { func AttributesFromGRPC(xs []*container.Container_Attribute) (res []Attribute, err error) {
if xs != nil { if xs != nil {
res = make([]Attribute, len(xs)) res = make([]Attribute, len(xs))
for i := range xs { for i := range xs {
err = res[i].FromGRPCMessage(&xs[i]) if xs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(xs[i])
return if err != nil {
return
}
} }
} }
} }
@ -762,3 +766,175 @@ func (r *ListResponse) FromGRPCMessage(m grpc.Message) error {
return r.ResponseHeaders.FromMessage(v) return r.ResponseHeaders.FromMessage(v)
} }
func (r *GetExtendedACLRequestBody) ToGRPCMessage() grpc.Message {
var m *container.GetExtendedACLRequest_Body
if r != nil {
m = new(container.GetExtendedACLRequest_Body)
m.SetContainerId(r.cid.ToGRPCMessage().(*refsGRPC.ContainerID))
}
return m
}
func (r *GetExtendedACLRequestBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*container.GetExtendedACLRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
cid := v.GetContainerId()
if cid == nil {
r.cid = nil
} else {
if r.cid == nil {
r.cid = new(refs.ContainerID)
}
err = r.cid.FromGRPCMessage(cid)
}
return err
}
func (r *GetExtendedACLRequest) ToGRPCMessage() grpc.Message {
var m *container.GetExtendedACLRequest
if r != nil {
m = new(container.GetExtendedACLRequest)
m.SetBody(r.body.ToGRPCMessage().(*container.GetExtendedACLRequest_Body))
r.RequestHeaders.ToMessage(m)
}
return m
}
func (r *GetExtendedACLRequest) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*container.GetExtendedACLRequest)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
r.body = nil
} else {
if r.body == nil {
r.body = new(GetExtendedACLRequestBody)
}
err = r.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return r.RequestHeaders.FromMessage(v)
}
func (r *GetExtendedACLResponseBody) ToGRPCMessage() grpc.Message {
var m *container.GetExtendedACLResponse_Body
if r != nil {
m = new(container.GetExtendedACLResponse_Body)
m.SetEacl(r.eacl.ToGRPCMessage().(*aclGRPC.EACLTable))
m.SetSignature(toSignatureRFC6979(r.sig))
m.SetSessionToken(r.token.ToGRPCMessage().(*sessionGRPC.SessionToken))
}
return m
}
func (r *GetExtendedACLResponseBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*container.GetExtendedACLResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
eacl := v.GetEacl()
if eacl == nil {
r.eacl = nil
} else {
if r.eacl == nil {
r.eacl = new(acl.Table)
}
err = r.eacl.FromGRPCMessage(eacl)
if err != nil {
return err
}
}
sig := v.GetSignature()
if sig == nil {
r.sig = nil
} else {
if r.sig == nil {
r.sig = new(refs.Signature)
}
r.sig.SetKey(sig.GetKey())
r.sig.SetSign(sig.GetSign())
}
token := v.GetSessionToken()
if token == nil {
r.token = nil
} else {
if r.token == nil {
r.token = new(session.Token)
}
err = r.token.FromGRPCMessage(token)
}
return err
}
func (r *GetExtendedACLResponse) ToGRPCMessage() grpc.Message {
var m *container.GetExtendedACLResponse
if r != nil {
m = new(container.GetExtendedACLResponse)
m.SetBody(r.body.ToGRPCMessage().(*container.GetExtendedACLResponse_Body))
r.ResponseHeaders.ToMessage(m)
}
return m
}
func (r *GetExtendedACLResponse) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*container.GetExtendedACLResponse)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
r.body = nil
} else {
if r.body == nil {
r.body = new(GetExtendedACLResponseBody)
}
err = r.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return r.ResponseHeaders.FromMessage(v)
}

Binary file not shown.

View file

@ -157,3 +157,41 @@ func DoFuzzJSONListResponse(data []byte) int {
} }
return 1 return 1
} }
func DoFuzzProtoGetExtendedACLRequest(data []byte) int {
msg := new(GetExtendedACLRequest)
if err := msg.UnmarshalProtobuf(data); err != nil {
return 0
}
_ = msg.MarshalProtobuf(nil)
return 1
}
func DoFuzzJSONGetExtendedACLRequest(data []byte) int {
msg := new(GetExtendedACLRequest)
if err := msg.UnmarshalJSON(data); err != nil {
return 0
}
_, err := msg.MarshalJSON()
if err != nil {
panic(err)
}
return 1
}
func DoFuzzProtoGetExtendedACLResponse(data []byte) int {
msg := new(GetExtendedACLResponse)
if err := msg.UnmarshalProtobuf(data); err != nil {
return 0
}
_ = msg.MarshalProtobuf(nil)
return 1
}
func DoFuzzJSONGetExtendedACLResponse(data []byte) int {
msg := new(GetExtendedACLResponse)
if err := msg.UnmarshalJSON(data); err != nil {
return 0
}
_, err := msg.MarshalJSON()
if err != nil {
panic(err)
}
return 1
}

View file

@ -89,3 +89,23 @@ func FuzzJSONListResponse(f *testing.F) {
DoFuzzJSONListResponse(data) DoFuzzJSONListResponse(data)
}) })
} }
func FuzzProtoGetExtendedACLRequest(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
DoFuzzProtoGetExtendedACLRequest(data)
})
}
func FuzzJSONGetExtendedACLRequest(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
DoFuzzJSONGetExtendedACLRequest(data)
})
}
func FuzzProtoGetExtendedACLResponse(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
DoFuzzProtoGetExtendedACLResponse(data)
})
}
func FuzzJSONGetExtendedACLResponse(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
DoFuzzJSONGetExtendedACLResponse(data)
})
}

Binary file not shown.

Binary file not shown.

View file

@ -34,6 +34,12 @@ const (
listReqBodyOwnerField = 1 listReqBodyOwnerField = 1
listRespBodyIDsField = 1 listRespBodyIDsField = 1
getEACLReqBodyIDField = 1
getEACLRespBodyTableField = 1
getEACLRespBodySignatureField = 2
getEACLRespBodyTokenField = 3
) )
func (a *Attribute) StableMarshal(buf []byte) []byte { func (a *Attribute) StableMarshal(buf []byte) []byte {
@ -343,3 +349,65 @@ func (r *ListResponseBody) StableSize() (size int) {
func (r *ListResponseBody) Unmarshal(data []byte) error { func (r *ListResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.ListResponse_Body)) return message.Unmarshal(r, data, new(container.ListResponse_Body))
} }
func (r *GetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid)
return buf
}
func (r *GetExtendedACLRequestBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(getEACLReqBodyIDField, r.cid)
return size
}
func (r *GetExtendedACLRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetExtendedACLRequest_Body))
}
func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf[offset:], r.eacl)
offset += protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig)
protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf[offset:], r.token)
return buf
}
func (r *GetExtendedACLResponseBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(getEACLRespBodyTableField, r.eacl)
size += protoutil.NestedStructureSize(getEACLRespBodySignatureField, r.sig)
size += protoutil.NestedStructureSize(getEACLRespBodyTokenField, r.token)
return size
}
func (r *GetExtendedACLResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetExtendedACLResponse_Body))
}

View file

@ -32,5 +32,9 @@ func TestMessageConvert(t *testing.T) {
func(empty bool) message.Message { return containertest.GenerateGetRequest(empty) }, func(empty bool) message.Message { return containertest.GenerateGetRequest(empty) },
func(empty bool) message.Message { return containertest.GenerateGetResponseBody(empty) }, func(empty bool) message.Message { return containertest.GenerateGetResponseBody(empty) },
func(empty bool) message.Message { return containertest.GenerateGetResponse(empty) }, func(empty bool) message.Message { return containertest.GenerateGetResponse(empty) },
func(empty bool) message.Message { return containertest.GenerateGetExtendedACLRequestBody(empty) },
func(empty bool) message.Message { return containertest.GenerateGetExtendedACLRequest(empty) },
func(empty bool) message.Message { return containertest.GenerateGetExtendedACLResponseBody(empty) },
func(empty bool) message.Message { return containertest.GenerateGetExtendedACLResponse(empty) },
) )
} }

View file

@ -1,8 +1,7 @@
package containertest package containertest
import ( import (
"crypto/rand" acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test" netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
@ -37,11 +36,8 @@ func GenerateContainer(empty bool) *container.Container {
m := new(container.Container) m := new(container.Container)
if !empty { if !empty {
nonce := make([]byte, 16)
_, _ = rand.Read(nonce)
m.SetBasicACL(12) m.SetBasicACL(12)
m.SetNonce(nonce) m.SetNonce([]byte{1, 2, 3})
m.SetOwnerID(refstest.GenerateOwnerID(false)) m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetAttributes(GenerateAttributes(false)) m.SetAttributes(GenerateAttributes(false))
m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false)) m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false))
@ -238,3 +234,52 @@ func GenerateListResponse(empty bool) *container.ListResponse {
return m return m
} }
func GenerateGetExtendedACLRequestBody(empty bool) *container.GetExtendedACLRequestBody {
m := new(container.GetExtendedACLRequestBody)
if !empty {
m.SetContainerID(refstest.GenerateContainerID(false))
}
return m
}
func GenerateGetExtendedACLRequest(empty bool) *container.GetExtendedACLRequest {
m := new(container.GetExtendedACLRequest)
if !empty {
m.SetBody(GenerateGetExtendedACLRequestBody(false))
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateGetExtendedACLResponseBody(empty bool) *container.GetExtendedACLResponseBody {
m := new(container.GetExtendedACLResponseBody)
if !empty {
m.SetEACL(acltest.GenerateTable(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetSessionToken(sessiontest.GenerateSessionToken(empty))
return m
}
func GenerateGetExtendedACLResponse(empty bool) *container.GetExtendedACLResponse {
m := new(container.GetExtendedACLResponse)
if !empty {
m.SetBody(GenerateGetExtendedACLResponseBody(false))
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}

View file

@ -1,6 +1,7 @@
package container package container
import ( import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
@ -109,6 +110,30 @@ type ListResponse struct {
session.ResponseHeaders session.ResponseHeaders
} }
type GetExtendedACLRequestBody struct {
cid *refs.ContainerID
}
type GetExtendedACLRequest struct {
body *GetExtendedACLRequestBody
session.RequestHeaders
}
type GetExtendedACLResponseBody struct {
eacl *acl.Table
sig *refs.Signature
token *session.Token
}
type GetExtendedACLResponse struct {
body *GetExtendedACLResponseBody
session.ResponseHeaders
}
func (a *Attribute) GetKey() string { func (a *Attribute) GetKey() string {
if a != nil { if a != nil {
return a.key return a.key
@ -444,3 +469,81 @@ func (r *ListResponse) GetBody() *ListResponseBody {
func (r *ListResponse) SetBody(v *ListResponseBody) { func (r *ListResponse) SetBody(v *ListResponseBody) {
r.body = v r.body = v
} }
func (r *GetExtendedACLRequestBody) GetContainerID() *refs.ContainerID {
if r != nil {
return r.cid
}
return nil
}
func (r *GetExtendedACLRequestBody) SetContainerID(v *refs.ContainerID) {
r.cid = v
}
func (r *GetExtendedACLRequest) GetBody() *GetExtendedACLRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *GetExtendedACLRequest) SetBody(v *GetExtendedACLRequestBody) {
r.body = v
}
func (r *GetExtendedACLResponseBody) GetEACL() *acl.Table {
if r != nil {
return r.eacl
}
return nil
}
func (r *GetExtendedACLResponseBody) SetEACL(v *acl.Table) {
r.eacl = v
}
func (r *GetExtendedACLResponseBody) GetSignature() *refs.Signature {
if r != nil {
return r.sig
}
return nil
}
func (r *GetExtendedACLResponseBody) SetSignature(v *refs.Signature) {
// TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type)
v.SetScheme(0)
r.sig = v
}
// GetSessionToken returns token of the session within which requested
// eACL table was set.
func (r *GetExtendedACLResponseBody) GetSessionToken() *session.Token {
if r != nil {
return r.token
}
return nil
}
// SetSessionToken sets token of the session within which requested
// eACL table was set.
func (r *GetExtendedACLResponseBody) SetSessionToken(v *session.Token) {
r.token = v
}
func (r *GetExtendedACLResponse) GetBody() *GetExtendedACLResponseBody {
if r != nil {
return r.body
}
return nil
}
func (r *GetExtendedACLResponse) SetBody(v *GetExtendedACLResponseBody) {
r.body = v
}

16
go.mod
View file

@ -1,15 +1,15 @@
module git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 module git.frostfs.info/TrueCloudLab/frostfs-api-go/v2
go 1.22 go 1.20
require ( require (
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0
github.com/VictoriaMetrics/easyproto v0.1.4 github.com/VictoriaMetrics/easyproto v0.1.4
github.com/mailru/easyjson v0.7.7 github.com/mailru/easyjson v0.7.7
github.com/stretchr/testify v1.8.3 github.com/stretchr/testify v1.8.3
golang.org/x/sync v0.7.0 golang.org/x/sync v0.6.0
google.golang.org/grpc v1.66.2 google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.34.1 google.golang.org/protobuf v1.33.0
) )
require ( require (
@ -19,10 +19,10 @@ require (
github.com/kr/pretty v0.1.0 // indirect github.com/kr/pretty v0.1.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.26.0 // indirect golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )

29
go.sum
View file

@ -8,7 +8,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@ -26,20 +25,20 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

Binary file not shown.

View file

@ -45,26 +45,28 @@ func (f *Filter) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func FiltersToGRPC(fs []Filter) (res []netmap.Filter) { func FiltersToGRPC(fs []Filter) (res []*netmap.Filter) {
if fs != nil { if fs != nil {
res = make([]netmap.Filter, 0, len(fs)) res = make([]*netmap.Filter, 0, len(fs))
for i := range fs { for i := range fs {
res = append(res, *fs[i].ToGRPCMessage().(*netmap.Filter)) res = append(res, fs[i].ToGRPCMessage().(*netmap.Filter))
} }
} }
return return
} }
func FiltersFromGRPC(fs []netmap.Filter) (res []Filter, err error) { func FiltersFromGRPC(fs []*netmap.Filter) (res []Filter, err error) {
if fs != nil { if fs != nil {
res = make([]Filter, len(fs)) res = make([]Filter, len(fs))
for i := range fs { for i := range fs {
err = res[i].FromGRPCMessage(&fs[i]) if fs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(fs[i])
return if err != nil {
return
}
} }
} }
} }
@ -103,26 +105,28 @@ func (s *Selector) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func SelectorsToGRPC(ss []Selector) (res []netmap.Selector) { func SelectorsToGRPC(ss []Selector) (res []*netmap.Selector) {
if ss != nil { if ss != nil {
res = make([]netmap.Selector, 0, len(ss)) res = make([]*netmap.Selector, 0, len(ss))
for i := range ss { for i := range ss {
res = append(res, *ss[i].ToGRPCMessage().(*netmap.Selector)) res = append(res, ss[i].ToGRPCMessage().(*netmap.Selector))
} }
} }
return return
} }
func SelectorsFromGRPC(ss []netmap.Selector) (res []Selector, err error) { func SelectorsFromGRPC(ss []*netmap.Selector) (res []Selector, err error) {
if ss != nil { if ss != nil {
res = make([]Selector, len(ss)) res = make([]Selector, len(ss))
for i := range ss { for i := range ss {
err = res[i].FromGRPCMessage(&ss[i]) if ss[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(ss[i])
return if err != nil {
return
}
} }
} }
} }
@ -159,26 +163,28 @@ func (r *Replica) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func ReplicasToGRPC(rs []Replica) (res []netmap.Replica) { func ReplicasToGRPC(rs []Replica) (res []*netmap.Replica) {
if rs != nil { if rs != nil {
res = make([]netmap.Replica, 0, len(rs)) res = make([]*netmap.Replica, 0, len(rs))
for i := range rs { for i := range rs {
res = append(res, *rs[i].ToGRPCMessage().(*netmap.Replica)) res = append(res, rs[i].ToGRPCMessage().(*netmap.Replica))
} }
} }
return return
} }
func ReplicasFromGRPC(rs []netmap.Replica) (res []Replica, err error) { func ReplicasFromGRPC(rs []*netmap.Replica) (res []Replica, err error) {
if rs != nil { if rs != nil {
res = make([]Replica, len(rs)) res = make([]Replica, len(rs))
for i := range rs { for i := range rs {
err = res[i].FromGRPCMessage(&rs[i]) if rs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(rs[i])
return if err != nil {
return
}
} }
} }
} }
@ -283,26 +289,28 @@ func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func AttributesToGRPC(as []Attribute) (res []netmap.NodeInfo_Attribute) { func AttributesToGRPC(as []Attribute) (res []*netmap.NodeInfo_Attribute) {
if as != nil { if as != nil {
res = make([]netmap.NodeInfo_Attribute, 0, len(as)) res = make([]*netmap.NodeInfo_Attribute, 0, len(as))
for i := range as { for i := range as {
res = append(res, *as[i].ToGRPCMessage().(*netmap.NodeInfo_Attribute)) res = append(res, as[i].ToGRPCMessage().(*netmap.NodeInfo_Attribute))
} }
} }
return return
} }
func AttributesFromGRPC(as []netmap.NodeInfo_Attribute) (res []Attribute, err error) { func AttributesFromGRPC(as []*netmap.NodeInfo_Attribute) (res []Attribute, err error) {
if as != nil { if as != nil {
res = make([]Attribute, len(as)) res = make([]Attribute, len(as))
for i := range as { for i := range as {
err = res[i].FromGRPCMessage(&as[i]) if as[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(as[i])
return if err != nil {
return
}
} }
} }
} }
@ -520,13 +528,13 @@ func (x *NetworkConfig) ToGRPCMessage() grpc.Message {
if x != nil { if x != nil {
m = new(netmap.NetworkConfig) m = new(netmap.NetworkConfig)
var ps []netmap.NetworkConfig_Parameter var ps []*netmap.NetworkConfig_Parameter
if ln := len(x.ps); ln > 0 { if ln := len(x.ps); ln > 0 {
ps = make([]netmap.NetworkConfig_Parameter, 0, ln) ps = make([]*netmap.NetworkConfig_Parameter, 0, ln)
for i := range ln { for i := 0; i < ln; i++ {
ps = append(ps, *x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter)) ps = append(ps, x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter))
} }
} }
@ -552,9 +560,11 @@ func (x *NetworkConfig) FromGRPCMessage(m grpc.Message) error {
ps = make([]NetworkParameter, ln) ps = make([]NetworkParameter, ln)
for i := range ln { for i := 0; i < ln; i++ {
if err := ps[i].FromGRPCMessage(&psV2[i]); err != nil { if psV2[i] != nil {
return err if err := ps[i].FromGRPCMessage(psV2[i]); err != nil {
return err
}
} }
} }
} }
@ -746,10 +756,10 @@ func (x *NetMap) ToGRPCMessage() grpc.Message {
m.SetEpoch(x.epoch) m.SetEpoch(x.epoch)
if x.nodes != nil { if x.nodes != nil {
nodes := make([]netmap.NodeInfo, len(x.nodes)) nodes := make([]*netmap.NodeInfo, len(x.nodes))
for i := range x.nodes { for i := range x.nodes {
nodes[i] = *x.nodes[i].ToGRPCMessage().(*netmap.NodeInfo) nodes[i] = x.nodes[i].ToGRPCMessage().(*netmap.NodeInfo)
} }
m.SetNodes(nodes) m.SetNodes(nodes)
@ -774,7 +784,7 @@ func (x *NetMap) FromGRPCMessage(m grpc.Message) error {
x.nodes = make([]NodeInfo, len(nodes)) x.nodes = make([]NodeInfo, len(nodes))
for i := range nodes { for i := range nodes {
err = x.nodes[i].FromGRPCMessage(&nodes[i]) err = x.nodes[i].FromGRPCMessage(nodes[i])
if err != nil { if err != nil {
return err return err
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -335,10 +335,6 @@ func (p *PlacementPolicy) SetContainerBackupFactor(backupFactor uint32) {
} }
func (p *PlacementPolicy) GetReplicas() []Replica { func (p *PlacementPolicy) GetReplicas() []Replica {
if p == nil {
return nil
}
return p.replicas return p.replicas
} }

View file

@ -26,7 +26,7 @@ func BenchmarkAttributesMarshal(b *testing.B) {
b.Run("marshal", func(b *testing.B) { b.Run("marshal", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
res := AttributesToGRPC(attrs) res := AttributesToGRPC(attrs)
if len(res) != len(raw) { if len(res) != len(raw) {
b.FailNow() b.FailNow()
@ -35,7 +35,7 @@ func BenchmarkAttributesMarshal(b *testing.B) {
}) })
b.Run("unmarshal", func(b *testing.B) { b.Run("unmarshal", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
res, err := AttributesFromGRPC(raw) res, err := AttributesFromGRPC(raw)
if err != nil || len(res) != len(raw) { if err != nil || len(res) != len(raw) {
b.FailNow() b.FailNow()

View file

@ -142,26 +142,28 @@ func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func AttributesToGRPC(xs []Attribute) (res []object.Header_Attribute) { func AttributesToGRPC(xs []Attribute) (res []*object.Header_Attribute) {
if xs != nil { if xs != nil {
res = make([]object.Header_Attribute, 0, len(xs)) res = make([]*object.Header_Attribute, 0, len(xs))
for i := range xs { for i := range xs {
res = append(res, *xs[i].ToGRPCMessage().(*object.Header_Attribute)) res = append(res, xs[i].ToGRPCMessage().(*object.Header_Attribute))
} }
} }
return return
} }
func AttributesFromGRPC(xs []object.Header_Attribute) (res []Attribute, err error) { func AttributesFromGRPC(xs []*object.Header_Attribute) (res []Attribute, err error) {
if xs != nil { if xs != nil {
res = make([]Attribute, len(xs)) res = make([]Attribute, len(xs))
for i := range xs { for i := range xs {
err = res[i].FromGRPCMessage(&xs[i]) if xs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(xs[i])
return if err != nil {
return
}
} }
} }
} }
@ -681,9 +683,9 @@ func (s *ECInfo) ToGRPCMessage() grpc.Message {
m = new(object.ECInfo) m = new(object.ECInfo)
if s.Chunks != nil { if s.Chunks != nil {
chunks := make([]object.ECInfo_Chunk, len(s.Chunks)) chunks := make([]*object.ECInfo_Chunk, len(s.Chunks))
for i := range chunks { for i := range chunks {
chunks[i] = *s.Chunks[i].ToGRPCMessage().(*object.ECInfo_Chunk) chunks[i] = s.Chunks[i].ToGRPCMessage().(*object.ECInfo_Chunk)
} }
m.Chunks = chunks m.Chunks = chunks
} }
@ -704,7 +706,7 @@ func (s *ECInfo) FromGRPCMessage(m grpc.Message) error {
} else { } else {
s.Chunks = make([]ECChunk, len(chunks)) s.Chunks = make([]ECChunk, len(chunks))
for i := range chunks { for i := range chunks {
if err := s.Chunks[i].FromGRPCMessage(&chunks[i]); err != nil { if err := s.Chunks[i].FromGRPCMessage(chunks[i]); err != nil {
return err return err
} }
} }
@ -1624,26 +1626,28 @@ func (f *SearchFilter) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func SearchFiltersToGRPC(fs []SearchFilter) (res []object.SearchRequest_Body_Filter) { func SearchFiltersToGRPC(fs []SearchFilter) (res []*object.SearchRequest_Body_Filter) {
if fs != nil { if fs != nil {
res = make([]object.SearchRequest_Body_Filter, 0, len(fs)) res = make([]*object.SearchRequest_Body_Filter, 0, len(fs))
for i := range fs { for i := range fs {
res = append(res, *fs[i].ToGRPCMessage().(*object.SearchRequest_Body_Filter)) res = append(res, fs[i].ToGRPCMessage().(*object.SearchRequest_Body_Filter))
} }
} }
return return
} }
func SearchFiltersFromGRPC(fs []object.SearchRequest_Body_Filter) (res []SearchFilter, err error) { func SearchFiltersFromGRPC(fs []*object.SearchRequest_Body_Filter) (res []SearchFilter, err error) {
if fs != nil { if fs != nil {
res = make([]SearchFilter, len(fs)) res = make([]SearchFilter, len(fs))
for i := range fs { for i := range fs {
err = res[i].FromGRPCMessage(&fs[i]) if fs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(fs[i])
return if err != nil {
return
}
} }
} }
} }
@ -1823,26 +1827,28 @@ func (r *Range) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func RangesToGRPC(rs []Range) (res []object.Range) { func RangesToGRPC(rs []Range) (res []*object.Range) {
if rs != nil { if rs != nil {
res = make([]object.Range, 0, len(rs)) res = make([]*object.Range, 0, len(rs))
for i := range rs { for i := range rs {
res = append(res, *rs[i].ToGRPCMessage().(*object.Range)) res = append(res, rs[i].ToGRPCMessage().(*object.Range))
} }
} }
return return
} }
func RangesFromGRPC(rs []object.Range) (res []Range, err error) { func RangesFromGRPC(rs []*object.Range) (res []Range, err error) {
if rs != nil { if rs != nil {
res = make([]Range, len(rs)) res = make([]Range, len(rs))
for i := range rs { for i := range rs {
err = res[i].FromGRPCMessage(&rs[i]) if rs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(rs[i])
return if err != nil {
return
}
} }
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -89,13 +89,13 @@ func (x *Lock) ToGRPCMessage() grpc.Message {
if x != nil { if x != nil {
m = new(lock.Lock) m = new(lock.Lock)
var members []refsGRPC.ObjectID var members []*refsGRPC.ObjectID
if x.members != nil { if x.members != nil {
members = make([]refsGRPC.ObjectID, len(x.members)) members = make([]*refsGRPC.ObjectID, len(x.members))
for i := range x.members { for i := range x.members {
members[i] = *x.members[i].ToGRPCMessage().(*refsGRPC.ObjectID) members[i] = x.members[i].ToGRPCMessage().(*refsGRPC.ObjectID)
} }
} }
@ -119,7 +119,7 @@ func (x *Lock) FromGRPCMessage(m grpc.Message) error {
var err error var err error
for i := range x.members { for i := range x.members {
err = x.members[i].FromGRPCMessage(&members[i]) err = x.members[i].FromGRPCMessage(members[i])
if err != nil { if err != nil {
return err return err
} }

View file

@ -1,7 +1,6 @@
package objecttest package objecttest
import ( import (
crand "crypto/rand"
"math/rand" "math/rand"
"time" "time"
@ -60,10 +59,7 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader {
m := new(object.SplitHeader) m := new(object.SplitHeader)
if !empty { if !empty {
id := make([]byte, 16) m.SetSplitID([]byte{1, 3, 5})
_, _ = crand.Read(id)
m.SetSplitID(id)
m.SetParent(refstest.GenerateObjectID(false)) m.SetParent(refstest.GenerateObjectID(false))
m.SetPrevious(refstest.GenerateObjectID(false)) m.SetPrevious(refstest.GenerateObjectID(false))
m.SetChildren(refstest.GenerateObjectIDs(false)) m.SetChildren(refstest.GenerateObjectIDs(false))
@ -95,10 +91,7 @@ func GenerateECHeader(empty bool) *object.ECHeader {
if !empty { if !empty {
ech.Parent = refstest.GenerateObjectID(empty) ech.Parent = refstest.GenerateObjectID(empty)
ech.ParentSplitID = []byte{1, 2, 3}
ech.ParentSplitID = make([]byte, 16)
_, _ = crand.Read(ech.ParentSplitID)
ech.ParentSplitParentID = refstest.GenerateObjectID(empty) ech.ParentSplitParentID = refstest.GenerateObjectID(empty)
ech.ParentAttributes = GenerateAttributes(empty) ech.ParentAttributes = GenerateAttributes(empty)
ech.Index = 0 ech.Index = 0
@ -157,10 +150,7 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo {
m := new(object.SplitInfo) m := new(object.SplitInfo)
if !empty { if !empty {
id := make([]byte, 16) m.SetSplitID([]byte("splitID"))
_, _ = crand.Read(id)
m.SetSplitID(id)
m.SetLastPart(refstest.GenerateObjectID(false)) m.SetLastPart(refstest.GenerateObjectID(false))
m.SetLink(refstest.GenerateObjectID(false)) m.SetLink(refstest.GenerateObjectID(false))
} }
@ -637,10 +627,7 @@ func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponseBo
if !empty { if !empty {
m.SetType(678) m.SetType(678)
m.SetHashList([][]byte{ m.SetHashList([][]byte{{1}, {2}})
refstest.GenerateChecksum(false).GetSum(),
refstest.GenerateChecksum(false).GetSum(),
})
} }
return m return m

View file

@ -1615,18 +1615,6 @@ func (r *PatchResponse) SetBody(v *PatchResponseBody) {
r.Body = v r.Body = v
} }
func (r *PatchResponseBody) GetObjectID() *refs.ObjectID {
if r != nil {
return r.ObjectID
}
return nil
}
func (r *PatchResponseBody) SetObjectID(objectID *refs.ObjectID) {
r.ObjectID = objectID
}
func (r *PatchRequestBodyPatch) GetChunk() []byte { func (r *PatchRequestBodyPatch) GetChunk() []byte {
if r != nil { if r != nil {
return r.Chunk return r.Chunk

View file

@ -24,7 +24,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
b.Run("to grpc message", func(b *testing.B) { b.Run("to grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
raw := ObjectIDListToGRPCMessage(ids) raw := ObjectIDListToGRPCMessage(ids)
if len(raw) != len(ids) { if len(raw) != len(ids) {
b.FailNow() b.FailNow()
@ -33,7 +33,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
}) })
b.Run("from grpc message", func(b *testing.B) { b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
ids, err := ObjectIDListFromGRPCMessage(raw) ids, err := ObjectIDListFromGRPCMessage(raw)
if err != nil || len(raw) != len(ids) { if err != nil || len(raw) != len(ids) {
b.FailNow() b.FailNow()
@ -42,7 +42,7 @@ func benchmarkObjectIDSlice(b *testing.B, size int) {
}) })
b.Run("marshal", func(b *testing.B) { b.Run("marshal", func(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
buf := make([]byte, ObjectIDNestedListSize(1, ids)) buf := make([]byte, ObjectIDNestedListSize(1, ids))
n := ObjectIDNestedListMarshal(1, buf, ids) n := ObjectIDNestedListMarshal(1, buf, ids)
if n != len(buf) { if n != len(buf) {

View file

@ -52,26 +52,28 @@ func (c *ContainerID) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func ContainerIDsToGRPCMessage(ids []ContainerID) (res []refs.ContainerID) { func ContainerIDsToGRPCMessage(ids []ContainerID) (res []*refs.ContainerID) {
if ids != nil { if ids != nil {
res = make([]refs.ContainerID, 0, len(ids)) res = make([]*refs.ContainerID, 0, len(ids))
for i := range ids { for i := range ids {
res = append(res, *ids[i].ToGRPCMessage().(*refs.ContainerID)) res = append(res, ids[i].ToGRPCMessage().(*refs.ContainerID))
} }
} }
return return
} }
func ContainerIDsFromGRPCMessage(idsV2 []refs.ContainerID) (res []ContainerID, err error) { func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []ContainerID, err error) {
if idsV2 != nil { if idsV2 != nil {
res = make([]ContainerID, len(idsV2)) res = make([]ContainerID, len(idsV2))
for i := range idsV2 { for i := range idsV2 {
err = res[i].FromGRPCMessage(&idsV2[i]) if idsV2[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(idsV2[i])
return if err != nil {
return
}
} }
} }
} }
@ -102,26 +104,28 @@ func (o *ObjectID) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func ObjectIDListToGRPCMessage(ids []ObjectID) (res []refs.ObjectID) { func ObjectIDListToGRPCMessage(ids []ObjectID) (res []*refs.ObjectID) {
if ids != nil { if ids != nil {
res = make([]refs.ObjectID, 0, len(ids)) res = make([]*refs.ObjectID, 0, len(ids))
for i := range ids { for i := range ids {
res = append(res, *ids[i].ToGRPCMessage().(*refs.ObjectID)) res = append(res, ids[i].ToGRPCMessage().(*refs.ObjectID))
} }
} }
return return
} }
func ObjectIDListFromGRPCMessage(idsV2 []refs.ObjectID) (res []ObjectID, err error) { func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []ObjectID, err error) {
if idsV2 != nil { if idsV2 != nil {
res = make([]ObjectID, len(idsV2)) res = make([]ObjectID, len(idsV2))
for i := range idsV2 { for i := range idsV2 {
err = res[i].FromGRPCMessage(&idsV2[i]) if idsV2[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(idsV2[i])
return if err != nil {
return
}
} }
} }
} }

Binary file not shown.

View file

@ -1,8 +1,7 @@
package refstest package refstest
import ( import (
crand "crypto/rand" "math/rand"
"crypto/sha256"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
) )
@ -22,10 +21,7 @@ func GenerateOwnerID(empty bool) *refs.OwnerID {
m := new(refs.OwnerID) m := new(refs.OwnerID)
if !empty { if !empty {
id := make([]byte, 25) m.SetValue([]byte{1, 2, 3})
_, _ = crand.Read(id)
m.SetValue(id)
} }
return m return m
@ -46,10 +42,7 @@ func GenerateObjectID(empty bool) *refs.ObjectID {
m := new(refs.ObjectID) m := new(refs.ObjectID)
if !empty { if !empty {
id := make([]byte, sha256.Size) m.SetValue([]byte{1, 2, 3})
_, _ = crand.Read(id)
m.SetValue(id)
} }
return m return m
@ -72,10 +65,7 @@ func GenerateContainerID(empty bool) *refs.ContainerID {
m := new(refs.ContainerID) m := new(refs.ContainerID)
if !empty { if !empty {
id := make([]byte, sha256.Size) m.SetValue([]byte{1, 2, 3})
_, _ = crand.Read(id)
m.SetValue(id)
} }
return m return m
@ -98,15 +88,9 @@ func GenerateSignature(empty bool) *refs.Signature {
m := new(refs.Signature) m := new(refs.Signature)
if !empty { if !empty {
key := make([]byte, 33) m.SetKey([]byte{1})
_, _ = crand.Read(key) m.SetSign([]byte{2})
m.SetScheme(refs.SignatureScheme(rand.Int31() % 3))
sign := make([]byte, 65)
_, _ = crand.Read(sign)
m.SetScheme(refs.ECDSA_SHA512)
m.SetKey(key)
m.SetSign(sign)
} }
return m return m
@ -116,11 +100,8 @@ func GenerateChecksum(empty bool) *refs.Checksum {
m := new(refs.Checksum) m := new(refs.Checksum)
if !empty { if !empty {
cs := make([]byte, sha256.Size) m.SetType(1)
_, _ = crand.Read(cs) m.SetSum([]byte{1, 2, 3})
m.SetType(refs.SHA256)
m.SetSum(cs)
} }
return m return m

View file

@ -2,16 +2,13 @@ package client
import ( import (
"context" "context"
"google.golang.org/grpc"
) )
// CallOption is a messaging session option within Protobuf RPC. // CallOption is a messaging session option within Protobuf RPC.
type CallOption func(*callParameters) type CallOption func(*callParameters)
type callParameters struct { type callParameters struct {
ctx context.Context // nolint:containedctx ctx context.Context // nolint:containedctx
dialer func(context.Context, grpc.ClientConnInterface) error
} }
func defaultCallParameters() *callParameters { func defaultCallParameters() *callParameters {
@ -30,11 +27,3 @@ func WithContext(ctx context.Context) CallOption {
prm.ctx = ctx prm.ctx = ctx
} }
} }
// WithDialer returns option to specify grpc dialer. If passed, it will be
// called after the connection is successfully created.
func WithDialer(dialer func(context.Context, grpc.ClientConnInterface) error) CallOption {
return func(prm *callParameters) {
prm.dialer = dialer
}
}

View file

@ -12,7 +12,7 @@ import (
var errInvalidEndpoint = errors.New("invalid endpoint options") var errInvalidEndpoint = errors.New("invalid endpoint options")
func (c *Client) openGRPCConn(ctx context.Context, dialer func(ctx context.Context, cc grpcstd.ClientConnInterface) error) error { func (c *Client) openGRPCConn(ctx context.Context) error {
if c.conn != nil { if c.conn != nil {
return nil return nil
} }
@ -21,21 +21,15 @@ func (c *Client) openGRPCConn(ctx context.Context, dialer func(ctx context.Conte
return errInvalidEndpoint return errInvalidEndpoint
} }
dialCtx, cancel := context.WithTimeout(ctx, c.dialTimeout)
var err error var err error
c.conn, err = grpcstd.NewClient(c.addr, c.grpcDialOpts...) c.conn, err = grpcstd.DialContext(dialCtx, c.addr, c.grpcDialOpts...)
cancel()
if err != nil { if err != nil {
return fmt.Errorf("gRPC new client: %w", err) return fmt.Errorf("gRPC dial: %w", err)
}
if dialer != nil {
ctx, cancel := context.WithTimeout(ctx, c.dialTimeout)
defer cancel()
if err := dialer(ctx, c.conn); err != nil {
_ = c.conn.Close()
return fmt.Errorf("gRPC dial: %w", err)
}
} }
return nil return nil

View file

@ -46,7 +46,7 @@ func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageRe
opt(prm) opt(prm)
} }
if err := c.openGRPCConn(prm.ctx, prm.dialer); err != nil { if err := c.openGRPCConn(prm.ctx); err != nil {
return nil, err return nil, err
} }

View file

@ -37,6 +37,7 @@ func (c *cfg) initDefault() {
c.dialTimeout = defaultDialTimeout c.dialTimeout = defaultDialTimeout
c.rwTimeout = defaultRWTimeout c.rwTimeout = defaultRWTimeout
c.grpcDialOpts = []grpc.DialOption{ c.grpcDialOpts = []grpc.DialOption{
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithTransportCredentials(insecure.NewCredentials()),
} }
} }

View file

@ -80,3 +80,19 @@ func ListContainers(
return resp, nil return resp, nil
} }
// GetEACL executes ContainerService.GetExtendedACL RPC.
func GetEACL(
cli *client.Client,
req *container.GetExtendedACLRequest,
opts ...client.CallOption,
) (*container.GetExtendedACLResponse, error) {
resp := new(container.GetExtendedACLResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceContainer, rpcContainerGetEACL), req, resp, opts...)
if err != nil {
return nil, err
}
return resp, nil
}

View file

@ -7,7 +7,6 @@ import (
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/encoding"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -69,58 +68,6 @@ func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) message.Message) {
require.Equal(t, bm, bm2) require.Equal(t, bm, bm2)
}) })
} }
t.Run("compatibility", func(t *testing.T) {
testCompatibility(t, msgGen)
})
}) })
} }
} }
func testCompatibility(t *testing.T, msgGen func(empty bool) message.Message) {
compareBinary := func(t *testing.T, msg message.Message) {
am, ok := msg.(binaryMessage)
if !ok {
t.Skip()
}
a := am.StableMarshal(nil)
b := msg.ToGRPCMessage().(encoding.ProtoMarshaler).MarshalProtobuf(nil)
if len(a) == 0 {
require.Empty(t, b)
} else {
require.Equal(t, a, b)
}
}
compareJSON := func(t *testing.T, msg message.Message) {
am, ok := msg.(jsonMessage)
if !ok {
t.Skip()
}
a, err := am.MarshalJSON()
require.NoError(t, err)
b, err := json.Marshal(msg.ToGRPCMessage())
require.NoError(t, err)
require.JSONEq(t, string(a), string(b))
}
t.Run("empty", func(t *testing.T) {
msg := msgGen(true)
t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) {
compareBinary(t, msg)
})
t.Run(fmt.Sprintf("JSON_%T", msg), func(t *testing.T) {
compareJSON(t, msg)
})
})
t.Run("not empty", func(t *testing.T) {
msg := msgGen(false)
t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) {
compareBinary(t, msg)
})
t.Run(fmt.Sprintf("JSON_%T", msg), func(t *testing.T) {
compareJSON(t, msg)
})
})
}

View file

@ -207,26 +207,28 @@ func (x *XHeader) FromGRPCMessage(m grpc.Message) error {
return nil return nil
} }
func XHeadersToGRPC(xs []XHeader) (res []session.XHeader) { func XHeadersToGRPC(xs []XHeader) (res []*session.XHeader) {
if xs != nil { if xs != nil {
res = make([]session.XHeader, 0, len(xs)) res = make([]*session.XHeader, 0, len(xs))
for i := range xs { for i := range xs {
res = append(res, *xs[i].ToGRPCMessage().(*session.XHeader)) res = append(res, xs[i].ToGRPCMessage().(*session.XHeader))
} }
} }
return return
} }
func XHeadersFromGRPC(xs []session.XHeader) (res []XHeader, err error) { func XHeadersFromGRPC(xs []*session.XHeader) (res []XHeader, err error) {
if xs != nil { if xs != nil {
res = make([]XHeader, len(xs)) res = make([]XHeader, len(xs))
for i := range xs { for i := range xs {
err = res[i].FromGRPCMessage(&xs[i]) if xs[i] != nil {
if err != nil { err = res[i].FromGRPCMessage(xs[i])
return if err != nil {
return
}
} }
} }
} }

Binary file not shown.

Binary file not shown.

View file

@ -1,7 +1,6 @@
package sessiontest package sessiontest
import ( import (
crand "crypto/rand"
"math/rand" "math/rand"
"time" "time"
@ -39,10 +38,7 @@ func GenerateCreateResponseBody(empty bool) *session.CreateResponseBody {
m := new(session.CreateResponseBody) m := new(session.CreateResponseBody)
if !empty { if !empty {
id := make([]byte, 16) m.SetID([]byte{1, 2, 3})
_, _ = crand.Read(id)
m.SetID(id)
m.SetSessionKey([]byte{4, 5, 6}) m.SetSessionKey([]byte{4, 5, 6})
} }
@ -168,10 +164,7 @@ func GenerateSessionTokenBody(empty bool) *session.TokenBody {
m := new(session.TokenBody) m := new(session.TokenBody)
if !empty { if !empty {
id := make([]byte, 16) m.SetID([]byte{1})
_, _ = crand.Read(id)
m.SetID(id)
m.SetSessionKey([]byte{2}) m.SetSessionKey([]byte{2})
m.SetOwnerID(refstest.GenerateOwnerID(false)) m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetLifetime(GenerateTokenLifetime(false)) m.SetLifetime(GenerateTokenLifetime(false))

View file

@ -46,6 +46,10 @@ func serviceMessageBody(req any) stableMarshaler {
return v.GetBody() return v.GetBody()
case *container.ListResponse: case *container.ListResponse:
return v.GetBody() return v.GetBody()
case *container.GetExtendedACLRequest:
return v.GetBody()
case *container.GetExtendedACLResponse:
return v.GetBody()
/* Object */ /* Object */
case *object.PutRequest: case *object.PutRequest:

View file

@ -77,7 +77,7 @@ func BenchmarkSignRequest(b *testing.B) {
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
b.StopTimer() b.StopTimer()
dec := new(accounting.Decimal) dec := new(accounting.Decimal)
dec.SetValue(100) dec.SetValue(100)
@ -103,7 +103,7 @@ func BenchmarkVerifyRequest(b *testing.B) {
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()
for range b.N { for i := 0; i < b.N; i++ {
b.StopTimer() b.StopTimer()
dec := new(accounting.Decimal) dec := new(accounting.Decimal)
dec.SetValue(100) dec.SetValue(100)

View file

@ -48,13 +48,13 @@ func (x *Status) ToGRPCMessage() grpc.Message {
m.SetCode(CodeToGRPC(x.code)) m.SetCode(CodeToGRPC(x.code))
m.SetMessage(x.msg) m.SetMessage(x.msg)
var ds []status.Status_Detail var ds []*status.Status_Detail
if ln := len(x.details); ln > 0 { if ln := len(x.details); ln > 0 {
ds = make([]status.Status_Detail, 0, ln) ds = make([]*status.Status_Detail, 0, ln)
for i := range ln { for i := 0; i < ln; i++ {
ds = append(ds, *x.details[i].ToGRPCMessage().(*status.Status_Detail)) ds = append(ds, x.details[i].ToGRPCMessage().(*status.Status_Detail))
} }
} }
@ -80,9 +80,11 @@ func (x *Status) FromGRPCMessage(m grpc.Message) error {
ds = make([]Detail, ln) ds = make([]Detail, ln)
for i := range ln { for i := 0; i < ln; i++ {
if err := ds[i].FromGRPCMessage(&dsV2[i]); err != nil { if dsV2[i] != nil {
return err if err := ds[i].FromGRPCMessage(dsV2[i]); err != nil {
return err
}
} }
} }
} }

Binary file not shown.

View file

@ -63,8 +63,6 @@ const (
SignatureVerificationFail SignatureVerificationFail
// NodeUnderMaintenance is a local Code value for NODE_UNDER_MAINTENANCE status. // NodeUnderMaintenance is a local Code value for NODE_UNDER_MAINTENANCE status.
NodeUnderMaintenance NodeUnderMaintenance
// InvalidArgument is a local Code value for INVALID_ARGUMENT status.
InvalidArgument
) )
const ( const (

Binary file not shown.

View file

@ -1,8 +1,6 @@
package tombstonetest package tombstonetest
import ( import (
"crypto/rand"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test" refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/tombstone"
) )
@ -11,11 +9,8 @@ func GenerateTombstone(empty bool) *tombstone.Tombstone {
m := new(tombstone.Tombstone) m := new(tombstone.Tombstone)
if !empty { if !empty {
id := make([]byte, 16)
_, _ = rand.Read(id)
m.SetExpirationEpoch(89) m.SetExpirationEpoch(89)
m.SetSplitID(id) m.SetSplitID([]byte{3, 2, 1})
m.SetMembers(refstest.GenerateObjectIDs(false)) m.SetMembers(refstest.GenerateObjectIDs(false))
} }

View file

@ -26,34 +26,11 @@ func nonZero[T protoInt]() T {
func TestStableMarshalSingle(t *testing.T) { func TestStableMarshalSingle(t *testing.T) {
t.Run("empty", func(t *testing.T) { t.Run("empty", func(t *testing.T) {
t.Run("proto", func(t *testing.T) { input := &generated.Primitives{}
input := &generated.Primitives{} require.Zero(t, input.StableSize())
require.Zero(t, input.StableSize())
r := input.MarshalProtobuf(nil) r := input.MarshalProtobuf(nil)
require.Empty(t, r) require.Empty(t, r)
})
t.Run("json", func(t *testing.T) {
input := &generated.Primitives{}
r, err := input.MarshalJSON()
require.NoError(t, err)
require.NotEmpty(t, r)
var actual test.Primitives
require.NoError(t, protojson.Unmarshal(r, &actual))
t.Run("protojson compatibility", func(t *testing.T) {
data, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(&actual)
require.NoError(t, err)
require.JSONEq(t, string(data), string(r))
})
var actualFrostfs generated.Primitives
require.NoError(t, actualFrostfs.UnmarshalJSON(r))
require.Equal(t, input, &actualFrostfs)
primitivesEqual(t, input, &actual)
})
}) })
marshalCases := []struct { marshalCases := []struct {
@ -72,8 +49,6 @@ func TestStableMarshalSingle(t *testing.T) {
{name: "fixed32", input: &generated.Primitives{FieldK: nonZero[uint32]()}}, {name: "fixed32", input: &generated.Primitives{FieldK: nonZero[uint32]()}},
{name: "enum, positive", input: &generated.Primitives{FieldH: generated.Primitives_POSITIVE}}, {name: "enum, positive", input: &generated.Primitives{FieldH: generated.Primitives_POSITIVE}},
{name: "enum, negative", input: &generated.Primitives{FieldH: generated.Primitives_NEGATIVE}}, {name: "enum, negative", input: &generated.Primitives{FieldH: generated.Primitives_NEGATIVE}},
{name: "oneof, first", input: &generated.Primitives{FieldM: &generated.Primitives_FieldMa{FieldMa: []byte{4, 2}}}},
{name: "oneof, second", input: &generated.Primitives{FieldM: &generated.Primitives_FieldMe{FieldMe: nonZero[uint32]()}}},
} }
for _, tc := range marshalCases { for _, tc := range marshalCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
@ -99,12 +74,6 @@ func TestStableMarshalSingle(t *testing.T) {
var actual test.Primitives var actual test.Primitives
require.NoError(t, protojson.Unmarshal(r, &actual)) require.NoError(t, protojson.Unmarshal(r, &actual))
t.Run("protojson compatibility", func(t *testing.T) {
data, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(&actual)
require.NoError(t, err)
require.JSONEq(t, string(data), string(r))
})
var actualFrostfs generated.Primitives var actualFrostfs generated.Primitives
require.NoError(t, actualFrostfs.UnmarshalJSON(r)) require.NoError(t, actualFrostfs.UnmarshalJSON(r))
require.Equal(t, tc.input, &actualFrostfs) require.Equal(t, tc.input, &actualFrostfs)
@ -117,7 +86,6 @@ func TestStableMarshalSingle(t *testing.T) {
func primitivesEqual(t *testing.T, a *generated.Primitives, b *test.Primitives) { func primitivesEqual(t *testing.T, a *generated.Primitives, b *test.Primitives) {
// Compare each field directly, because proto-generated code has private fields. // Compare each field directly, because proto-generated code has private fields.
require.Equal(t, len(a.FieldA), len(b.FieldA))
require.Equal(t, a.FieldA, b.FieldA) require.Equal(t, a.FieldA, b.FieldA)
require.Equal(t, a.FieldB, b.FieldB) require.Equal(t, a.FieldB, b.FieldB)
require.Equal(t, a.FieldC, b.FieldC) require.Equal(t, a.FieldC, b.FieldC)
@ -129,9 +97,6 @@ func primitivesEqual(t *testing.T, a *generated.Primitives, b *test.Primitives)
require.Equal(t, a.FieldJ, b.FieldJ) require.Equal(t, a.FieldJ, b.FieldJ)
require.Equal(t, a.FieldK, b.FieldK) require.Equal(t, a.FieldK, b.FieldK)
require.EqualValues(t, a.FieldH, b.FieldH) require.EqualValues(t, a.FieldH, b.FieldH)
require.Equal(t, a.GetFieldMa(), b.GetFieldMa())
require.Equal(t, a.GetFieldMe(), b.GetFieldMe())
require.Equal(t, a.GetFieldAux().GetInnerField(), b.GetFieldAux().GetInnerField())
} }
func repPrimitivesEqual(t *testing.T, a *generated.RepPrimitives, b *test.RepPrimitives) { func repPrimitivesEqual(t *testing.T, a *generated.RepPrimitives, b *test.RepPrimitives) {
@ -143,10 +108,6 @@ func repPrimitivesEqual(t *testing.T, a *generated.RepPrimitives, b *test.RepPri
require.Equal(t, a.FieldE, b.FieldE) require.Equal(t, a.FieldE, b.FieldE)
require.Equal(t, a.FieldF, b.FieldF) require.Equal(t, a.FieldF, b.FieldF)
require.Equal(t, a.FieldFu, b.FieldFu) require.Equal(t, a.FieldFu, b.FieldFu)
require.Equal(t, len(a.GetFieldAux()), len(b.GetFieldAux()))
for i := range a.FieldAux {
require.Equal(t, a.GetFieldAux()[i].GetInnerField(), b.GetFieldAux()[i].GetInnerField())
}
} }
func randIntSlice[T protoInt](n int, includeZero bool) []T { func randIntSlice[T protoInt](n int, includeZero bool) []T {
@ -163,14 +124,6 @@ func randIntSlice[T protoInt](n int, includeZero bool) []T {
return r return r
} }
func uint32SliceToAux(s []uint32) []generated.RepPrimitives_Aux {
r := make([]generated.RepPrimitives_Aux, len(s))
for i := range s {
r[i] = generated.RepPrimitives_Aux{InnerField: s[i]}
}
return r
}
func TestStableMarshalRep(t *testing.T) { func TestStableMarshalRep(t *testing.T) {
t.Run("empty", func(t *testing.T) { t.Run("empty", func(t *testing.T) {
marshalCases := []struct { marshalCases := []struct {
@ -218,9 +171,6 @@ func TestStableMarshalRep(t *testing.T) {
{name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](1, true)}}, {name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](1, true)}},
{name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, true)}}, {name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, true)}},
{name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, false)}}, {name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, false)}},
{name: "message", input: &generated.RepPrimitives{FieldAux: uint32SliceToAux(randIntSlice[uint32](1, true))}},
{name: "message", input: &generated.RepPrimitives{FieldAux: uint32SliceToAux(randIntSlice[uint32](2, true))}},
{name: "message", input: &generated.RepPrimitives{FieldAux: uint32SliceToAux(randIntSlice[uint32](2, false))}},
} }
for _, tc := range marshalCases { for _, tc := range marshalCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {

Binary file not shown.

Binary file not shown.

View file

@ -22,14 +22,6 @@ message Primitives {
NEGATIVE = -1; NEGATIVE = -1;
} }
SomeEnum field_h = 300; SomeEnum field_h = 300;
message Aux { uint32 inner_field = 1; }
oneof field_m {
bytes field_ma = 401;
uint32 field_me = 402;
Aux field_aux = 403;
}
} }
message RepPrimitives { message RepPrimitives {
@ -40,7 +32,4 @@ message RepPrimitives {
repeated int64 field_e = 5; repeated int64 field_e = 5;
repeated uint64 field_f = 6; repeated uint64 field_f = 6;
repeated uint64 field_fu = 7 [ packed = false ]; repeated uint64 field_fu = 7 [ packed = false ];
message Aux { uint32 inner_field = 1; }
repeated Aux field_aux = 8;
} }

View file

@ -126,24 +126,29 @@ func emitOneofGettersSetters(g *protogen.GeneratedFile, msg *protogen.Message, f
// For some reason protoc generates different code for oneof message/non-message fields: // For some reason protoc generates different code for oneof message/non-message fields:
// 1. For message we have 2 level struct wrapping and setters use inner type. // 1. For message we have 2 level struct wrapping and setters use inner type.
// 2. For other types we also have 2 level wrapping, but setters use outer type. // 2. For other types we also have 2 level wrapping, but setters use outer type.
ft := fieldType(g, ff)
g.P("func (x *", msg.GoIdent.GoName, ") Get", ff.GoName, "() ", ft, " {")
g.P("if xx, ok := x.Get", ff.Oneof.GoName, "().(*", ff.GoIdent, "); ok { return xx.", ff.GoName, " }")
g.P("return ", fieldDefaultValue(ff))
g.P("}")
if ff.Desc.Kind() == protoreflect.MessageKind { if ff.Desc.Kind() == protoreflect.MessageKind {
ft := fieldType(g, ff)
g.P("func (x *", msg.GoIdent.GoName, ") Get", ff.GoName, "() ", ft, " {")
g.P("if xx, ok := x.Get", ff.Oneof.GoName, "().(*", ff.GoIdent, "); ok { return xx.", ff.GoName, " }")
g.P("return nil")
g.P("}")
g.P("func (x *", msg.GoIdent.GoName, ") Set", ff.GoName, "(v ", ft, ") {") g.P("func (x *", msg.GoIdent.GoName, ") Set", ff.GoName, "(v ", ft, ") {")
g.P("x.", ff.Oneof.GoName, " = &", ff.GoIdent, "{", ff.GoName, ": v}") g.P("x.", ff.Oneof.GoName, " = &", ff.GoIdent, "{", ff.GoName, ": v}")
g.P("}") g.P("}")
} else { } else {
g.P("func (x *", msg.GoIdent.GoName, ") Get", ff.GoName, "() *", ff.GoIdent, " {")
g.P("if xx, ok := x.Get", ff.Oneof.GoName, "().(*", ff.GoIdent, "); ok { return xx }")
g.P("return nil")
g.P("}")
g.P("func (x *", msg.GoIdent.GoName, ") Set", ff.GoName, "(v *", ff.GoIdent, ") {") g.P("func (x *", msg.GoIdent.GoName, ") Set", ff.GoName, "(v *", ff.GoIdent, ") {")
g.P("x.", ff.Oneof.GoName, " = v") g.P("x.", ff.Oneof.GoName, " = v")
g.P("}") g.P("}")
ft := fieldType(g, ff) ft := fieldType(g, ff)
emitGetterSetter(g, ff.GoIdent.GoName, ff.GoName, ft.String(), fieldDefaultValue(ff)) emitGetterSetter(g, ff.GoIdent.GoName, ff.GoName, ft.String(), "nil")
} }
} }

View file

@ -59,35 +59,6 @@ func emitJSONUnmarshal(g *protogen.GeneratedFile, msg *protogen.Message) {
g.P("}") g.P("}")
} }
func emitJSONParseInteger(g *protogen.GeneratedFile, ident string, method string, bitSize int, typ string) {
g.P("r := in.JsonNumber()")
g.P("n := r.String()")
g.P("v, err := ", strconvPackage.Ident(method), "(n, 10, ", bitSize, ")")
g.P("if err != nil {")
g.P(" in.AddError(err)")
g.P(" return")
g.P("}")
g.P(ident, " := ", typ, "(v)")
}
func emitJSONReadEnum(g *protogen.GeneratedFile, name string, enumType string) {
g.P(`switch v := in.Interface().(type) {
case string:
if vv, ok := `+enumType+`_value[v]; ok {
`+name+` = `+enumType+`(vv)
break
}
vv, err := `, strconvPackage.Ident("ParseInt"), `(v, 10, 32)
if err != nil {
in.AddError(err)
return
}
`+name+` = `+enumType+`(vv)
case float64:
`+name+` = `+enumType+`(v)
}`)
}
func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) { func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string) {
g.P("{") g.P("{")
defer g.P("}") defer g.P("}")
@ -112,20 +83,30 @@ func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string
enumType := fieldType(g, f).String() enumType := fieldType(g, f).String()
g.P("var parsedValue " + enumType) g.P("var parsedValue " + enumType)
emitJSONReadEnum(g, "parsedValue", enumType) g.P(`switch v := in.Interface().(type) {
case string:
if vv, ok := `+enumType+`_value[v]; ok {
parsedValue = `+enumType+`(vv)
break
}
vv, err := `, strconvPackage.Ident("ParseInt"), `(v, 10, 32)
if err != nil {
in.AddError(err)
return
}
parsedValue = `+enumType+`(vv)
case float64:
parsedValue = `+enumType+`(v)
}`)
template = "%s = parsedValue" template = "%s = parsedValue"
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
emitJSONParseInteger(g, "pv", "ParseInt", 32, "int32") template = "%s = in.Int32()"
template = "%s = pv"
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
emitJSONParseInteger(g, "pv", "ParseUint", 32, "uint32") template = "%s = in.Uint32()"
template = "%s = pv"
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
emitJSONParseInteger(g, "pv", "ParseInt", 64, "int64") template = "%s = in.Int64()"
template = "%s = pv"
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
emitJSONParseInteger(g, "pv", "ParseUint", 64, "uint64") template = "%s = in.Uint64()"
template = "%s = pv"
case protoreflect.FloatKind: case protoreflect.FloatKind:
template = "%s = in.Float32()" template = "%s = in.Float32()"
case protoreflect.DoubleKind: case protoreflect.DoubleKind:
@ -133,20 +114,10 @@ func emitJSONFieldRead(g *protogen.GeneratedFile, f *protogen.Field, name string
case protoreflect.StringKind: case protoreflect.StringKind:
template = "%s = in.String()" template = "%s = in.String()"
case protoreflect.BytesKind: case protoreflect.BytesKind:
// Since some time ago proto3 support optional keyword, thus the presence is not tracked by default: template = "%s = in.Bytes()"
// https://github.com/protocolbuffers/protobuf-go/blob/fb995f184a1719ec42b247a3771d1036d92adf67/internal/impl/message_reflect_field.go#L327
// We do not explicitly support `optional` keyword, protoc will fail on such fileds.
// Thus, treat empty string as `[]byte(nil)`.
template = `{
tmp := in.Bytes()
if len(tmp) == 0 {
tmp = nil
}
%s = tmp
}`
case protoreflect.MessageKind: case protoreflect.MessageKind:
if f.Desc.IsList() { if f.Desc.IsList() {
g.P("f = ", fieldType(g, f)[2:], "{}") g.P("f = new(", fieldType(g, f)[3:], ")")
} else { } else {
g.P("f = new(", fieldType(g, f)[1:], ")") g.P("f = new(", fieldType(g, f)[1:], ")")
} }
@ -176,11 +147,8 @@ func emitJSONMarshal(g *protogen.GeneratedFile, msg *protogen.Message) {
g.P("func (x *", msg.GoIdent.GoName, ") MarshalEasyJSON(out *", jwriterPackage.Ident("Writer"), ") {") g.P("func (x *", msg.GoIdent.GoName, ") MarshalEasyJSON(out *", jwriterPackage.Ident("Writer"), ") {")
g.P(`if x == nil { out.RawString("null"); return }`) g.P(`if x == nil { out.RawString("null"); return }`)
if len(msg.Fields) != 0 {
g.P("first := true")
}
g.P("out.RawByte('{')") g.P("out.RawByte('{')")
for _, f := range msg.Fields { for i, f := range msg.Fields {
if f.Oneof != nil { if f.Oneof != nil {
if f.Oneof.Fields[0] != f { if f.Oneof.Fields[0] != f {
continue continue
@ -189,38 +157,31 @@ func emitJSONMarshal(g *protogen.GeneratedFile, msg *protogen.Message) {
g.P("switch xx := x.", f.Oneof.GoName, ".(type) {") g.P("switch xx := x.", f.Oneof.GoName, ".(type) {")
for _, ff := range f.Oneof.Fields { for _, ff := range f.Oneof.Fields {
g.P("case *", ff.GoIdent, ":") g.P("case *", ff.GoIdent, ":")
emitJSONFieldWrite(g, ff, "xx") emitJSONFieldWrite(g, ff, "xx", i == 0)
} }
g.P("default:")
g.P(`out.RawString("null")`)
g.P("}") g.P("}")
continue continue
} }
emitJSONFieldWrite(g, f, "x") emitJSONFieldWrite(g, f, "x", i == 0)
} }
g.P("out.RawByte('}')") g.P("out.RawByte('}')")
g.P("}") g.P("}")
} }
func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name string) { func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name string, first bool) {
g.P("{") g.P("{")
defer g.P("}") defer g.P("}")
g.P("const prefix string = ", `",\"`, fieldJSONName(f), `\":"`)
if first {
g.P("out.RawString(prefix[1:])")
} else {
g.P("out.RawString(prefix)")
}
selector := name + "." + f.GoName selector := name + "." + f.GoName
// This code is responsible for ignoring default values.
// We will restore it after having parametrized JSON marshaling.
//
// isNotDefault := notNil
// if f.Desc.IsList() {
// isNotDefault = notEmpty
// } else if f.Desc.Kind() != protoreflect.MessageKind {
// _, isNotDefault = easyprotoKindInfo(f.Desc.Kind())
// }
// g.P("if ", isNotDefault(selector), "{")
// defer g.P("}")
g.P("if !first { out.RawByte(','); } else { first = false; }")
g.P("const prefix string = ", `"\"`, fieldJSONName(f), `\":"`)
g.P("out.RawString(prefix)")
if f.Desc.IsList() { if f.Desc.IsList() {
selector += "[i]" selector += "[i]"
g.P("out.RawByte('[')") g.P("out.RawByte('[')")
@ -236,27 +197,15 @@ func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name strin
case protoreflect.BoolKind: case protoreflect.BoolKind:
template = "out.Bool(%s)" template = "out.Bool(%s)"
case protoreflect.EnumKind: case protoreflect.EnumKind:
enumType := fieldType(g, f).String() template = "out.Int32(int32(%s))"
template = `v := int32(%s)
if vv, ok := ` + enumType + `_name[v]; ok {
out.String(vv)
} else {
out.Int32(v)
}`
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
template = "out.Int32(%s)" template = "out.Int32(%s)"
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
template = "out.Uint32(%s)" template = "out.Uint32(%s)"
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
g.P("out.RawByte('\"')") template = "out.Int64(%s)"
g.P("out.Buffer.Buf = ", strconvPackage.Ident("AppendInt"), "(out.Buffer.Buf, ", selector, ", 10)")
g.P("out.RawByte('\"')")
return
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
g.P("out.RawByte('\"')") template = "out.Uint64(%s)"
g.P("out.Buffer.Buf = ", strconvPackage.Ident("AppendUint"), "(out.Buffer.Buf, ", selector, ", 10)")
g.P("out.RawByte('\"')")
return
case protoreflect.FloatKind: case protoreflect.FloatKind:
template = "out.Float32(%s)" template = "out.Float32(%s)"
case protoreflect.DoubleKind: case protoreflect.DoubleKind:
@ -264,10 +213,7 @@ func emitJSONFieldWrite(g *protogen.GeneratedFile, f *protogen.Field, name strin
case protoreflect.StringKind: case protoreflect.StringKind:
template = "out.String(%s)" template = "out.String(%s)"
case protoreflect.BytesKind: case protoreflect.BytesKind:
g.P("if ", selector, "!= nil {") template = "out.Base64Bytes(%s)"
g.P("out.Base64Bytes(", selector, ")")
g.P("} else { out.String(\"\") }")
return
case protoreflect.MessageKind: case protoreflect.MessageKind:
template = "%s.MarshalEasyJSON(out)" template = "%s.MarshalEasyJSON(out)"
case protoreflect.GroupKind: case protoreflect.GroupKind:

View file

@ -39,8 +39,8 @@ func emitFieldUnmarshal(g *protogen.GeneratedFile, f *protogen.Field) {
g.P("data, ok := fc.MessageData()") g.P("data, ok := fc.MessageData()")
g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`) g.P(`if !ok { return fmt.Errorf("cannot unmarshal field %s", "`, f.GoName, `") }`)
if f.Desc.IsList() { if f.Desc.IsList() {
g.P(name, " = append(", name, ", ", fieldType(g, f)[2:], "{})") g.P(name, " = append(", name, ", new(", fieldType(g, f)[3:], "))")
g.P("ff := &", name, "[len(", name, ")-1]") g.P("ff := ", name, "[len(", name, ")-1]")
name = "ff" name = "ff"
} else if f.Oneof != nil { } else if f.Oneof != nil {
const tmp = "oneofField" const tmp = "oneofField"
@ -172,12 +172,11 @@ func emitMarshalRaw(g *protogen.GeneratedFile, f *protogen.Field, name string) {
defer g.P("}") defer g.P("}")
name += "[i]" name += "[i]"
} else {
g.P("if ", notNil(name), " {")
defer g.P("}")
} }
g.P("if ", notNil(name), " && ", name, ".StableSize() != 0 {")
g.P(name, ".EmitProtobuf(mm.AppendMessage(", f.Desc.Number(), "))") g.P(name, ".EmitProtobuf(mm.AppendMessage(", f.Desc.Number(), "))")
g.P("}")
return return
} }

View file

@ -43,10 +43,7 @@ func fieldType(g *protogen.GeneratedFile, field *protogen.Field) structField {
case protoreflect.BytesKind: case protoreflect.BytesKind:
typ = "[]byte" typ = "[]byte"
case protoreflect.MessageKind: case protoreflect.MessageKind:
typ = structField(g.QualifiedGoIdent(field.Message.GoIdent)) typ = structField(g.QualifiedGoIdent(field.Message.GoIdent)).PointerTo()
if !field.Desc.IsList() {
typ = typ.PointerTo()
}
case protoreflect.GroupKind: case protoreflect.GroupKind:
panic("unimplemented") panic("unimplemented")
} }

View file

@ -72,7 +72,7 @@ func emitFieldSize(g *protogen.GeneratedFile, f *protogen.Field) {
case f.Desc.IsList() && (f.Desc.Kind() == protoreflect.MessageKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()): case f.Desc.IsList() && (f.Desc.Kind() == protoreflect.MessageKind || f.Desc.Kind() == protoreflect.Uint64Kind && !f.Desc.IsPacked()):
g.P("for i := range ", name, "{") g.P("for i := range ", name, "{")
if f.Desc.Kind() == protoreflect.MessageKind { if f.Desc.Kind() == protoreflect.MessageKind {
g.P("size += ", protoPackage.Ident("NestedStructureSizeUnchecked"), "(", f.Desc.Number(), ", &", name, "[i])") g.P("size += ", protoPackage.Ident("NestedStructureSize"), "(", f.Desc.Number(), ", ", name, "[i])")
} else { } else {
if f.Desc.Kind() != protoreflect.Uint64Kind { if f.Desc.Kind() != protoreflect.Uint64Kind {
panic("only uint64 unpacked primitive is supported") panic("only uint64 unpacked primitive is supported")

View file

@ -2,6 +2,8 @@ package main
import ( import (
"flag" "flag"
"fmt"
"os"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/protogen/internalgengo" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/protogen/internalgengo"
"google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/compiler/protogen"
@ -10,10 +12,18 @@ import (
func main() { func main() {
var flags flag.FlagSet var flags flag.FlagSet
genFuzz := flags.Bool("fuzz", false, "generate fuzz tests") genFuzz := flags.Bool("fuzz", false, "generate fuzz tests")
yamlConfigPath := flags.String("config", "", "path to the configuration")
protogen.Options{ protogen.Options{
ParamFunc: flags.Set, ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error { }.Run(func(gen *protogen.Plugin) error {
if *yamlConfigPath != "" {
s, e := os.Getwd()
fmt.Fprintln(os.Stderr, s, e)
data, err := os.ReadFile(*yamlConfigPath)
fmt.Fprintln(os.Stderr, string(data), err)
}
for _, f := range gen.Files { for _, f := range gen.Files {
if f.Generate { if f.Generate {
internalgengo.GenerateFile(gen, f) internalgengo.GenerateFile(gen, f)