[#40] types: Generate StableMarshaler/StableSize methods for protobufs

* Add plugin option for protogen in Makefile
* Fix the generator for the plugin in util/protogen
* Erase convertable types, move helpful methods to gRPC protobufs
* Erase helpers for convertations
* Generate StableMarshlal/StableSize for protobufs by the protoc plugin

Signed-off-by: Airat Arifullin a.arifullin@yadro.com
This commit is contained in:
Airat Arifullin 2023-06-13 01:33:53 +03:00
parent 285516a94e
commit bc16a32c24
151 changed files with 1099 additions and 17200 deletions

View file

@ -46,7 +46,9 @@ protoc:
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
echo "⇒ Processing $$f "; \
protoc \
--proto_path=.:./vendor:/usr/local/include \
--proto_path=.:./vendor:/usr/local/include:/home/aarifullin/ws/frostfs-api \
--plugin=protoc-gen-go-frostfs=/home/aarifullin/ws/frostfs-api-go/util/protogen/protogen \
--go-frostfs_out=. --go-frostfs_opt=paths=source_relative \
--go_out=. --go_opt=paths=source_relative \
--go-grpc_opt=require_unimplemented_servers=false \
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \

View file

@ -1,104 +0,0 @@
package accounting
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
)
type BalanceRequestBody struct {
ownerID *refs.OwnerID
}
type BalanceResponseBody struct {
bal *Decimal
}
type Decimal struct {
val int64
prec uint32
}
type BalanceRequest struct {
body *BalanceRequestBody
session.RequestHeaders
}
type BalanceResponse struct {
body *BalanceResponseBody
session.ResponseHeaders
}
func (b *BalanceRequestBody) GetOwnerID() *refs.OwnerID {
if b != nil {
return b.ownerID
}
return nil
}
func (b *BalanceRequestBody) SetOwnerID(v *refs.OwnerID) {
b.ownerID = v
}
func (b *BalanceRequest) GetBody() *BalanceRequestBody {
if b != nil {
return b.body
}
return nil
}
func (b *BalanceRequest) SetBody(v *BalanceRequestBody) {
b.body = v
}
func (d *Decimal) GetValue() int64 {
if d != nil {
return d.val
}
return 0
}
func (d *Decimal) SetValue(v int64) {
d.val = v
}
func (d *Decimal) GetPrecision() uint32 {
if d != nil {
return d.prec
}
return 0
}
func (d *Decimal) SetPrecision(v uint32) {
d.prec = v
}
func (br *BalanceResponseBody) GetBalance() *Decimal {
if br != nil {
return br.bal
}
return nil
}
func (br *BalanceResponseBody) SetBalance(v *Decimal) {
br.bal = v
}
func (br *BalanceResponse) GetBody() *BalanceResponseBody {
if br != nil {
return br.body
}
return nil
}
func (br *BalanceResponse) SetBody(v *BalanceResponseBody) {
br.body = v
}

View file

@ -1,178 +0,0 @@
package accounting
import (
accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (b *BalanceRequestBody) ToGRPCMessage() grpc.Message {
var m *accounting.BalanceRequest_Body
if b != nil {
m = new(accounting.BalanceRequest_Body)
m.SetOwnerId(b.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))
}
return m
}
func (b *BalanceRequestBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*accounting.BalanceRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
ownerID := v.GetOwnerId()
if ownerID == nil {
b.ownerID = nil
} else {
if b.ownerID == nil {
b.ownerID = new(refs.OwnerID)
}
err = b.ownerID.FromGRPCMessage(ownerID)
}
return err
}
func (b *BalanceRequest) ToGRPCMessage() grpc.Message {
var m *accounting.BalanceRequest
if b != nil {
m = new(accounting.BalanceRequest)
m.SetBody(b.body.ToGRPCMessage().(*accounting.BalanceRequest_Body))
b.RequestHeaders.ToMessage(m)
}
return m
}
func (b *BalanceRequest) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*accounting.BalanceRequest)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
b.body = nil
} else {
if b.body == nil {
b.body = new(BalanceRequestBody)
}
err = b.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return b.RequestHeaders.FromMessage(v)
}
func (d *Decimal) ToGRPCMessage() grpc.Message {
var m *accounting.Decimal
if d != nil {
m = new(accounting.Decimal)
m.SetValue(d.val)
m.SetPrecision(d.prec)
}
return m
}
func (d *Decimal) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*accounting.Decimal)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
d.val = v.GetValue()
d.prec = v.GetPrecision()
return nil
}
func (br *BalanceResponseBody) ToGRPCMessage() grpc.Message {
var m *accounting.BalanceResponse_Body
if br != nil {
m = new(accounting.BalanceResponse_Body)
m.SetBalance(br.bal.ToGRPCMessage().(*accounting.Decimal))
}
return m
}
func (br *BalanceResponseBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*accounting.BalanceResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
bal := v.GetBalance()
if bal == nil {
br.bal = nil
} else {
if br.bal == nil {
br.bal = new(Decimal)
}
err = br.bal.FromGRPCMessage(bal)
}
return err
}
func (br *BalanceResponse) ToGRPCMessage() grpc.Message {
var m *accounting.BalanceResponse
if br != nil {
m = new(accounting.BalanceResponse)
m.SetBody(br.body.ToGRPCMessage().(*accounting.BalanceResponse_Body))
br.ResponseHeaders.ToMessage(m)
}
return m
}
func (br *BalanceResponse) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*accounting.BalanceResponse)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
br.body = nil
} else {
if br.body == nil {
br.body = new(BalanceResponseBody)
}
err = br.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return br.ResponseHeaders.FromMessage(v)
}

Binary file not shown.

BIN
accounting/grpc/service_frostfs.pb.go generated Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
accounting/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,14 +0,0 @@
package accounting
import (
accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (d *Decimal) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(d)
}
func (d *Decimal) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(d, data, new(accounting.Decimal))
}

View file

@ -1,104 +0,0 @@
package accounting
import (
accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
decimalValueField = 1
decimalPrecisionField = 2
balanceReqBodyOwnerField = 1
balanceRespBodyDecimalField = 1
)
func (d *Decimal) StableMarshal(buf []byte) []byte {
if d == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, d.StableSize())
}
var offset int
offset += protoutil.Int64Marshal(decimalValueField, buf[offset:], d.val)
protoutil.UInt32Marshal(decimalPrecisionField, buf[offset:], d.prec)
return buf
}
func (d *Decimal) StableSize() (size int) {
if d == nil {
return 0
}
size += protoutil.Int64Size(decimalValueField, d.val)
size += protoutil.UInt32Size(decimalPrecisionField, d.prec)
return size
}
func (d *Decimal) Unmarshal(data []byte) error {
return message.Unmarshal(d, data, new(accounting.Decimal))
}
func (b *BalanceRequestBody) StableMarshal(buf []byte) []byte {
if b == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, b.StableSize())
}
protoutil.NestedStructureMarshal(balanceReqBodyOwnerField, buf, b.ownerID)
return buf
}
func (b *BalanceRequestBody) StableSize() (size int) {
if b == nil {
return 0
}
size = protoutil.NestedStructureSize(balanceReqBodyOwnerField, b.ownerID)
return size
}
func (b *BalanceRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(b, data, new(accounting.BalanceRequest_Body))
}
func (br *BalanceResponseBody) StableMarshal(buf []byte) []byte {
if br == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, br.StableSize())
}
protoutil.NestedStructureMarshal(balanceRespBodyDecimalField, buf, br.bal)
return buf
}
func (br *BalanceResponseBody) StableSize() (size int) {
if br == nil {
return 0
}
size = protoutil.NestedStructureSize(balanceRespBodyDecimalField, br.bal)
return size
}
func (br *BalanceResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(br, data, new(accounting.BalanceResponse_Body))
}

View file

@ -4,16 +4,16 @@ import (
"testing"
accountingtest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
"google.golang.org/protobuf/proto"
)
func TestMessage(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return accountingtest.GenerateDecimal(empty) },
func(empty bool) message.Message { return accountingtest.GenerateBalanceRequestBody(empty) },
func(empty bool) message.Message { return accountingtest.GenerateBalanceRequest(empty) },
func(empty bool) message.Message { return accountingtest.GenerateBalanceResponseBody(empty) },
func(empty bool) message.Message { return accountingtest.GenerateBalanceResponse(empty) },
func(empty bool) proto.Message { return accountingtest.GenerateDecimal(empty) },
func(empty bool) proto.Message { return accountingtest.GenerateBalanceRequestBody(empty) },
func(empty bool) proto.Message { return accountingtest.GenerateBalanceRequest(empty) },
func(empty bool) proto.Message { return accountingtest.GenerateBalanceResponseBody(empty) },
func(empty bool) proto.Message { return accountingtest.GenerateBalanceResponse(empty) },
)
}

View file

@ -1,7 +1,7 @@
package accountingtest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting"
accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc"
accountingtest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test"
)
@ -14,16 +14,16 @@ func GenerateBalanceRequest(empty bool) *accounting.BalanceRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateBalanceRequestBody(empty bool) *accounting.BalanceRequestBody {
m := new(accounting.BalanceRequestBody)
func GenerateBalanceRequestBody(empty bool) *accounting.BalanceRequest_Body {
m := new(accounting.BalanceRequest_Body)
if !empty {
m.SetOwnerID(accountingtest.GenerateOwnerID(false))
m.SetOwnerId(accountingtest.GenerateOwnerID(false))
}
return m
@ -37,13 +37,13 @@ func GenerateBalanceResponse(empty bool) *accounting.BalanceResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateBalanceResponseBody(empty bool) *accounting.BalanceResponseBody {
m := new(accounting.BalanceResponseBody)
func GenerateBalanceResponseBody(empty bool) *accounting.BalanceResponse_Body {
m := new(accounting.BalanceResponse_Body)
if !empty {
m.SetBalance(GenerateDecimal(false))
@ -54,7 +54,6 @@ func GenerateBalanceResponseBody(empty bool) *accounting.BalanceResponseBody {
func GenerateDecimal(empty bool) *accounting.Decimal {
m := new(accounting.Decimal)
if !empty {
m.SetValue(1)
m.SetPrecision(2)

View file

@ -3,24 +3,23 @@ package acl_test
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl"
aclGrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
)
func BenchmarkTable_ToGRPCMessage(b *testing.B) {
func BenchmarkTable_StableMarshal(b *testing.B) {
const size = 4
tb := new(acl.Table)
rs := make([]acl.Record, size)
tb := new(acl.EACLTable)
rs := acltest.GenerateRecords(true)
for i := range rs {
fs := make([]acl.HeaderFilter, size)
fs := make([]*acl.EACLRecord_Filter, size)
for j := range fs {
fs[j] = *acltest.GenerateFilter(false)
fs[j] = acltest.GenerateFilter(false)
}
ts := make([]acl.Target, size)
ts := make([]*acl.EACLRecord_Target, size)
for j := range ts {
ts[j] = *acltest.GenerateTarget(false)
ts[j] = acltest.GenerateTarget(false)
}
rs[i].SetFilters(fs)
@ -28,24 +27,10 @@ func BenchmarkTable_ToGRPCMessage(b *testing.B) {
}
tb.SetRecords(rs)
raw := tb.ToGRPCMessage()
b.Run("to grpc message", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
raw := tb.ToGRPCMessage()
if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) {
b.FailNow()
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if len(tb.StableMarshal(nil)) != tb.StableSize() {
b.FailNow()
}
})
b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
tb := new(acl.Table)
if tb.FromGRPCMessage(raw) != nil {
b.FailNow()
}
}
})
}
}

View file

@ -1,535 +0,0 @@
package acl
import (
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
// RoleToGRPCField converts unified role enum into grpc enum.
func RoleToGRPCField(t Role) acl.Role {
switch t {
case RoleUser:
return acl.Role_USER
case RoleSystem:
return acl.Role_SYSTEM
case RoleOthers:
return acl.Role_OTHERS
default:
return acl.Role_ROLE_UNSPECIFIED
}
}
// RoleFromGRPCField converts grpc enum into unified role enum.
func RoleFromGRPCField(t acl.Role) Role {
switch t {
case acl.Role_USER:
return RoleUser
case acl.Role_SYSTEM:
return RoleSystem
case acl.Role_OTHERS:
return RoleOthers
default:
return RoleUnknown
}
}
// OperationToGRPCField converts unified operation enum into grpc enum.
func OperationToGRPCField(t Operation) acl.Operation {
switch t {
case OperationPut:
return acl.Operation_PUT
case OperationDelete:
return acl.Operation_DELETE
case OperationGet:
return acl.Operation_GET
case OperationHead:
return acl.Operation_HEAD
case OperationSearch:
return acl.Operation_SEARCH
case OperationRange:
return acl.Operation_GETRANGE
case OperationRangeHash:
return acl.Operation_GETRANGEHASH
default:
return acl.Operation_OPERATION_UNSPECIFIED
}
}
// OperationFromGRPCField converts grpc enum into unified operation enum.
func OperationFromGRPCField(t acl.Operation) Operation {
switch t {
case acl.Operation_PUT:
return OperationPut
case acl.Operation_DELETE:
return OperationDelete
case acl.Operation_GET:
return OperationGet
case acl.Operation_HEAD:
return OperationHead
case acl.Operation_SEARCH:
return OperationSearch
case acl.Operation_GETRANGE:
return OperationRange
case acl.Operation_GETRANGEHASH:
return OperationRangeHash
default:
return OperationUnknown
}
}
// ActionToGRPCField converts unified action enum into grpc enum.
func ActionToGRPCField(t Action) acl.Action {
switch t {
case ActionDeny:
return acl.Action_DENY
case ActionAllow:
return acl.Action_ALLOW
default:
return acl.Action_ACTION_UNSPECIFIED
}
}
// ActionFromGRPCField converts grpc enum into unified action enum.
func ActionFromGRPCField(t acl.Action) Action {
switch t {
case acl.Action_DENY:
return ActionDeny
case acl.Action_ALLOW:
return ActionAllow
default:
return ActionUnknown
}
}
// HeaderTypeToGRPCField converts unified header type enum into grpc enum.
func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType {
switch t {
case HeaderTypeRequest:
return acl.HeaderType_REQUEST
case HeaderTypeObject:
return acl.HeaderType_OBJECT
case HeaderTypeService:
return acl.HeaderType_SERVICE
default:
return acl.HeaderType_HEADER_UNSPECIFIED
}
}
// HeaderTypeFromGRPCField converts grpc enum into unified header type enum.
func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType {
switch t {
case acl.HeaderType_REQUEST:
return HeaderTypeRequest
case acl.HeaderType_OBJECT:
return HeaderTypeObject
case acl.HeaderType_SERVICE:
return HeaderTypeService
default:
return HeaderTypeUnknown
}
}
// MatchTypeToGRPCField converts unified match type enum into grpc enum.
func MatchTypeToGRPCField(t MatchType) acl.MatchType {
switch t {
case MatchTypeStringEqual:
return acl.MatchType_STRING_EQUAL
case MatchTypeStringNotEqual:
return acl.MatchType_STRING_NOT_EQUAL
default:
return acl.MatchType_MATCH_TYPE_UNSPECIFIED
}
}
// MatchTypeFromGRPCField converts grpc enum into unified match type enum.
func MatchTypeFromGRPCField(t acl.MatchType) MatchType {
switch t {
case acl.MatchType_STRING_EQUAL:
return MatchTypeStringEqual
case acl.MatchType_STRING_NOT_EQUAL:
return MatchTypeStringNotEqual
default:
return MatchTypeUnknown
}
}
func (f *HeaderFilter) ToGRPCMessage() grpc.Message {
var m *acl.EACLRecord_Filter
if f != nil {
m = new(acl.EACLRecord_Filter)
m.SetKey(f.key)
m.SetValue(f.value)
m.SetHeader(HeaderTypeToGRPCField(f.hdrType))
m.SetMatchType(MatchTypeToGRPCField(f.matchType))
}
return m
}
func (f *HeaderFilter) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.EACLRecord_Filter)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
f.key = v.GetKey()
f.value = v.GetValue()
f.hdrType = HeaderTypeFromGRPCField(v.GetHeaderType())
f.matchType = MatchTypeFromGRPCField(v.GetMatchType())
return nil
}
func HeaderFiltersToGRPC(fs []HeaderFilter) (res []*acl.EACLRecord_Filter) {
if fs != nil {
res = make([]*acl.EACLRecord_Filter, 0, len(fs))
for i := range fs {
res = append(res, fs[i].ToGRPCMessage().(*acl.EACLRecord_Filter))
}
}
return
}
func HeaderFiltersFromGRPC(fs []*acl.EACLRecord_Filter) (res []HeaderFilter, err error) {
if fs != nil {
res = make([]HeaderFilter, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
}
}
}
return
}
func (t *Target) ToGRPCMessage() grpc.Message {
var m *acl.EACLRecord_Target
if t != nil {
m = new(acl.EACLRecord_Target)
m.SetRole(RoleToGRPCField(t.role))
m.SetKeys(t.keys)
}
return m
}
func (t *Target) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.EACLRecord_Target)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
t.role = RoleFromGRPCField(v.GetRole())
t.keys = v.GetKeys()
return nil
}
func TargetsToGRPC(ts []Target) (res []*acl.EACLRecord_Target) {
if ts != nil {
res = make([]*acl.EACLRecord_Target, 0, len(ts))
for i := range ts {
res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord_Target))
}
}
return
}
func TargetsFromGRPC(fs []*acl.EACLRecord_Target) (res []Target, err error) {
if fs != nil {
res = make([]Target, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
}
}
}
return
}
func (r *Record) ToGRPCMessage() grpc.Message {
var m *acl.EACLRecord
if r != nil {
m = new(acl.EACLRecord)
m.SetOperation(OperationToGRPCField(r.op))
m.SetAction(ActionToGRPCField(r.action))
m.SetFilters(HeaderFiltersToGRPC(r.filters))
m.SetTargets(TargetsToGRPC(r.targets))
}
return m
}
func (r *Record) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.EACLRecord)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
r.filters, err = HeaderFiltersFromGRPC(v.GetFilters())
if err != nil {
return err
}
r.targets, err = TargetsFromGRPC(v.GetTargets())
if err != nil {
return err
}
r.op = OperationFromGRPCField(v.GetOperation())
r.action = ActionFromGRPCField(v.GetAction())
return nil
}
func RecordsToGRPC(ts []Record) (res []*acl.EACLRecord) {
if ts != nil {
res = make([]*acl.EACLRecord, 0, len(ts))
for i := range ts {
res = append(res, ts[i].ToGRPCMessage().(*acl.EACLRecord))
}
}
return
}
func RecordsFromGRPC(fs []*acl.EACLRecord) (res []Record, err error) {
if fs != nil {
res = make([]Record, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
}
}
}
return
}
func (t *Table) ToGRPCMessage() grpc.Message {
var m *acl.EACLTable
if t != nil {
m = new(acl.EACLTable)
m.SetVersion(t.version.ToGRPCMessage().(*refsGRPC.Version))
m.SetContainerId(t.cid.ToGRPCMessage().(*refsGRPC.ContainerID))
m.SetRecords(RecordsToGRPC(t.records))
}
return m
}
func (t *Table) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.EACLTable)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
cid := v.GetContainerId()
if cid == nil {
t.cid = nil
} else {
if t.cid == nil {
t.cid = new(refs.ContainerID)
}
err = t.cid.FromGRPCMessage(cid)
if err != nil {
return err
}
}
version := v.GetVersion()
if version == nil {
t.version = nil
} else {
if t.version == nil {
t.version = new(refs.Version)
}
err = t.version.FromGRPCMessage(version)
if err != nil {
return err
}
}
t.records, err = RecordsFromGRPC(v.GetRecords())
return err
}
func (l *TokenLifetime) ToGRPCMessage() grpc.Message {
var m *acl.BearerToken_Body_TokenLifetime
if l != nil {
m = new(acl.BearerToken_Body_TokenLifetime)
m.SetExp(l.exp)
m.SetIat(l.iat)
m.SetNbf(l.nbf)
}
return m
}
func (l *TokenLifetime) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.BearerToken_Body_TokenLifetime)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
l.exp = v.GetExp()
l.iat = v.GetIat()
l.nbf = v.GetNbf()
return nil
}
func (bt *BearerTokenBody) ToGRPCMessage() grpc.Message {
var m *acl.BearerToken_Body
if bt != nil {
m = new(acl.BearerToken_Body)
m.SetOwnerId(bt.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))
m.SetLifetime(bt.lifetime.ToGRPCMessage().(*acl.BearerToken_Body_TokenLifetime))
m.SetEaclTable(bt.eacl.ToGRPCMessage().(*acl.EACLTable))
m.SetImpersonate(bt.impersonate)
}
return m
}
func (bt *BearerTokenBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.BearerToken_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
ownerID := v.GetOwnerId()
if ownerID == nil {
bt.ownerID = nil
} else {
if bt.ownerID == nil {
bt.ownerID = new(refs.OwnerID)
}
err = bt.ownerID.FromGRPCMessage(ownerID)
if err != nil {
return err
}
}
lifetime := v.GetLifetime()
if lifetime == nil {
bt.lifetime = nil
} else {
if bt.lifetime == nil {
bt.lifetime = new(TokenLifetime)
}
err = bt.lifetime.FromGRPCMessage(lifetime)
if err != nil {
return err
}
}
eacl := v.GetEaclTable()
if eacl == nil {
bt.eacl = nil
} else {
if bt.eacl == nil {
bt.eacl = new(Table)
}
err = bt.eacl.FromGRPCMessage(eacl)
}
bt.impersonate = v.GetAllowImpersonate()
return err
}
func (bt *BearerToken) ToGRPCMessage() grpc.Message {
var m *acl.BearerToken
if bt != nil {
m = new(acl.BearerToken)
m.SetBody(bt.body.ToGRPCMessage().(*acl.BearerToken_Body))
m.SetSignature(bt.sig.ToGRPCMessage().(*refsGRPC.Signature))
}
return m
}
func (bt *BearerToken) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*acl.BearerToken)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
bt.body = nil
} else {
if bt.body == nil {
bt.body = new(BearerTokenBody)
}
err = bt.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
sig := v.GetSignature()
if sig == nil {
bt.sig = nil
} else {
if bt.sig == nil {
bt.sig = new(refs.Signature)
}
err = bt.sig.FromGRPCMessage(sig)
}
return err
}

BIN
acl/grpc/types.pb.go generated

Binary file not shown.

BIN
acl/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,62 +0,0 @@
package acl
import (
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (f *HeaderFilter) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(f)
}
func (f *HeaderFilter) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(f, data, new(acl.EACLRecord_Filter))
}
func (t *Target) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(t)
}
func (t *Target) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(t, data, new(acl.EACLRecord_Target))
}
func (r *Record) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(r)
}
func (r *Record) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(r, data, new(acl.EACLRecord))
}
func (t *Table) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(t)
}
func (t *Table) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(t, data, new(acl.EACLTable))
}
func (l *TokenLifetime) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(l)
}
func (l *TokenLifetime) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(l, data, new(acl.BearerToken_Body_TokenLifetime))
}
func (bt *BearerTokenBody) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(bt)
}
func (bt *BearerTokenBody) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(bt, data, new(acl.BearerToken_Body))
}
func (bt *BearerToken) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(bt)
}
func (bt *BearerToken) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(bt, data, new(acl.BearerToken))
}

View file

@ -1,308 +0,0 @@
package acl
import (
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
filterHeaderTypeField = 1
filterMatchTypeField = 2
filterNameField = 3
filterValueField = 4
targetTypeField = 1
targetKeysField = 2
recordOperationField = 1
recordActionField = 2
recordFiltersField = 3
recordTargetsField = 4
tableVersionField = 1
tableContainerIDField = 2
tableRecordsField = 3
lifetimeExpirationField = 1
lifetimeNotValidBeforeField = 2
lifetimeIssuedAtField = 3
bearerTokenBodyACLField = 1
bearerTokenBodyOwnerField = 2
bearerTokenBodyLifetimeField = 3
bearerTokenBodyImpersonate = 4
bearerTokenBodyField = 1
bearerTokenSignatureField = 2
)
// StableMarshal marshals unified acl table structure in a protobuf
// compatible way without field order shuffle.
func (t *Table) StableMarshal(buf []byte) []byte {
if t == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, t.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(tableVersionField, buf[offset:], t.version)
offset += protoutil.NestedStructureMarshal(tableContainerIDField, buf[offset:], t.cid)
for i := range t.records {
offset += protoutil.NestedStructureMarshal(tableRecordsField, buf[offset:], &t.records[i])
}
return buf
}
// StableSize of acl table structure marshalled by StableMarshal function.
func (t *Table) StableSize() (size int) {
if t == nil {
return 0
}
size += protoutil.NestedStructureSize(tableVersionField, t.version)
size += protoutil.NestedStructureSize(tableContainerIDField, t.cid)
for i := range t.records {
size += protoutil.NestedStructureSize(tableRecordsField, &t.records[i])
}
return size
}
func (t *Table) Unmarshal(data []byte) error {
return message.Unmarshal(t, data, new(acl.EACLTable))
}
// StableMarshal marshals unified acl record structure in a protobuf
// compatible way without field order shuffle.
func (r *Record) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += protoutil.EnumMarshal(recordOperationField, buf[offset:], int32(r.op))
offset += protoutil.EnumMarshal(recordActionField, buf[offset:], int32(r.action))
for i := range r.filters {
offset += protoutil.NestedStructureMarshal(recordFiltersField, buf[offset:], &r.filters[i])
}
for i := range r.targets {
offset += protoutil.NestedStructureMarshal(recordTargetsField, buf[offset:], &r.targets[i])
}
return buf
}
// StableSize of acl record structure marshalled by StableMarshal function.
func (r *Record) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.EnumSize(recordOperationField, int32(r.op))
size += protoutil.EnumSize(recordActionField, int32(r.action))
for i := range r.filters {
size += protoutil.NestedStructureSize(recordFiltersField, &r.filters[i])
}
for i := range r.targets {
size += protoutil.NestedStructureSize(recordTargetsField, &r.targets[i])
}
return size
}
func (r *Record) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(acl.EACLRecord))
}
// StableMarshal marshals unified header filter structure in a protobuf
// compatible way without field order shuffle.
func (f *HeaderFilter) StableMarshal(buf []byte) []byte {
if f == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, f.StableSize())
}
var offset int
offset += protoutil.EnumMarshal(filterHeaderTypeField, buf[offset:], int32(f.hdrType))
offset += protoutil.EnumMarshal(filterMatchTypeField, buf[offset:], int32(f.matchType))
offset += protoutil.StringMarshal(filterNameField, buf[offset:], f.key)
protoutil.StringMarshal(filterValueField, buf[offset:], f.value)
return buf
}
// StableSize of header filter structure marshalled by StableMarshal function.
func (f *HeaderFilter) StableSize() (size int) {
if f == nil {
return 0
}
size += protoutil.EnumSize(filterHeaderTypeField, int32(f.hdrType))
size += protoutil.EnumSize(filterMatchTypeField, int32(f.matchType))
size += protoutil.StringSize(filterNameField, f.key)
size += protoutil.StringSize(filterValueField, f.value)
return size
}
func (f *HeaderFilter) Unmarshal(data []byte) error {
return message.Unmarshal(f, data, new(acl.EACLRecord_Filter))
}
// StableMarshal marshals unified role info structure in a protobuf
// compatible way without field order shuffle.
func (t *Target) StableMarshal(buf []byte) []byte {
if t == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, t.StableSize())
}
var offset int
offset += protoutil.EnumMarshal(targetTypeField, buf[offset:], int32(t.role))
protoutil.RepeatedBytesMarshal(targetKeysField, buf[offset:], t.keys)
return buf
}
// StableSize of role info structure marshalled by StableMarshal function.
func (t *Target) StableSize() (size int) {
if t == nil {
return 0
}
size += protoutil.EnumSize(targetTypeField, int32(t.role))
size += protoutil.RepeatedBytesSize(targetKeysField, t.keys)
return size
}
func (t *Target) Unmarshal(data []byte) error {
return message.Unmarshal(t, data, new(acl.EACLRecord_Target))
}
func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
if l == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, l.StableSize())
}
var offset int
offset += protoutil.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp)
offset += protoutil.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf)
protoutil.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat)
return buf
}
func (l *TokenLifetime) StableSize() (size int) {
if l == nil {
return 0
}
size += protoutil.UInt64Size(lifetimeExpirationField, l.exp)
size += protoutil.UInt64Size(lifetimeNotValidBeforeField, l.nbf)
size += protoutil.UInt64Size(lifetimeIssuedAtField, l.iat)
return size
}
func (l *TokenLifetime) Unmarshal(data []byte) error {
return message.Unmarshal(l, data, new(acl.BearerToken_Body_TokenLifetime))
}
func (bt *BearerTokenBody) StableMarshal(buf []byte) []byte {
if bt == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, bt.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID)
offset += protoutil.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime)
protoutil.BoolMarshal(bearerTokenBodyImpersonate, buf[offset:], bt.impersonate)
return buf
}
func (bt *BearerTokenBody) StableSize() (size int) {
if bt == nil {
return 0
}
size += protoutil.NestedStructureSize(bearerTokenBodyACLField, bt.eacl)
size += protoutil.NestedStructureSize(bearerTokenBodyOwnerField, bt.ownerID)
size += protoutil.NestedStructureSize(bearerTokenBodyLifetimeField, bt.lifetime)
size += protoutil.BoolSize(bearerTokenBodyImpersonate, bt.impersonate)
return size
}
func (bt *BearerTokenBody) Unmarshal(data []byte) error {
return message.Unmarshal(bt, data, new(acl.BearerToken_Body))
}
func (bt *BearerToken) StableMarshal(buf []byte) []byte {
if bt == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, bt.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(bearerTokenBodyField, buf[offset:], bt.body)
protoutil.NestedStructureMarshal(bearerTokenSignatureField, buf[offset:], bt.sig)
return buf
}
func (bt *BearerToken) StableSize() (size int) {
if bt == nil {
return 0
}
size += protoutil.NestedStructureSize(bearerTokenBodyField, bt.body)
size += protoutil.NestedStructureSize(bearerTokenSignatureField, bt.sig)
return size
}
func (bt *BearerToken) Unmarshal(data []byte) error {
return message.Unmarshal(bt, data, new(acl.BearerToken))
}

View file

@ -4,18 +4,18 @@ import (
"testing"
acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
"google.golang.org/protobuf/proto"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return acltest.GenerateFilter(empty) },
func(empty bool) message.Message { return acltest.GenerateTarget(empty) },
func(empty bool) message.Message { return acltest.GenerateRecord(empty) },
func(empty bool) message.Message { return acltest.GenerateTable(empty) },
func(empty bool) message.Message { return acltest.GenerateTokenLifetime(empty) },
func(empty bool) message.Message { return acltest.GenerateBearerTokenBody(empty) },
func(empty bool) message.Message { return acltest.GenerateBearerToken(empty) },
func(empty bool) proto.Message { return acltest.GenerateFilter(empty) },
func(empty bool) proto.Message { return acltest.GenerateTarget(empty) },
func(empty bool) proto.Message { return acltest.GenerateRecord(empty) },
func(empty bool) proto.Message { return acltest.GenerateTable(empty) },
func(empty bool) proto.Message { return acltest.GenerateTokenLifetime(empty) },
func(empty bool) proto.Message { return acltest.GenerateBearerTokenBody(empty) },
func(empty bool) proto.Message { return acltest.GenerateBearerToken(empty) },
)
}

View file

@ -1,110 +0,0 @@
package acl
import (
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
)
// String returns string representation of Action.
func (x Action) String() string {
return ActionToGRPCField(x).String()
}
// FromString parses Action from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Action) FromString(s string) bool {
var g acl.Action
ok := g.FromString(s)
if ok {
*x = ActionFromGRPCField(g)
}
return ok
}
// String returns string representation of Role.
func (x Role) String() string {
return RoleToGRPCField(x).String()
}
// FromString parses Role from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Role) FromString(s string) bool {
var g acl.Role
ok := g.FromString(s)
if ok {
*x = RoleFromGRPCField(g)
}
return ok
}
// String returns string representation of Operation.
func (x Operation) String() string {
return OperationToGRPCField(x).String()
}
// FromString parses Operation from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Operation) FromString(s string) bool {
var g acl.Operation
ok := g.FromString(s)
if ok {
*x = OperationFromGRPCField(g)
}
return ok
}
// String returns string representation of MatchType.
func (x MatchType) String() string {
return MatchTypeToGRPCField(x).String()
}
// FromString parses MatchType from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *MatchType) FromString(s string) bool {
var g acl.MatchType
ok := g.FromString(s)
if ok {
*x = MatchTypeFromGRPCField(g)
}
return ok
}
// String returns string representation of HeaderType.
func (x HeaderType) String() string {
return HeaderTypeToGRPCField(x).String()
}
// FromString parses HeaderType from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *HeaderType) FromString(s string) bool {
var g acl.HeaderType
ok := g.FromString(s)
if ok {
*x = HeaderTypeFromGRPCField(g)
}
return ok
}

View file

@ -1,7 +1,7 @@
package acltest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl"
acl "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
accountingtest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
)
@ -17,24 +17,24 @@ func GenerateBearerToken(empty bool) *acl.BearerToken {
return m
}
func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody {
m := new(acl.BearerTokenBody)
func GenerateBearerTokenBody(empty bool) *acl.BearerToken_Body {
m := new(acl.BearerToken_Body)
if !empty {
m.SetOwnerID(accountingtest.GenerateOwnerID(false))
m.SetEACL(GenerateTable(false))
m.SetOwnerId(accountingtest.GenerateOwnerID(false))
m.SetEaclTable(GenerateTable(false))
m.SetLifetime(GenerateTokenLifetime(false))
}
return m
}
func GenerateTable(empty bool) *acl.Table {
m := new(acl.Table)
func GenerateTable(empty bool) *acl.EACLTable {
m := new(acl.EACLTable)
if !empty {
m.SetRecords(GenerateRecords(false))
m.SetContainerID(accountingtest.GenerateContainerID(false))
m.SetContainerId(accountingtest.GenerateContainerID(false))
}
m.SetVersion(accountingtest.GenerateVersion(empty))
@ -42,25 +42,25 @@ func GenerateTable(empty bool) *acl.Table {
return m
}
func GenerateRecords(empty bool) []acl.Record {
var rs []acl.Record
func GenerateRecords(empty bool) []*acl.EACLRecord {
var rs []*acl.EACLRecord
if !empty {
rs = append(rs,
*GenerateRecord(false),
*GenerateRecord(false),
GenerateRecord(false),
GenerateRecord(false),
)
}
return rs
}
func GenerateRecord(empty bool) *acl.Record {
m := new(acl.Record)
func GenerateRecord(empty bool) *acl.EACLRecord {
m := new(acl.EACLRecord)
if !empty {
m.SetAction(acl.ActionAllow)
m.SetOperation(acl.OperationGet)
m.SetAction(acl.Action_ALLOW)
m.SetOperation(acl.Operation_GET)
m.SetFilters(GenerateFilters(false))
m.SetTargets(GenerateTargets(false))
}
@ -68,58 +68,58 @@ func GenerateRecord(empty bool) *acl.Record {
return m
}
func GenerateFilters(empty bool) []acl.HeaderFilter {
var fs []acl.HeaderFilter
func GenerateFilters(empty bool) []*acl.EACLRecord_Filter {
var fs []*acl.EACLRecord_Filter
if !empty {
fs = append(fs,
*GenerateFilter(false),
*GenerateFilter(false),
GenerateFilter(false),
GenerateFilter(false),
)
}
return fs
}
func GenerateFilter(empty bool) *acl.HeaderFilter {
m := new(acl.HeaderFilter)
func GenerateFilter(empty bool) *acl.EACLRecord_Filter {
m := new(acl.EACLRecord_Filter)
if !empty {
m.SetKey("key")
m.SetValue("val")
m.SetHeaderType(acl.HeaderTypeRequest)
m.SetMatchType(acl.MatchTypeStringEqual)
m.SetHeader(acl.HeaderType_REQUEST)
m.SetMatchType(acl.MatchType_STRING_EQUAL)
}
return m
}
func GenerateTargets(empty bool) []acl.Target {
var ts []acl.Target
func GenerateTargets(empty bool) []*acl.EACLRecord_Target {
var ts []*acl.EACLRecord_Target
if !empty {
ts = append(ts,
*GenerateTarget(false),
*GenerateTarget(false),
GenerateTarget(false),
GenerateTarget(false),
)
}
return ts
}
func GenerateTarget(empty bool) *acl.Target {
m := new(acl.Target)
func GenerateTarget(empty bool) *acl.EACLRecord_Target {
m := new(acl.EACLRecord_Target)
if !empty {
m.SetRole(acl.RoleSystem)
m.SetRole(acl.Role_SYSTEM)
m.SetKeys([][]byte{{1}, {2}})
}
return m
}
func GenerateTokenLifetime(empty bool) *acl.TokenLifetime {
m := new(acl.TokenLifetime)
func GenerateTokenLifetime(empty bool) *acl.BearerToken_Body_TokenLifetime {
m := new(acl.BearerToken_Body_TokenLifetime)
if !empty {
m.SetExp(1)

View file

@ -1,379 +0,0 @@
package acl
import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
// HeaderFilter is a unified structure of FilterInfo
// message from proto definition.
type HeaderFilter struct {
hdrType HeaderType
matchType MatchType
key, value string
}
// Target is a unified structure of Target
// message from proto definition.
type Target struct {
role Role
keys [][]byte
}
// Record is a unified structure of EACLRecord
// message from proto definition.
type Record struct {
op Operation
action Action
filters []HeaderFilter
targets []Target
}
// Table is a unified structure of EACLTable
// message from proto definition.
type Table struct {
version *refs.Version
cid *refs.ContainerID
records []Record
}
type TokenLifetime struct {
exp, nbf, iat uint64
}
type BearerTokenBody struct {
eacl *Table
ownerID *refs.OwnerID
lifetime *TokenLifetime
impersonate bool
}
type BearerToken struct {
body *BearerTokenBody
sig *refs.Signature
}
// Target is a unified enum of MatchType enum from proto definition.
type MatchType uint32
// HeaderType is a unified enum of HeaderType enum from proto definition.
type HeaderType uint32
// Action is a unified enum of Action enum from proto definition.
type Action uint32
// Operation is a unified enum of Operation enum from proto definition.
type Operation uint32
// Role is a unified enum of Role enum from proto definition.
type Role uint32
const (
MatchTypeUnknown MatchType = iota
MatchTypeStringEqual
MatchTypeStringNotEqual
)
const (
HeaderTypeUnknown HeaderType = iota
HeaderTypeRequest
HeaderTypeObject
HeaderTypeService
)
const (
ActionUnknown Action = iota
ActionAllow
ActionDeny
)
const (
OperationUnknown Operation = iota
OperationGet
OperationHead
OperationPut
OperationDelete
OperationSearch
OperationRange
OperationRangeHash
)
const (
RoleUnknown Role = iota
RoleUser
RoleSystem
RoleOthers
)
func (f *HeaderFilter) GetHeaderType() HeaderType {
if f != nil {
return f.hdrType
}
return HeaderTypeUnknown
}
func (f *HeaderFilter) SetHeaderType(v HeaderType) {
f.hdrType = v
}
func (f *HeaderFilter) GetMatchType() MatchType {
if f != nil {
return f.matchType
}
return MatchTypeUnknown
}
func (f *HeaderFilter) SetMatchType(v MatchType) {
f.matchType = v
}
func (f *HeaderFilter) GetKey() string {
if f != nil {
return f.key
}
return ""
}
func (f *HeaderFilter) SetKey(v string) {
f.key = v
}
func (f *HeaderFilter) GetValue() string {
if f != nil {
return f.value
}
return ""
}
func (f *HeaderFilter) SetValue(v string) {
f.value = v
}
func (t *Target) GetRole() Role {
if t != nil {
return t.role
}
return RoleUnknown
}
func (t *Target) SetRole(v Role) {
t.role = v
}
func (t *Target) GetKeys() [][]byte {
if t != nil {
return t.keys
}
return nil
}
func (t *Target) SetKeys(v [][]byte) {
t.keys = v
}
func (r *Record) GetOperation() Operation {
if r != nil {
return r.op
}
return OperationUnknown
}
func (r *Record) SetOperation(v Operation) {
r.op = v
}
func (r *Record) GetAction() Action {
if r != nil {
return r.action
}
return ActionUnknown
}
func (r *Record) SetAction(v Action) {
r.action = v
}
func (r *Record) GetFilters() []HeaderFilter {
if r != nil {
return r.filters
}
return nil
}
func (r *Record) SetFilters(v []HeaderFilter) {
r.filters = v
}
func (r *Record) GetTargets() []Target {
if r != nil {
return r.targets
}
return nil
}
func (r *Record) SetTargets(v []Target) {
r.targets = v
}
func (t *Table) GetVersion() *refs.Version {
if t != nil {
return t.version
}
return nil
}
func (t *Table) SetVersion(v *refs.Version) {
t.version = v
}
func (t *Table) GetContainerID() *refs.ContainerID {
if t != nil {
return t.cid
}
return nil
}
func (t *Table) SetContainerID(v *refs.ContainerID) {
t.cid = v
}
func (t *Table) GetRecords() []Record {
if t != nil {
return t.records
}
return nil
}
func (t *Table) SetRecords(v []Record) {
t.records = v
}
func (l *TokenLifetime) GetExp() uint64 {
if l != nil {
return l.exp
}
return 0
}
func (l *TokenLifetime) SetExp(v uint64) {
l.exp = v
}
func (l *TokenLifetime) GetNbf() uint64 {
if l != nil {
return l.nbf
}
return 0
}
func (l *TokenLifetime) SetNbf(v uint64) {
l.nbf = v
}
func (l *TokenLifetime) GetIat() uint64 {
if l != nil {
return l.iat
}
return 0
}
func (l *TokenLifetime) SetIat(v uint64) {
l.iat = v
}
func (bt *BearerTokenBody) GetEACL() *Table {
if bt != nil {
return bt.eacl
}
return nil
}
func (bt *BearerTokenBody) SetEACL(v *Table) {
bt.eacl = v
}
func (bt *BearerTokenBody) GetOwnerID() *refs.OwnerID {
if bt != nil {
return bt.ownerID
}
return nil
}
func (bt *BearerTokenBody) SetOwnerID(v *refs.OwnerID) {
bt.ownerID = v
}
func (bt *BearerTokenBody) GetLifetime() *TokenLifetime {
if bt != nil {
return bt.lifetime
}
return nil
}
func (bt *BearerTokenBody) SetLifetime(v *TokenLifetime) {
bt.lifetime = v
}
func (bt *BearerTokenBody) GetImpersonate() bool {
if bt != nil {
return bt.impersonate
}
return false
}
func (bt *BearerTokenBody) SetImpersonate(v bool) {
bt.impersonate = v
}
func (bt *BearerToken) GetBody() *BearerTokenBody {
if bt != nil {
return bt.body
}
return nil
}
func (bt *BearerToken) SetBody(v *BearerTokenBody) {
bt.body = v
}
func (bt *BearerToken) GetSignature() *refs.Signature {
if bt != nil {
return bt.sig
}
return nil
}
func (bt *BearerToken) SetSignature(v *refs.Signature) {
bt.sig = v
}

View file

@ -1,94 +0,0 @@
package audit
import (
audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (a *DataAuditResult) ToGRPCMessage() grpc.Message {
var m *audit.DataAuditResult
if a != nil {
m = new(audit.DataAuditResult)
m.SetAuditEpoch(a.auditEpoch)
m.SetPublicKey(a.pubKey)
m.SetContainerId(a.cid.ToGRPCMessage().(*refsGRPC.ContainerID))
m.SetComplete(a.complete)
m.SetVersion(a.version.ToGRPCMessage().(*refsGRPC.Version))
m.SetPassNodes(a.passNodes)
m.SetFailNodes(a.failNodes)
m.SetRetries(a.retries)
m.SetRequests(a.requests)
m.SetHit(a.hit)
m.SetMiss(a.miss)
m.SetFail(a.fail)
m.SetPassSg(refs.ObjectIDListToGRPCMessage(a.passSG))
m.SetFailSg(refs.ObjectIDListToGRPCMessage(a.failSG))
}
return m
}
func (a *DataAuditResult) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*audit.DataAuditResult)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
cid := v.GetContainerId()
if cid == nil {
a.cid = nil
} else {
if a.cid == nil {
a.cid = new(refs.ContainerID)
}
err = a.cid.FromGRPCMessage(cid)
if err != nil {
return err
}
}
version := v.GetVersion()
if version == nil {
a.version = nil
} else {
if a.version == nil {
a.version = new(refs.Version)
}
err = a.version.FromGRPCMessage(version)
if err != nil {
return err
}
}
a.passSG, err = refs.ObjectIDListFromGRPCMessage(v.GetPassSg())
if err != nil {
return err
}
a.failSG, err = refs.ObjectIDListFromGRPCMessage(v.GetFailSg())
if err != nil {
return err
}
a.auditEpoch = v.GetAuditEpoch()
a.pubKey = v.GetPublicKey()
a.complete = v.GetComplete()
a.passNodes = v.GetPassNodes()
a.failNodes = v.GetFailNodes()
a.retries = v.GetRetries()
a.requests = v.GetRequests()
a.hit = v.GetHit()
a.miss = v.GetMiss()
a.fail = v.GetFail()
return err
}

BIN
audit/grpc/types.pb.go generated

Binary file not shown.

BIN
audit/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,14 +0,0 @@
package audit
import (
audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (a *DataAuditResult) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(a)
}
func (a *DataAuditResult) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(a, data, new(audit.DataAuditResult))
}

View file

@ -1,88 +0,0 @@
package audit
import (
audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
_ = iota
versionFNum
auditEpochFNum
cidFNum
pubKeyFNum
completeFNum
requestsFNum
retriesFNum
passSGFNum
failSGFNum
hitFNum
missFNum
failFNum
passNodesFNum
failNodesFNum
)
// StableMarshal marshals unified DataAuditResult structure into a protobuf
// binary format without field order shuffle.
func (a *DataAuditResult) StableMarshal(buf []byte) []byte {
if a == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, a.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(versionFNum, buf[offset:], a.version)
offset += proto.Fixed64Marshal(auditEpochFNum, buf[offset:], a.auditEpoch)
offset += proto.NestedStructureMarshal(cidFNum, buf[offset:], a.cid)
offset += proto.BytesMarshal(pubKeyFNum, buf[offset:], a.pubKey)
offset += proto.BoolMarshal(completeFNum, buf[offset:], a.complete)
offset += proto.UInt32Marshal(requestsFNum, buf[offset:], a.requests)
offset += proto.UInt32Marshal(retriesFNum, buf[offset:], a.retries)
offset += refs.ObjectIDNestedListMarshal(passSGFNum, buf[offset:], a.passSG)
offset += refs.ObjectIDNestedListMarshal(failSGFNum, buf[offset:], a.failSG)
offset += proto.UInt32Marshal(hitFNum, buf[offset:], a.hit)
offset += proto.UInt32Marshal(missFNum, buf[offset:], a.miss)
offset += proto.UInt32Marshal(failFNum, buf[offset:], a.fail)
offset += proto.RepeatedBytesMarshal(passNodesFNum, buf[offset:], a.passNodes)
proto.RepeatedBytesMarshal(failNodesFNum, buf[offset:], a.failNodes)
return buf
}
// StableSize returns byte length of DataAuditResult structure
// marshaled by StableMarshal function.
func (a *DataAuditResult) StableSize() (size int) {
if a == nil {
return 0
}
size += proto.NestedStructureSize(versionFNum, a.version)
size += proto.Fixed64Size(auditEpochFNum, a.auditEpoch)
size += proto.NestedStructureSize(cidFNum, a.cid)
size += proto.BytesSize(pubKeyFNum, a.pubKey)
size += proto.BoolSize(completeFNum, a.complete)
size += proto.UInt32Size(requestsFNum, a.requests)
size += proto.UInt32Size(retriesFNum, a.retries)
size += refs.ObjectIDNestedListSize(passSGFNum, a.passSG)
size += refs.ObjectIDNestedListSize(failSGFNum, a.failSG)
size += proto.UInt32Size(hitFNum, a.hit)
size += proto.UInt32Size(missFNum, a.miss)
size += proto.UInt32Size(failFNum, a.fail)
size += proto.RepeatedBytesSize(passNodesFNum, a.passNodes)
size += proto.RepeatedBytesSize(failNodesFNum, a.failNodes)
return size
}
// Unmarshal unmarshals DataAuditResult structure from its protobuf
// binary representation.
func (a *DataAuditResult) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(audit.DataAuditResult))
}

View file

@ -4,12 +4,12 @@ import (
"testing"
audittest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
"google.golang.org/protobuf/proto"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return audittest.GenerateDataAuditResult(empty) },
func(empty bool) proto.Message { return audittest.GenerateDataAuditResult(empty) },
)
}

View file

@ -1,7 +1,7 @@
package audittest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit"
audit "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/audit/grpc"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
)
@ -20,9 +20,9 @@ func GenerateDataAuditResult(empty bool) *audit.DataAuditResult {
m.SetRequests(666)
m.SetRetries(777)
m.SetVersion(refstest.GenerateVersion(false))
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetPassSG(refstest.GenerateObjectIDs(false))
m.SetFailSG(refstest.GenerateObjectIDs(false))
m.SetContainerId(refstest.GenerateContainerID(false))
m.SetPassSg(refstest.GenerateObjectIDs(false))
m.SetFailSg(refstest.GenerateObjectIDs(false))
}
return m

View file

@ -1,243 +0,0 @@
package audit
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
)
// DataAuditResult is a unified structure of
// DataAuditResult message from proto definition.
type DataAuditResult struct {
version *refs.Version
auditEpoch uint64
requests, retries uint32
hit, miss, fail uint32
cid *refs.ContainerID
pubKey []byte
passSG, failSG []refs.ObjectID
failNodes, passNodes [][]byte
complete bool
}
// GetVersion returns version of Data Audit structure.
func (a *DataAuditResult) GetVersion() *refs.Version {
if a != nil {
return a.version
}
return nil
}
// SetVersion sets version of Data Audit structure.
func (a *DataAuditResult) SetVersion(v *refs.Version) {
a.version = v
}
// GetAuditEpoch returns epoch number when the Data Audit was conducted.
func (a *DataAuditResult) GetAuditEpoch() uint64 {
if a != nil {
return a.auditEpoch
}
return 0
}
// SetAuditEpoch sets epoch number when the Data Audit was conducted.
func (a *DataAuditResult) SetAuditEpoch(v uint64) {
a.auditEpoch = v
}
// GetContainerID returns container under audit.
func (a *DataAuditResult) GetContainerID() *refs.ContainerID {
if a != nil {
return a.cid
}
return nil
}
// SetContainerID sets container under audit.
func (a *DataAuditResult) SetContainerID(v *refs.ContainerID) {
a.cid = v
}
// GetPublicKey returns public key of the auditing InnerRing node in a binary format.
func (a *DataAuditResult) GetPublicKey() []byte {
if a != nil {
return a.pubKey
}
return nil
}
// SetPublicKey sets public key of the auditing InnerRing node in a binary format.
func (a *DataAuditResult) SetPublicKey(v []byte) {
a.pubKey = v
}
// GetPassSG returns list of Storage Groups that passed audit PoR stage.
func (a *DataAuditResult) GetPassSG() []refs.ObjectID {
if a != nil {
return a.passSG
}
return nil
}
// SetPassSG sets list of Storage Groups that passed audit PoR stage.
func (a *DataAuditResult) SetPassSG(v []refs.ObjectID) {
a.passSG = v
}
// GetFailSG returns list of Storage Groups that failed audit PoR stage.
func (a *DataAuditResult) GetFailSG() []refs.ObjectID {
if a != nil {
return a.failSG
}
return nil
}
// SetFailSG sets list of Storage Groups that failed audit PoR stage.
func (a *DataAuditResult) SetFailSG(v []refs.ObjectID) {
a.failSG = v
}
// GetRequests returns number of requests made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) GetRequests() uint32 {
if a != nil {
return a.requests
}
return 0
}
// SetRequests sets number of requests made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) SetRequests(v uint32) {
a.requests = v
}
// GetRetries returns number of retries made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) GetRetries() uint32 {
if a != nil {
return a.retries
}
return 0
}
// SetRetries sets number of retries made by PoR audit check to get
// all headers of the objects inside storage groups.
func (a *DataAuditResult) SetRetries(v uint32) {
a.retries = v
}
// GetHit returns number of sampled objects under audit placed
// in an optimal way according to the containers placement policy
// when checking PoP.
func (a *DataAuditResult) GetHit() uint32 {
if a != nil {
return a.hit
}
return 0
}
// SetHit sets number of sampled objects under audit placed
// in an optimal way according to the containers placement policy
// when checking PoP.
func (a *DataAuditResult) SetHit(v uint32) {
a.hit = v
}
// GetMiss returns number of sampled objects under audit placed
// in suboptimal way according to the containers placement policy,
// but still at a satisfactory level when checking PoP.
func (a *DataAuditResult) GetMiss() uint32 {
if a != nil {
return a.miss
}
return 0
}
// SetMiss sets number of sampled objects under audit placed
// in suboptimal way according to the containers placement policy,
// but still at a satisfactory level when checking PoP.
func (a *DataAuditResult) SetMiss(v uint32) {
a.miss = v
}
// GetFail returns number of sampled objects under audit stored
// in a way not confirming placement policy or not found at all
// when checking PoP.
func (a *DataAuditResult) GetFail() uint32 {
if a != nil {
return a.fail
}
return 0
}
// SetFail sets number of sampled objects under audit stored
// in a way not confirming placement policy or not found at all
// when checking PoP.
func (a *DataAuditResult) SetFail(v uint32) {
a.fail = v
}
// GetPassNodes returns list of storage node public keys that
// passed at least one PDP.
func (a *DataAuditResult) GetPassNodes() [][]byte {
if a != nil {
return a.passNodes
}
return nil
}
// SetPassNodes sets list of storage node public keys that
// passed at least one PDP.
func (a *DataAuditResult) SetPassNodes(v [][]byte) {
a.passNodes = v
}
// GetFailNodes returns list of storage node public keys that
// failed at least one PDP.
func (a *DataAuditResult) GetFailNodes() [][]byte {
if a != nil {
return a.failNodes
}
return nil
}
// SetFailNodes sets list of storage node public keys that
// failed at least one PDP.
func (a *DataAuditResult) SetFailNodes(v [][]byte) {
a.failNodes = v
}
// GetComplete returns boolean completion statement of audit result.
func (a *DataAuditResult) GetComplete() bool {
if a != nil {
return a.complete
}
return false // bool default
}
// SetComplete sets boolean completion statement of audit result.
func (a *DataAuditResult) SetComplete(v bool) {
a.complete = v
}

View file

@ -3,7 +3,7 @@ package container_test
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
containertest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/test"
"github.com/stretchr/testify/require"
)
@ -16,7 +16,7 @@ func TestContainer_HomomorphicHashingDisabled(t *testing.T) {
})
t.Run("disabled", func(t *testing.T) {
attr := container.Attribute{}
attr := new(container.Container_Attribute)
attr.SetKey(container.SysAttributeHomomorphicHashing)
attr.SetValue("NOT_true")
@ -25,7 +25,7 @@ func TestContainer_HomomorphicHashingDisabled(t *testing.T) {
attr.SetValue("true")
cnr.SetAttributes([]container.Attribute{attr})
cnr.SetAttributes([]*container.Container_Attribute{attr})
require.False(t, cnr.HomomorphicHashingState())
})
}

File diff suppressed because it is too large Load diff

View file

@ -46,10 +46,10 @@ const disabledHomomorphicHashingValue = "true"
// is undefined.
//
// See also SetHomomorphicHashingState.
func (c Container) HomomorphicHashingState() bool {
for i := range c.attr {
if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS {
return c.attr[i].GetValue() != disabledHomomorphicHashingValue
func (c *Container) HomomorphicHashingState() bool {
for i := range c.Attributes {
if c.Attributes[i].GetKey() == SysAttributeHomomorphicHashing || c.Attributes[i].GetKey() == SysAttributeHomomorphicHashingNeoFS {
return c.Attributes[i].GetValue() != disabledHomomorphicHashingValue
}
}
@ -64,16 +64,17 @@ func (c Container) HomomorphicHashingState() bool {
//
// See also HomomorphicHashingState.
func (c *Container) SetHomomorphicHashingState(enable bool) {
for i := range c.attr {
if c.attr[i].GetKey() == SysAttributeHomomorphicHashing || c.attr[i].GetKey() == SysAttributeHomomorphicHashingNeoFS {
attributes := c.GetAttributes()
for _, attr := range attributes {
if attr.GetKey() == SysAttributeHomomorphicHashing || attr.GetKey() == SysAttributeHomomorphicHashingNeoFS {
if enable {
// approach without allocation/waste
// coping works since the attributes
// order is not important
c.attr[i] = c.attr[len(c.attr)-1]
c.attr = c.attr[:len(c.attr)-1]
attr = attributes[len(attributes)-1]
c.SetAttributes(attributes[:len(attributes)-1])
} else {
c.attr[i].SetValue(disabledHomomorphicHashingValue)
attr.SetValue(disabledHomomorphicHashingValue)
}
return
@ -81,10 +82,10 @@ func (c *Container) SetHomomorphicHashingState(enable bool) {
}
if !enable {
attr := Attribute{}
attr := new(Container_Attribute)
attr.SetKey(SysAttributeHomomorphicHashing)
attr.SetValue(disabledHomomorphicHashingValue)
c.attr = append(c.attr, attr)
c.SetAttributes(append(c.Attributes, attr))
}
}

Binary file not shown.

BIN
container/grpc/service_frostfs.pb.go generated Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
container/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,22 +0,0 @@
package container
import (
container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (a *Attribute) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(a)
}
func (a *Attribute) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(a, data, new(container.Container_Attribute))
}
func (c *Container) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(c)
}
func (c *Container) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(c, data, new(container.Container))
}

View file

@ -1,546 +0,0 @@
package container
import (
container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
attributeKeyField = 1
attributeValueField = 2
containerVersionField = 1
containerOwnerField = 2
containerNonceField = 3
containerBasicACLField = 4
containerAttributesField = 5
containerPlacementField = 6
putReqBodyContainerField = 1
putReqBodySignatureField = 2
putRespBodyIDField = 1
deleteReqBodyIDField = 1
deleteReqBodySignatureField = 2
getReqBodyIDField = 1
getRespBodyContainerField = 1
getRespBodySignatureField = 2
getRespBodyTokenField = 3
listReqBodyOwnerField = 1
listRespBodyIDsField = 1
setEACLReqBodyTableField = 1
setEACLReqBodySignatureField = 2
getEACLReqBodyIDField = 1
getEACLRespBodyTableField = 1
getEACLRespBodySignatureField = 2
getEACLRespBodyTokenField = 3
usedSpaceAnnounceEpochField = 1
usedSpaceAnnounceCIDField = 2
usedSpaceAnnounceUsedSpaceField = 3
usedSpaceReqBodyAnnouncementsField = 1
)
func (a *Attribute) StableMarshal(buf []byte) []byte {
if a == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, a.StableSize())
}
var offset int
offset += protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key)
protoutil.StringMarshal(attributeValueField, buf[offset:], a.val)
return buf
}
func (a *Attribute) StableSize() (size int) {
if a == nil {
return 0
}
size += protoutil.StringSize(attributeKeyField, a.key)
size += protoutil.StringSize(attributeValueField, a.val)
return size
}
func (a *Attribute) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(container.Container_Attribute))
}
func (c *Container) StableMarshal(buf []byte) []byte {
if c == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, c.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(containerVersionField, buf[offset:], c.version)
offset += protoutil.NestedStructureMarshal(containerOwnerField, buf[offset:], c.ownerID)
offset += protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce)
offset += protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL)
for i := range c.attr {
offset += protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i])
}
protoutil.NestedStructureMarshal(containerPlacementField, buf[offset:], c.policy)
return buf
}
func (c *Container) StableSize() (size int) {
if c == nil {
return 0
}
size += protoutil.NestedStructureSize(containerVersionField, c.version)
size += protoutil.NestedStructureSize(containerOwnerField, c.ownerID)
size += protoutil.BytesSize(containerNonceField, c.nonce)
size += protoutil.UInt32Size(containerBasicACLField, c.basicACL)
for i := range c.attr {
size += protoutil.NestedStructureSize(containerAttributesField, &c.attr[i])
}
size += protoutil.NestedStructureSize(containerPlacementField, c.policy)
return size
}
func (c *Container) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(container.Container))
}
func (r *PutRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(putReqBodyContainerField, buf[offset:], r.cnr)
protoutil.NestedStructureMarshal(putReqBodySignatureField, buf[offset:], r.sig)
return buf
}
func (r *PutRequestBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(putReqBodyContainerField, r.cnr)
size += protoutil.NestedStructureSize(putReqBodySignatureField, r.sig)
return size
}
func (r *PutRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.PutRequest_Body))
}
func (r *PutResponseBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid)
return buf
}
func (r *PutResponseBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(putRespBodyIDField, r.cid)
return size
}
func (r *PutResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.PutResponse_Body))
}
func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf[offset:], r.cid)
protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf[offset:], r.sig)
return buf
}
func (r *DeleteRequestBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(deleteReqBodyIDField, r.cid)
size += protoutil.NestedStructureSize(deleteReqBodySignatureField, r.sig)
return size
}
func (r *DeleteRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.DeleteRequest_Body))
}
func (r *DeleteResponseBody) StableMarshal(_ []byte) []byte {
return nil
}
func (r *DeleteResponseBody) StableSize() (size int) {
return 0
}
func (r *DeleteResponseBody) Unmarshal([]byte) error {
return nil
}
func (r *GetRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid)
return buf
}
func (r *GetRequestBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(getReqBodyIDField, r.cid)
return size
}
func (r *GetRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetRequest_Body))
}
func (r *GetResponseBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr)
offset += protoutil.NestedStructureMarshal(getRespBodySignatureField, buf[offset:], r.sig)
protoutil.NestedStructureMarshal(getRespBodyTokenField, buf[offset:], r.token)
return buf
}
func (r *GetResponseBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(getRespBodyContainerField, r.cnr)
size += protoutil.NestedStructureSize(getRespBodySignatureField, r.sig)
size += protoutil.NestedStructureSize(getRespBodyTokenField, r.token)
return size
}
func (r *GetResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.GetResponse_Body))
}
func (r *ListRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID)
return buf
}
func (r *ListRequestBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(listReqBodyOwnerField, r.ownerID)
return size
}
func (r *ListRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.ListRequest_Body))
}
func (r *ListResponseBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
for i := range r.cidList {
offset += protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], &r.cidList[i])
}
return buf
}
func (r *ListResponseBody) StableSize() (size int) {
if r == nil {
return 0
}
for i := range r.cidList {
size += protoutil.NestedStructureSize(listRespBodyIDsField, &r.cidList[i])
}
return size
}
func (r *ListResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.ListResponse_Body))
}
func (r *SetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf[offset:], r.eacl)
protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf[offset:], r.sig)
return buf
}
func (r *SetExtendedACLRequestBody) StableSize() (size int) {
if r == nil {
return 0
}
size += protoutil.NestedStructureSize(setEACLReqBodyTableField, r.eacl)
size += protoutil.NestedStructureSize(setEACLReqBodySignatureField, r.sig)
return size
}
func (r *SetExtendedACLRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.SetExtendedACLRequest_Body))
}
func (r *SetExtendedACLResponseBody) StableMarshal(_ []byte) []byte {
return nil
}
func (r *SetExtendedACLResponseBody) StableSize() (size int) {
return 0
}
func (r *SetExtendedACLResponseBody) Unmarshal([]byte) error {
return nil
}
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))
}
func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) []byte {
if a == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, a.StableSize())
}
var offset int
offset += protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch)
offset += protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid)
protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace)
return buf
}
func (a *UsedSpaceAnnouncement) StableSize() (size int) {
if a == nil {
return 0
}
size += protoutil.UInt64Size(usedSpaceAnnounceEpochField, a.epoch)
size += protoutil.NestedStructureSize(usedSpaceAnnounceCIDField, a.cid)
size += protoutil.UInt64Size(usedSpaceAnnounceUsedSpaceField, a.usedSpace)
return size
}
func (a *UsedSpaceAnnouncement) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(container.AnnounceUsedSpaceRequest_Body_Announcement))
}
func (r *AnnounceUsedSpaceRequestBody) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
for i := range r.announcements {
offset += protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], &r.announcements[i])
}
return buf
}
func (r *AnnounceUsedSpaceRequestBody) StableSize() (size int) {
if r == nil {
return 0
}
for i := range r.announcements {
size += protoutil.NestedStructureSize(usedSpaceReqBodyAnnouncementsField, &r.announcements[i])
}
return size
}
func (r *AnnounceUsedSpaceRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(container.AnnounceUsedSpaceRequest_Body))
}
func (r *AnnounceUsedSpaceResponseBody) StableMarshal(_ []byte) []byte {
return nil
}
func (r *AnnounceUsedSpaceResponseBody) StableSize() (size int) {
return 0
}
func (r *AnnounceUsedSpaceResponseBody) Unmarshal([]byte) error {
return nil
}

View file

@ -4,44 +4,44 @@ import (
"testing"
containertest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
"google.golang.org/protobuf/proto"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return containertest.GenerateAttribute(empty) },
func(empty bool) message.Message { return containertest.GenerateContainer(empty) },
func(empty bool) message.Message { return containertest.GeneratePutRequestBody(empty) },
func(empty bool) message.Message { return containertest.GeneratePutRequest(empty) },
func(empty bool) message.Message { return containertest.GeneratePutResponseBody(empty) },
func(empty bool) message.Message { return containertest.GeneratePutResponse(empty) },
func(empty bool) message.Message { return containertest.GenerateGetRequestBody(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.GenerateGetResponse(empty) },
func(empty bool) message.Message { return containertest.GenerateDeleteRequestBody(empty) },
func(empty bool) message.Message { return containertest.GenerateDeleteRequest(empty) },
func(empty bool) message.Message { return containertest.GenerateDeleteResponseBody(empty) },
func(empty bool) message.Message { return containertest.GenerateDeleteResponse(empty) },
func(empty bool) message.Message { return containertest.GenerateListRequestBody(empty) },
func(empty bool) message.Message { return containertest.GenerateListRequest(empty) },
func(empty bool) message.Message { return containertest.GenerateListResponseBody(empty) },
func(empty bool) message.Message { return containertest.GenerateListResponse(empty) },
func(empty bool) message.Message { return containertest.GenerateSetExtendedACLRequestBody(empty) },
func(empty bool) message.Message { return containertest.GenerateSetExtendedACLRequest(empty) },
func(empty bool) message.Message { return containertest.GenerateGetRequestBody(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.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) },
func(empty bool) message.Message { return containertest.GenerateUsedSpaceAnnouncement(empty) },
func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceRequestBody(empty) },
func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceRequest(empty) },
func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceResponseBody(empty) },
func(empty bool) message.Message { return containertest.GenerateAnnounceUsedSpaceResponse(empty) },
func(empty bool) proto.Message { return containertest.GenerateAttribute(empty) },
func(empty bool) proto.Message { return containertest.GenerateContainer(empty) },
func(empty bool) proto.Message { return containertest.GeneratePutRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GeneratePutRequest(empty) },
func(empty bool) proto.Message { return containertest.GeneratePutResponseBody(empty) },
func(empty bool) proto.Message { return containertest.GeneratePutResponse(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetRequest(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetResponseBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetResponse(empty) },
func(empty bool) proto.Message { return containertest.GenerateDeleteRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateDeleteRequest(empty) },
func(empty bool) proto.Message { return containertest.GenerateDeleteResponseBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateDeleteResponse(empty) },
func(empty bool) proto.Message { return containertest.GenerateListRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateListRequest(empty) },
func(empty bool) proto.Message { return containertest.GenerateListResponseBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateListResponse(empty) },
func(empty bool) proto.Message { return containertest.GenerateSetExtendedACLRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateSetExtendedACLRequest(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetRequest(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetResponseBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetResponse(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLRequest(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLResponseBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateGetExtendedACLResponse(empty) },
func(empty bool) proto.Message { return containertest.GenerateUsedSpaceAnnouncement(empty) },
func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceRequestBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceRequest(empty) },
func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceResponseBody(empty) },
func(empty bool) proto.Message { return containertest.GenerateAnnounceUsedSpaceResponse(empty) },
)
}

View file

@ -2,14 +2,14 @@ package containertest
import (
acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test"
)
func GenerateAttribute(empty bool) *container.Attribute {
m := new(container.Attribute)
func GenerateAttribute(empty bool) *container.Container_Attribute {
m := new(container.Container_Attribute)
if !empty {
m.SetKey("key")
@ -19,13 +19,13 @@ func GenerateAttribute(empty bool) *container.Attribute {
return m
}
func GenerateAttributes(empty bool) []container.Attribute {
var res []container.Attribute
func GenerateAttributes(empty bool) []*container.Container_Attribute {
var res []*container.Container_Attribute
if !empty {
res = append(res,
*GenerateAttribute(false),
*GenerateAttribute(false),
GenerateAttribute(false),
GenerateAttribute(false),
)
}
@ -36,9 +36,9 @@ func GenerateContainer(empty bool) *container.Container {
m := new(container.Container)
if !empty {
m.SetBasicACL(12)
m.SetBasicAcl(12)
m.SetNonce([]byte{1, 2, 3})
m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetOwnerId(refstest.GenerateOwnerID(false))
m.SetAttributes(GenerateAttributes(false))
m.SetPlacementPolicy(netmaptest.GeneratePlacementPolicy(false))
}
@ -48,14 +48,14 @@ func GenerateContainer(empty bool) *container.Container {
return m
}
func GeneratePutRequestBody(empty bool) *container.PutRequestBody {
m := new(container.PutRequestBody)
func GeneratePutRequestBody(empty bool) *container.PutRequest_Body {
m := new(container.PutRequest_Body)
if !empty {
m.SetContainer(GenerateContainer(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetSignature(refstest.GenerateSignatureRFC6979(empty))
return m
}
@ -68,16 +68,16 @@ func GeneratePutRequest(empty bool) *container.PutRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GeneratePutResponseBody(empty bool) *container.PutResponseBody {
m := new(container.PutResponseBody)
func GeneratePutResponseBody(empty bool) *container.PutResponse_Body {
m := new(container.PutResponse_Body)
if !empty {
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetContainerId(refstest.GenerateContainerID(false))
}
return m
@ -91,16 +91,16 @@ func GeneratePutResponse(empty bool) *container.PutResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateGetRequestBody(empty bool) *container.GetRequestBody {
m := new(container.GetRequestBody)
func GenerateGetRequestBody(empty bool) *container.GetRequest_Body {
m := new(container.GetRequest_Body)
if !empty {
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetContainerId(refstest.GenerateContainerID(false))
}
return m
@ -114,19 +114,19 @@ func GenerateGetRequest(empty bool) *container.GetRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateGetResponseBody(empty bool) *container.GetResponseBody {
m := new(container.GetResponseBody)
func GenerateGetResponseBody(empty bool) *container.GetResponse_Body {
m := new(container.GetResponse_Body)
if !empty {
m.SetContainer(GenerateContainer(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetSignature(refstest.GenerateSignatureRFC6979(empty))
m.SetSessionToken(sessiontest.GenerateSessionToken(empty))
return m
@ -140,19 +140,19 @@ func GenerateGetResponse(empty bool) *container.GetResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateDeleteRequestBody(empty bool) *container.DeleteRequestBody {
m := new(container.DeleteRequestBody)
func GenerateDeleteRequestBody(empty bool) *container.DeleteRequest_Body {
m := new(container.DeleteRequest_Body)
if !empty {
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetContainerId(refstest.GenerateContainerID(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetSignature(refstest.GenerateSignatureRFC6979(empty))
return m
}
@ -165,13 +165,13 @@ func GenerateDeleteRequest(empty bool) *container.DeleteRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateDeleteResponseBody(_ bool) *container.DeleteResponseBody {
m := new(container.DeleteResponseBody)
func GenerateDeleteResponseBody(_ bool) *container.DeleteResponse_Body {
m := new(container.DeleteResponse_Body)
return m
}
@ -184,16 +184,16 @@ func GenerateDeleteResponse(empty bool) *container.DeleteResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateListRequestBody(empty bool) *container.ListRequestBody {
m := new(container.ListRequestBody)
func GenerateListRequestBody(empty bool) *container.ListRequest_Body {
m := new(container.ListRequest_Body)
if !empty {
m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetOwnerId(refstest.GenerateOwnerID(false))
}
return m
@ -207,16 +207,16 @@ func GenerateListRequest(empty bool) *container.ListRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateListResponseBody(empty bool) *container.ListResponseBody {
m := new(container.ListResponseBody)
func GenerateListResponseBody(empty bool) *container.ListResponse_Body {
m := new(container.ListResponse_Body)
if !empty {
m.SetContainerIDs(refstest.GenerateContainerIDs(false))
m.SetContainerIds(refstest.GenerateContainerIDs(false))
}
return m
@ -230,19 +230,19 @@ func GenerateListResponse(empty bool) *container.ListResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateSetExtendedACLRequestBody(empty bool) *container.SetExtendedACLRequestBody {
m := new(container.SetExtendedACLRequestBody)
func GenerateSetExtendedACLRequestBody(empty bool) *container.SetExtendedACLRequest_Body {
m := new(container.SetExtendedACLRequest_Body)
if !empty {
m.SetEACL(acltest.GenerateTable(false))
m.SetEacl(acltest.GenerateTable(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetSignature(refstest.GenerateSignatureRFC6979(empty))
return m
}
@ -255,13 +255,13 @@ func GenerateSetExtendedACLRequest(empty bool) *container.SetExtendedACLRequest
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateSetExtendedACLResponseBody(_ bool) *container.SetExtendedACLResponseBody {
m := new(container.SetExtendedACLResponseBody)
func GenerateSetExtendedACLResponseBody(_ bool) *container.SetExtendedACLResponse_Body {
m := new(container.SetExtendedACLResponse_Body)
return m
}
@ -274,16 +274,16 @@ func GenerateSetExtendedACLResponse(empty bool) *container.SetExtendedACLRespons
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateGetExtendedACLRequestBody(empty bool) *container.GetExtendedACLRequestBody {
m := new(container.GetExtendedACLRequestBody)
func GenerateGetExtendedACLRequestBody(empty bool) *container.GetExtendedACLRequest_Body {
m := new(container.GetExtendedACLRequest_Body)
if !empty {
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetContainerId(refstest.GenerateContainerID(false))
}
return m
@ -297,19 +297,19 @@ func GenerateGetExtendedACLRequest(empty bool) *container.GetExtendedACLRequest
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateGetExtendedACLResponseBody(empty bool) *container.GetExtendedACLResponseBody {
m := new(container.GetExtendedACLResponseBody)
func GenerateGetExtendedACLResponseBody(empty bool) *container.GetExtendedACLResponse_Body {
m := new(container.GetExtendedACLResponse_Body)
if !empty {
m.SetEACL(acltest.GenerateTable(false))
m.SetEacl(acltest.GenerateTable(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
m.SetSignature(refstest.GenerateSignatureRFC6979(empty))
m.SetSessionToken(sessiontest.GenerateSessionToken(empty))
return m
@ -323,16 +323,16 @@ func GenerateGetExtendedACLResponse(empty bool) *container.GetExtendedACLRespons
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateUsedSpaceAnnouncement(empty bool) *container.UsedSpaceAnnouncement {
m := new(container.UsedSpaceAnnouncement)
func GenerateUsedSpaceAnnouncement(empty bool) *container.AnnounceUsedSpaceRequest_Body_Announcement {
m := new(container.AnnounceUsedSpaceRequest_Body_Announcement)
if !empty {
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetContainerId(refstest.GenerateContainerID(false))
m.SetEpoch(1)
m.SetUsedSpace(2)
}
@ -340,21 +340,21 @@ func GenerateUsedSpaceAnnouncement(empty bool) *container.UsedSpaceAnnouncement
return m
}
func GenerateUsedSpaceAnnouncements(empty bool) []container.UsedSpaceAnnouncement {
var res []container.UsedSpaceAnnouncement
func GenerateUsedSpaceAnnouncements(empty bool) []*container.AnnounceUsedSpaceRequest_Body_Announcement {
var res []*container.AnnounceUsedSpaceRequest_Body_Announcement
if !empty {
res = append(res,
*GenerateUsedSpaceAnnouncement(false),
*GenerateUsedSpaceAnnouncement(false),
GenerateUsedSpaceAnnouncement(false),
GenerateUsedSpaceAnnouncement(false),
)
}
return res
}
func GenerateAnnounceUsedSpaceRequestBody(empty bool) *container.AnnounceUsedSpaceRequestBody {
m := new(container.AnnounceUsedSpaceRequestBody)
func GenerateAnnounceUsedSpaceRequestBody(empty bool) *container.AnnounceUsedSpaceRequest_Body {
m := new(container.AnnounceUsedSpaceRequest_Body)
if !empty {
m.SetAnnouncements(GenerateUsedSpaceAnnouncements(false))
@ -371,13 +371,13 @@ func GenerateAnnounceUsedSpaceRequest(empty bool) *container.AnnounceUsedSpaceRe
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateAnnounceUsedSpaceResponseBody(_ bool) *container.AnnounceUsedSpaceResponseBody {
m := new(container.AnnounceUsedSpaceResponseBody)
func GenerateAnnounceUsedSpaceResponseBody(_ bool) *container.AnnounceUsedSpaceResponse_Body {
m := new(container.AnnounceUsedSpaceResponse_Body)
return m
}
@ -390,7 +390,7 @@ func GenerateAnnounceUsedSpaceResponse(empty bool) *container.AnnounceUsedSpaceR
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}

View file

@ -1,717 +0,0 @@
package container
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/refs"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
)
type Attribute struct {
key, val string
}
type Container struct {
version *refs.Version
ownerID *refs.OwnerID
nonce []byte
basicACL uint32
attr []Attribute
policy *netmap.PlacementPolicy
}
type PutRequestBody struct {
cnr *Container
sig *refs.Signature
}
type PutRequest struct {
body *PutRequestBody
session.RequestHeaders
}
type PutResponseBody struct {
cid *refs.ContainerID
}
type PutResponse struct {
body *PutResponseBody
session.ResponseHeaders
}
type GetRequestBody struct {
cid *refs.ContainerID
}
type GetRequest struct {
body *GetRequestBody
session.RequestHeaders
}
type GetResponseBody struct {
cnr *Container
token *session.Token
sig *refs.Signature
}
type GetResponse struct {
body *GetResponseBody
session.ResponseHeaders
}
type DeleteRequestBody struct {
cid *refs.ContainerID
sig *refs.Signature
}
type DeleteRequest struct {
body *DeleteRequestBody
session.RequestHeaders
}
type DeleteResponseBody struct{}
type DeleteResponse struct {
body *DeleteResponseBody
session.ResponseHeaders
}
type ListRequestBody struct {
ownerID *refs.OwnerID
}
type ListRequest struct {
body *ListRequestBody
session.RequestHeaders
}
type ListResponseBody struct {
cidList []refs.ContainerID
}
type ListResponse struct {
body *ListResponseBody
session.ResponseHeaders
}
type SetExtendedACLRequestBody struct {
eacl *acl.Table
sig *refs.Signature
}
type SetExtendedACLRequest struct {
body *SetExtendedACLRequestBody
session.RequestHeaders
}
type SetExtendedACLResponseBody struct{}
type SetExtendedACLResponse struct {
body *SetExtendedACLResponseBody
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
}
type UsedSpaceAnnouncement struct {
epoch uint64
cid *refs.ContainerID
usedSpace uint64
}
type AnnounceUsedSpaceRequestBody struct {
announcements []UsedSpaceAnnouncement
}
type AnnounceUsedSpaceRequest struct {
body *AnnounceUsedSpaceRequestBody
session.RequestHeaders
}
type AnnounceUsedSpaceResponseBody struct{}
type AnnounceUsedSpaceResponse struct {
body *AnnounceUsedSpaceResponseBody
session.ResponseHeaders
}
func (a *Attribute) GetKey() string {
if a != nil {
return a.key
}
return ""
}
func (a *Attribute) SetKey(v string) {
a.key = v
}
func (a *Attribute) GetValue() string {
if a != nil {
return a.val
}
return ""
}
func (a *Attribute) SetValue(v string) {
a.val = v
}
func (c *Container) GetVersion() *refs.Version {
if c != nil {
return c.version
}
return nil
}
func (c *Container) SetVersion(v *refs.Version) {
c.version = v
}
func (c *Container) GetOwnerID() *refs.OwnerID {
if c != nil {
return c.ownerID
}
return nil
}
func (c *Container) SetOwnerID(v *refs.OwnerID) {
c.ownerID = v
}
func (c *Container) GetNonce() []byte {
if c != nil {
return c.nonce
}
return nil
}
func (c *Container) SetNonce(v []byte) {
c.nonce = v
}
func (c *Container) GetBasicACL() uint32 {
if c != nil {
return c.basicACL
}
return 0
}
func (c *Container) SetBasicACL(v uint32) {
c.basicACL = v
}
func (c *Container) GetAttributes() []Attribute {
if c != nil {
return c.attr
}
return nil
}
func (c *Container) SetAttributes(v []Attribute) {
c.attr = v
}
func (c *Container) GetPlacementPolicy() *netmap.PlacementPolicy {
if c != nil {
return c.policy
}
return nil
}
func (c *Container) SetPlacementPolicy(v *netmap.PlacementPolicy) {
c.policy = v
}
func (r *PutRequestBody) GetContainer() *Container {
if r != nil {
return r.cnr
}
return nil
}
func (r *PutRequestBody) SetContainer(v *Container) {
r.cnr = v
}
func (r *PutRequestBody) GetSignature() *refs.Signature {
if r != nil {
return r.sig
}
return nil
}
func (r *PutRequestBody) SetSignature(v *refs.Signature) {
// TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type)
v.SetScheme(0)
r.sig = v
}
func (r *PutRequest) GetBody() *PutRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *PutRequest) SetBody(v *PutRequestBody) {
r.body = v
}
func (r *PutResponseBody) GetContainerID() *refs.ContainerID {
if r != nil {
return r.cid
}
return nil
}
func (r *PutResponseBody) SetContainerID(v *refs.ContainerID) {
r.cid = v
}
func (r *PutResponse) GetBody() *PutResponseBody {
if r != nil {
return r.body
}
return nil
}
func (r *PutResponse) SetBody(v *PutResponseBody) {
r.body = v
}
func (r *GetRequestBody) GetContainerID() *refs.ContainerID {
if r != nil {
return r.cid
}
return nil
}
func (r *GetRequestBody) SetContainerID(v *refs.ContainerID) {
r.cid = v
}
func (r *GetRequest) GetBody() *GetRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *GetRequest) SetBody(v *GetRequestBody) {
r.body = v
}
func (r *GetResponseBody) GetContainer() *Container {
if r != nil {
return r.cnr
}
return nil
}
func (r *GetResponseBody) SetContainer(v *Container) {
r.cnr = v
}
// GetSessionToken returns token of the session within which requested
// container was created.
func (r *GetResponseBody) GetSessionToken() *session.Token {
if r != nil {
return r.token
}
return nil
}
// SetSessionToken sets token of the session within which requested
// container was created.
func (r *GetResponseBody) SetSessionToken(v *session.Token) {
r.token = v
}
// GetSignature returns signature of the requested container.
func (r *GetResponseBody) GetSignature() *refs.Signature {
if r != nil {
return r.sig
}
return nil
}
// SetSignature sets signature of the requested container.
func (r *GetResponseBody) SetSignature(v *refs.Signature) {
// TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type)
v.SetScheme(0)
r.sig = v
}
func (r *GetResponse) GetBody() *GetResponseBody {
if r != nil {
return r.body
}
return nil
}
func (r *GetResponse) SetBody(v *GetResponseBody) {
r.body = v
}
func (r *DeleteRequestBody) GetContainerID() *refs.ContainerID {
if r != nil {
return r.cid
}
return nil
}
func (r *DeleteRequestBody) SetContainerID(v *refs.ContainerID) {
r.cid = v
}
func (r *DeleteRequestBody) GetSignature() *refs.Signature {
if r != nil {
return r.sig
}
return nil
}
func (r *DeleteRequestBody) SetSignature(v *refs.Signature) {
// TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type)
v.SetScheme(0)
r.sig = v
}
func (r *DeleteRequest) GetBody() *DeleteRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *DeleteRequest) SetBody(v *DeleteRequestBody) {
r.body = v
}
func (r *DeleteResponse) GetBody() *DeleteResponseBody {
if r != nil {
return r.body
}
return nil
}
func (r *DeleteResponse) SetBody(v *DeleteResponseBody) {
r.body = v
}
func (r *ListRequestBody) GetOwnerID() *refs.OwnerID {
if r != nil {
return r.ownerID
}
return nil
}
func (r *ListRequestBody) SetOwnerID(v *refs.OwnerID) {
r.ownerID = v
}
func (r *ListRequest) GetBody() *ListRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *ListRequest) SetBody(v *ListRequestBody) {
r.body = v
}
func (r *ListResponseBody) GetContainerIDs() []refs.ContainerID {
if r != nil {
return r.cidList
}
return nil
}
func (r *ListResponseBody) SetContainerIDs(v []refs.ContainerID) {
r.cidList = v
}
func (r *ListResponse) GetBody() *ListResponseBody {
if r != nil {
return r.body
}
return nil
}
func (r *ListResponse) SetBody(v *ListResponseBody) {
r.body = v
}
func (r *SetExtendedACLRequestBody) GetEACL() *acl.Table {
if r != nil {
return r.eacl
}
return nil
}
func (r *SetExtendedACLRequestBody) SetEACL(v *acl.Table) {
r.eacl = v
}
func (r *SetExtendedACLRequestBody) GetSignature() *refs.Signature {
if r != nil {
return r.sig
}
return nil
}
func (r *SetExtendedACLRequestBody) SetSignature(v *refs.Signature) {
// TODO: (neofs-api-go#381) avoid this hack (e.g. create refs.SignatureRFC6979 type)
v.SetScheme(0)
r.sig = v
}
func (r *SetExtendedACLRequest) GetBody() *SetExtendedACLRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *SetExtendedACLRequest) SetBody(v *SetExtendedACLRequestBody) {
r.body = v
}
func (r *SetExtendedACLResponse) GetBody() *SetExtendedACLResponseBody {
if r != nil {
return r.body
}
return nil
}
func (r *SetExtendedACLResponse) SetBody(v *SetExtendedACLResponseBody) {
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
}
func (a *UsedSpaceAnnouncement) GetEpoch() uint64 {
if a != nil {
return a.epoch
}
return 0
}
func (a *UsedSpaceAnnouncement) SetEpoch(v uint64) {
a.epoch = v
}
func (a *UsedSpaceAnnouncement) GetUsedSpace() uint64 {
if a != nil {
return a.usedSpace
}
return 0
}
func (a *UsedSpaceAnnouncement) SetUsedSpace(v uint64) {
a.usedSpace = v
}
func (a *UsedSpaceAnnouncement) GetContainerID() *refs.ContainerID {
if a != nil {
return a.cid
}
return nil
}
func (a *UsedSpaceAnnouncement) SetContainerID(v *refs.ContainerID) {
a.cid = v
}
func (r *AnnounceUsedSpaceRequestBody) GetAnnouncements() []UsedSpaceAnnouncement {
if r != nil {
return r.announcements
}
return nil
}
func (r *AnnounceUsedSpaceRequestBody) SetAnnouncements(v []UsedSpaceAnnouncement) {
r.announcements = v
}
func (r *AnnounceUsedSpaceRequest) GetBody() *AnnounceUsedSpaceRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *AnnounceUsedSpaceRequest) SetBody(v *AnnounceUsedSpaceRequestBody) {
r.body = v
}
func (r *AnnounceUsedSpaceResponse) GetBody() *AnnounceUsedSpaceResponseBody {
if r != nil {
return r.body
}
return nil
}
func (r *AnnounceUsedSpaceResponse) SetBody(v *AnnounceUsedSpaceResponseBody) {
r.body = v
}

28
lock/grpc/lock_test.go Normal file
View file

@ -0,0 +1,28 @@
package lock_test
import (
"testing"
lock "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/grpc"
locktest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/test"
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
func TestLockRW(t *testing.T) {
l := new(lock.Lock)
obj := new(object.Object)
require.Error(t, lock.ReadLock(l, obj))
l = locktest.GenerateLock(false)
lock.WriteLock(obj, l)
l2 := new(lock.Lock)
require.NoError(t, lock.ReadLock(l2, obj))
require.True(t, proto.Equal(l, l2))
}

View file

@ -1,8 +1,62 @@
package lock
import refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
import (
"errors"
"fmt"
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"google.golang.org/protobuf/proto"
)
// SetMembers sets `members` field.
func (x *Lock) SetMembers(ids []*refs.ObjectID) {
x.Members = ids
}
func (x *Lock) Unmarshal(data []byte) error {
return proto.Unmarshal(data, x)
}
// WriteLock writes Lock to the Object as a payload content.
// The object must not be nil.
func WriteLock(obj *object.Object, lock *Lock) {
hdr := obj.GetHeader()
if hdr == nil {
hdr = new(object.Header)
obj.SetHeader(hdr)
}
hdr.SetObjectType(object.ObjectType_LOCK)
payload := lock.StableMarshal(nil)
obj.SetPayload(payload)
}
// ReadLock reads Lock from the Object payload content.
func ReadLock(lock *Lock, obj *object.Object) error {
payload := obj.GetPayload()
if len(payload) == 0 {
return errors.New("empty payload")
}
err := lock.Unmarshal(payload)
if err != nil {
return fmt.Errorf("decode lock content from payload: %w", err)
}
return nil
}
func (l *Lock) NumberOfMembers() int {
return len(l.GetMembers())
}
// IterateMembers passes members of the lock list to f.
func (x *Lock) IterateMembers(f func(*refs.ObjectID)) {
if x != nil {
for i := range x.Members {
f(x.Members[i])
}
}
}

BIN
lock/grpc/types.pb.go generated

Binary file not shown.

BIN
lock/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

20
lock/test/generate.go Normal file
View file

@ -0,0 +1,20 @@
package locktest
import (
lock "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/grpc"
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
)
func GenerateLock(empty bool) *lock.Lock {
m := new(lock.Lock)
if !empty {
m.SetMembers([]*refs.ObjectID{
refstest.GenerateObjectID(false),
refstest.GenerateObjectID(false),
})
}
return m
}

View file

@ -1,919 +0,0 @@
package netmap
import (
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (f *Filter) ToGRPCMessage() grpc.Message {
var m *netmap.Filter
if f != nil {
m = new(netmap.Filter)
m.SetKey(f.key)
m.SetValue(f.value)
m.SetName(f.name)
m.SetOp(OperationToGRPCMessage(f.op))
m.SetFilters(FiltersToGRPC(f.filters))
}
return m
}
func (f *Filter) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.Filter)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
f.filters, err = FiltersFromGRPC(v.GetFilters())
if err != nil {
return err
}
f.key = v.GetKey()
f.value = v.GetValue()
f.name = v.GetName()
f.op = OperationFromGRPCMessage(v.GetOp())
return nil
}
func FiltersToGRPC(fs []Filter) (res []*netmap.Filter) {
if fs != nil {
res = make([]*netmap.Filter, 0, len(fs))
for i := range fs {
res = append(res, fs[i].ToGRPCMessage().(*netmap.Filter))
}
}
return
}
func FiltersFromGRPC(fs []*netmap.Filter) (res []Filter, err error) {
if fs != nil {
res = make([]Filter, len(fs))
for i := range fs {
if fs[i] != nil {
err = res[i].FromGRPCMessage(fs[i])
if err != nil {
return
}
}
}
}
return
}
func (s *Selector) ToGRPCMessage() grpc.Message {
var m *netmap.Selector
if s != nil {
m = new(netmap.Selector)
m.SetName(s.name)
m.SetAttribute(s.attribute)
m.SetFilter(s.filter)
m.SetCount(s.count)
m.SetClause(ClauseToGRPCMessage(s.clause))
}
return m
}
func (s *Selector) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.Selector)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
s.name = v.GetName()
s.attribute = v.GetAttribute()
s.filter = v.GetFilter()
s.count = v.GetCount()
s.clause = ClauseFromGRPCMessage(v.GetClause())
return nil
}
func SelectorsToGRPC(ss []Selector) (res []*netmap.Selector) {
if ss != nil {
res = make([]*netmap.Selector, 0, len(ss))
for i := range ss {
res = append(res, ss[i].ToGRPCMessage().(*netmap.Selector))
}
}
return
}
func SelectorsFromGRPC(ss []*netmap.Selector) (res []Selector, err error) {
if ss != nil {
res = make([]Selector, len(ss))
for i := range ss {
if ss[i] != nil {
err = res[i].FromGRPCMessage(ss[i])
if err != nil {
return
}
}
}
}
return
}
func (r *Replica) ToGRPCMessage() grpc.Message {
var m *netmap.Replica
if r != nil {
m = new(netmap.Replica)
m.SetSelector(r.selector)
m.SetCount(r.count)
}
return m
}
func (r *Replica) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.Replica)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
r.selector = v.GetSelector()
r.count = v.GetCount()
return nil
}
func ReplicasToGRPC(rs []Replica) (res []*netmap.Replica) {
if rs != nil {
res = make([]*netmap.Replica, 0, len(rs))
for i := range rs {
res = append(res, rs[i].ToGRPCMessage().(*netmap.Replica))
}
}
return
}
func ReplicasFromGRPC(rs []*netmap.Replica) (res []Replica, err error) {
if rs != nil {
res = make([]Replica, len(rs))
for i := range rs {
if rs[i] != nil {
err = res[i].FromGRPCMessage(rs[i])
if err != nil {
return
}
}
}
}
return
}
func (p *PlacementPolicy) ToGRPCMessage() grpc.Message {
var m *netmap.PlacementPolicy
if p != nil {
m = new(netmap.PlacementPolicy)
m.SetFilters(FiltersToGRPC(p.filters))
m.SetSelectors(SelectorsToGRPC(p.selectors))
m.SetReplicas(ReplicasToGRPC(p.replicas))
m.SetContainerBackupFactor(p.backupFactor)
}
return m
}
func (p *PlacementPolicy) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.PlacementPolicy)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
p.filters, err = FiltersFromGRPC(v.GetFilters())
if err != nil {
return err
}
p.selectors, err = SelectorsFromGRPC(v.GetSelectors())
if err != nil {
return err
}
p.replicas, err = ReplicasFromGRPC(v.GetReplicas())
if err != nil {
return err
}
p.backupFactor = v.GetContainerBackupFactor()
return nil
}
func ClauseToGRPCMessage(n Clause) netmap.Clause {
return netmap.Clause(n)
}
func ClauseFromGRPCMessage(n netmap.Clause) Clause {
return Clause(n)
}
func OperationToGRPCMessage(n Operation) netmap.Operation {
return netmap.Operation(n)
}
func OperationFromGRPCMessage(n netmap.Operation) Operation {
return Operation(n)
}
func NodeStateToGRPCMessage(n NodeState) netmap.NodeInfo_State {
return netmap.NodeInfo_State(n)
}
func NodeStateFromRPCMessage(n netmap.NodeInfo_State) NodeState {
return NodeState(n)
}
func (a *Attribute) ToGRPCMessage() grpc.Message {
var m *netmap.NodeInfo_Attribute
if a != nil {
m = new(netmap.NodeInfo_Attribute)
m.SetKey(a.key)
m.SetValue(a.value)
m.SetParents(a.parents)
}
return m
}
func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NodeInfo_Attribute)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
a.key = v.GetKey()
a.value = v.GetValue()
a.parents = v.GetParents()
return nil
}
func AttributesToGRPC(as []Attribute) (res []*netmap.NodeInfo_Attribute) {
if as != nil {
res = make([]*netmap.NodeInfo_Attribute, 0, len(as))
for i := range as {
res = append(res, as[i].ToGRPCMessage().(*netmap.NodeInfo_Attribute))
}
}
return
}
func AttributesFromGRPC(as []*netmap.NodeInfo_Attribute) (res []Attribute, err error) {
if as != nil {
res = make([]Attribute, len(as))
for i := range as {
if as[i] != nil {
err = res[i].FromGRPCMessage(as[i])
if err != nil {
return
}
}
}
}
return
}
func (ni *NodeInfo) ToGRPCMessage() grpc.Message {
var m *netmap.NodeInfo
if ni != nil {
m = new(netmap.NodeInfo)
m.SetPublicKey(ni.publicKey)
m.SetAddresses(ni.addresses)
m.SetState(NodeStateToGRPCMessage(ni.state))
m.SetAttributes(AttributesToGRPC(ni.attributes))
}
return m
}
func (ni *NodeInfo) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NodeInfo)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
ni.attributes, err = AttributesFromGRPC(v.GetAttributes())
if err != nil {
return err
}
ni.publicKey = v.GetPublicKey()
ni.addresses = v.GetAddresses()
ni.state = NodeStateFromRPCMessage(v.GetState())
return nil
}
func (l *LocalNodeInfoRequestBody) ToGRPCMessage() grpc.Message {
var m *netmap.LocalNodeInfoRequest_Body
if l != nil {
m = new(netmap.LocalNodeInfoRequest_Body)
}
return m
}
func (l *LocalNodeInfoRequestBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.LocalNodeInfoRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
return nil
}
func (l *LocalNodeInfoRequest) ToGRPCMessage() grpc.Message {
var m *netmap.LocalNodeInfoRequest
if l != nil {
m = new(netmap.LocalNodeInfoRequest)
m.SetBody(l.body.ToGRPCMessage().(*netmap.LocalNodeInfoRequest_Body))
l.RequestHeaders.ToMessage(m)
}
return m
}
func (l *LocalNodeInfoRequest) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.LocalNodeInfoRequest)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
l.body = nil
} else {
if l.body == nil {
l.body = new(LocalNodeInfoRequestBody)
}
err = l.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return l.RequestHeaders.FromMessage(v)
}
func (l *LocalNodeInfoResponseBody) ToGRPCMessage() grpc.Message {
var m *netmap.LocalNodeInfoResponse_Body
if l != nil {
m = new(netmap.LocalNodeInfoResponse_Body)
m.SetVersion(l.version.ToGRPCMessage().(*refsGRPC.Version))
m.SetNodeInfo(l.nodeInfo.ToGRPCMessage().(*netmap.NodeInfo))
}
return m
}
func (l *LocalNodeInfoResponseBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.LocalNodeInfoResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
version := v.GetVersion()
if version == nil {
l.version = nil
} else {
if l.version == nil {
l.version = new(refs.Version)
}
err = l.version.FromGRPCMessage(version)
if err != nil {
return err
}
}
nodeInfo := v.GetNodeInfo()
if nodeInfo == nil {
l.nodeInfo = nil
} else {
if l.nodeInfo == nil {
l.nodeInfo = new(NodeInfo)
}
err = l.nodeInfo.FromGRPCMessage(nodeInfo)
}
return err
}
func (l *LocalNodeInfoResponse) ToGRPCMessage() grpc.Message {
var m *netmap.LocalNodeInfoResponse
if l != nil {
m = new(netmap.LocalNodeInfoResponse)
m.SetBody(l.body.ToGRPCMessage().(*netmap.LocalNodeInfoResponse_Body))
l.ResponseHeaders.ToMessage(m)
}
return m
}
func (l *LocalNodeInfoResponse) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.LocalNodeInfoResponse)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
l.body = nil
} else {
if l.body == nil {
l.body = new(LocalNodeInfoResponseBody)
}
err = l.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return l.ResponseHeaders.FromMessage(v)
}
func (x *NetworkParameter) ToGRPCMessage() grpc.Message {
var m *netmap.NetworkConfig_Parameter
if x != nil {
m = new(netmap.NetworkConfig_Parameter)
m.SetKey(x.k)
m.SetValue(x.v)
}
return m
}
func (x *NetworkParameter) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetworkConfig_Parameter)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
x.k = v.GetKey()
x.v = v.GetValue()
return nil
}
func (x *NetworkConfig) ToGRPCMessage() grpc.Message {
var m *netmap.NetworkConfig
if x != nil {
m = new(netmap.NetworkConfig)
var ps []*netmap.NetworkConfig_Parameter
if ln := len(x.ps); ln > 0 {
ps = make([]*netmap.NetworkConfig_Parameter, 0, ln)
for i := 0; i < ln; i++ {
ps = append(ps, x.ps[i].ToGRPCMessage().(*netmap.NetworkConfig_Parameter))
}
}
m.SetParameters(ps)
}
return m
}
func (x *NetworkConfig) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetworkConfig)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var (
ps []NetworkParameter
psV2 = v.GetParameters()
)
if psV2 != nil {
ln := len(psV2)
ps = make([]NetworkParameter, ln)
for i := 0; i < ln; i++ {
if psV2[i] != nil {
if err := ps[i].FromGRPCMessage(psV2[i]); err != nil {
return err
}
}
}
}
x.ps = ps
return nil
}
func (i *NetworkInfo) ToGRPCMessage() grpc.Message {
var m *netmap.NetworkInfo
if i != nil {
m = new(netmap.NetworkInfo)
m.SetMagicNumber(i.magicNum)
m.SetCurrentEpoch(i.curEpoch)
m.SetMsPerBlock(i.msPerBlock)
m.SetNetworkConfig(i.netCfg.ToGRPCMessage().(*netmap.NetworkConfig))
}
return m
}
func (i *NetworkInfo) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetworkInfo)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
netCfg := v.GetNetworkConfig()
if netCfg == nil {
i.netCfg = nil
} else {
if i.netCfg == nil {
i.netCfg = new(NetworkConfig)
}
err = i.netCfg.FromGRPCMessage(netCfg)
if err != nil {
return err
}
}
i.magicNum = v.GetMagicNumber()
i.curEpoch = v.GetCurrentEpoch()
i.msPerBlock = v.GetMsPerBlock()
return nil
}
func (l *NetworkInfoRequestBody) ToGRPCMessage() grpc.Message {
var m *netmap.NetworkInfoRequest_Body
if l != nil {
m = new(netmap.NetworkInfoRequest_Body)
}
return m
}
func (l *NetworkInfoRequestBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetworkInfoRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
return nil
}
func (l *NetworkInfoRequest) ToGRPCMessage() grpc.Message {
var m *netmap.NetworkInfoRequest
if l != nil {
m = new(netmap.NetworkInfoRequest)
m.SetBody(l.body.ToGRPCMessage().(*netmap.NetworkInfoRequest_Body))
l.RequestHeaders.ToMessage(m)
}
return m
}
func (l *NetworkInfoRequest) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetworkInfoRequest)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
l.body = nil
} else {
if l.body == nil {
l.body = new(NetworkInfoRequestBody)
}
err = l.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return l.RequestHeaders.FromMessage(v)
}
func (i *NetworkInfoResponseBody) ToGRPCMessage() grpc.Message {
var m *netmap.NetworkInfoResponse_Body
if i != nil {
m = new(netmap.NetworkInfoResponse_Body)
m.SetNetworkInfo(i.netInfo.ToGRPCMessage().(*netmap.NetworkInfo))
}
return m
}
func (i *NetworkInfoResponseBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetworkInfoResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
netInfo := v.GetNetworkInfo()
if netInfo == nil {
i.netInfo = nil
} else {
if i.netInfo == nil {
i.netInfo = new(NetworkInfo)
}
err = i.netInfo.FromGRPCMessage(netInfo)
}
return err
}
func (l *NetworkInfoResponse) ToGRPCMessage() grpc.Message {
var m *netmap.NetworkInfoResponse
if l != nil {
m = new(netmap.NetworkInfoResponse)
m.SetBody(l.body.ToGRPCMessage().(*netmap.NetworkInfoResponse_Body))
l.ResponseHeaders.ToMessage(m)
}
return m
}
func (l *NetworkInfoResponse) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetworkInfoResponse)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
l.body = nil
} else {
if l.body == nil {
l.body = new(NetworkInfoResponseBody)
}
err = l.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return l.ResponseHeaders.FromMessage(v)
}
func (x *NetMap) ToGRPCMessage() grpc.Message {
var m *netmap.Netmap
if x != nil {
m = new(netmap.Netmap)
m.SetEpoch(x.epoch)
if x.nodes != nil {
nodes := make([]*netmap.NodeInfo, len(x.nodes))
for i := range x.nodes {
nodes[i] = x.nodes[i].ToGRPCMessage().(*netmap.NodeInfo)
}
m.SetNodes(nodes)
}
}
return m
}
func (x *NetMap) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.Netmap)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
nodes := v.GetNodes()
if nodes == nil {
x.nodes = nil
} else {
x.nodes = make([]NodeInfo, len(nodes))
for i := range nodes {
err = x.nodes[i].FromGRPCMessage(nodes[i])
if err != nil {
return err
}
}
}
x.epoch = v.GetEpoch()
return nil
}
func (x *SnapshotRequestBody) ToGRPCMessage() grpc.Message {
var m *netmap.NetmapSnapshotRequest_Body
if x != nil {
m = new(netmap.NetmapSnapshotRequest_Body)
}
return m
}
func (x *SnapshotRequestBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetmapSnapshotRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
return nil
}
func (x *SnapshotRequest) ToGRPCMessage() grpc.Message {
var m *netmap.NetmapSnapshotRequest
if x != nil {
m = new(netmap.NetmapSnapshotRequest)
m.SetBody(x.body.ToGRPCMessage().(*netmap.NetmapSnapshotRequest_Body))
x.RequestHeaders.ToMessage(m)
}
return m
}
func (x *SnapshotRequest) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetmapSnapshotRequest)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
x.body = nil
} else {
if x.body == nil {
x.body = new(SnapshotRequestBody)
}
err = x.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return x.RequestHeaders.FromMessage(v)
}
func (x *SnapshotResponseBody) ToGRPCMessage() grpc.Message {
var m *netmap.NetmapSnapshotResponse_Body
if x != nil {
m = new(netmap.NetmapSnapshotResponse_Body)
m.SetNetmap(x.netMap.ToGRPCMessage().(*netmap.Netmap))
}
return m
}
func (x *SnapshotResponseBody) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetmapSnapshotResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
netMap := v.GetNetmap()
if netMap == nil {
x.netMap = nil
} else {
if x.netMap == nil {
x.netMap = new(NetMap)
}
err = x.netMap.FromGRPCMessage(netMap)
}
return err
}
func (x *SnapshotResponse) ToGRPCMessage() grpc.Message {
var m *netmap.NetmapSnapshotResponse
if x != nil {
m = new(netmap.NetmapSnapshotResponse)
m.SetBody(x.body.ToGRPCMessage().(*netmap.NetmapSnapshotResponse_Body))
x.ResponseHeaders.ToMessage(m)
}
return m
}
func (x *SnapshotResponse) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*netmap.NetmapSnapshotResponse)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
body := v.GetBody()
if body == nil {
x.body = nil
} else {
if x.body == nil {
x.body = new(SnapshotResponseBody)
}
err = x.body.FromGRPCMessage(body)
if err != nil {
return err
}
}
return x.ResponseHeaders.FromMessage(v)
}

Binary file not shown.

BIN
netmap/grpc/service_frostfs.pb.go generated Normal file

Binary file not shown.

Binary file not shown.

View file

@ -1,5 +1,10 @@
package netmap
// SetUnique of placement policy.
func (m *PlacementPolicy) SetUnique(unique bool) {
m.Unique = unique
}
// SetReplicas of placement policy.
func (m *PlacementPolicy) SetReplicas(v []*Replica) {
m.Replicas = v
@ -122,6 +127,29 @@ func (m *NodeInfo) SetState(v NodeInfo_State) {
m.State = v
}
// NumberOfAddresses returns number of network addresses of the node.
func (ni *NodeInfo) NumberOfAddresses() int {
if ni != nil {
return len(ni.Addresses)
}
return 0
}
// IterateAddresses iterates over network addresses of the node.
// Breaks iteration on f's true return.
//
// Handler should not be nil.
func (ni *NodeInfo) IterateAddresses(f func(string) bool) {
if ni != nil {
for i := range ni.Addresses {
if f(ni.Addresses[i]) {
break
}
}
}
}
// SetCurrentEpoch sets number of the current epoch.
func (x *NetworkInfo) SetCurrentEpoch(v uint64) {
x.CurrentEpoch = v
@ -196,6 +224,29 @@ func (x *NetworkConfig) SetParameters(v []*NetworkConfig_Parameter) {
x.Parameters = v
}
// NumberOfParameters returns number of network parameters.
func (x *NetworkConfig) NumberOfParameters() int {
if x != nil {
return len(x.GetParameters())
}
return 0
}
// IterateParameters iterates over network parameters.
// Breaks iteration on f's true return.
//
// Handler must not be nil.
func (x *NetworkConfig) IterateParameters(f func(*NetworkConfig_Parameter) bool) {
if x != nil {
for i := range x.Parameters {
if f(x.Parameters[i]) {
break
}
}
}
}
// SetEpoch sets revision number of the Netmap.
func (x *Netmap) SetEpoch(v uint64) {
x.Epoch = v

BIN
netmap/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,62 +0,0 @@
package netmap
import (
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (p *PlacementPolicy) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(p)
}
func (p *PlacementPolicy) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(p, data, new(netmap.PlacementPolicy))
}
func (f *Filter) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(f)
}
func (f *Filter) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(f, data, new(netmap.Filter))
}
func (s *Selector) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(s)
}
func (s *Selector) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(s, data, new(netmap.Selector))
}
func (r *Replica) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(r)
}
func (r *Replica) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(r, data, new(netmap.Replica))
}
func (a *Attribute) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(a)
}
func (a *Attribute) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(a, data, new(netmap.NodeInfo_Attribute))
}
func (ni *NodeInfo) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(ni)
}
func (ni *NodeInfo) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(ni, data, new(netmap.NodeInfo))
}
func (i *NetworkInfo) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(i)
}
func (i *NetworkInfo) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(i, data, new(netmap.NetworkInfo))
}

View file

@ -1,554 +0,0 @@
package netmap
import (
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
protoutil "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
nameFilterField = 1
keyFilterField = 2
opFilterField = 3
valueFilterField = 4
filtersFilterField = 5
nameSelectorField = 1
countSelectorField = 2
clauseSelectorField = 3
attributeSelectorField = 4
filterSelectorField = 5
countReplicaField = 1
selectorReplicaField = 2
replicasPolicyField = 1
backupPolicyField = 2
selectorsPolicyField = 3
filtersPolicyField = 4
uniquePolicyField = 5
keyAttributeField = 1
valueAttributeField = 2
parentsAttributeField = 3
keyNodeInfoField = 1
addressNodeInfoField = 2
attributesNodeInfoField = 3
stateNodeInfoField = 4
versionInfoResponseBodyField = 1
nodeInfoResponseBodyField = 2
)
func (f *Filter) StableMarshal(buf []byte) []byte {
if f == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, f.StableSize())
}
var offset int
offset += protoutil.StringMarshal(nameFilterField, buf[offset:], f.name)
offset += protoutil.StringMarshal(keyFilterField, buf[offset:], f.key)
offset += protoutil.EnumMarshal(opFilterField, buf[offset:], int32(f.op))
offset += protoutil.StringMarshal(valueFilterField, buf[offset:], f.value)
for i := range f.filters {
offset += protoutil.NestedStructureMarshal(filtersFilterField, buf[offset:], &f.filters[i])
}
return buf
}
func (f *Filter) StableSize() (size int) {
size += protoutil.StringSize(nameFilterField, f.name)
size += protoutil.StringSize(keyFilterField, f.key)
size += protoutil.EnumSize(opFilterField, int32(f.op))
size += protoutil.StringSize(valueFilterField, f.value)
for i := range f.filters {
size += protoutil.NestedStructureSize(filtersFilterField, &f.filters[i])
}
return size
}
func (f *Filter) Unmarshal(data []byte) error {
return message.Unmarshal(f, data, new(netmap.Filter))
}
func (s *Selector) StableMarshal(buf []byte) []byte {
if s == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, s.StableSize())
}
var offset int
offset += protoutil.StringMarshal(nameSelectorField, buf[offset:], s.name)
offset += protoutil.UInt32Marshal(countSelectorField, buf[offset:], s.count)
offset += protoutil.EnumMarshal(clauseSelectorField, buf[offset:], int32(s.clause))
offset += protoutil.StringMarshal(attributeSelectorField, buf[offset:], s.attribute)
protoutil.StringMarshal(filterSelectorField, buf[offset:], s.filter)
return buf
}
func (s *Selector) StableSize() (size int) {
size += protoutil.StringSize(nameSelectorField, s.name)
size += protoutil.UInt32Size(countSelectorField, s.count)
size += protoutil.EnumSize(countSelectorField, int32(s.clause))
size += protoutil.StringSize(attributeSelectorField, s.attribute)
size += protoutil.StringSize(filterSelectorField, s.filter)
return size
}
func (s *Selector) Unmarshal(data []byte) error {
return message.Unmarshal(s, data, new(netmap.Selector))
}
func (r *Replica) StableMarshal(buf []byte) []byte {
if r == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, r.StableSize())
}
var offset int
offset += protoutil.UInt32Marshal(countReplicaField, buf[offset:], r.count)
protoutil.StringMarshal(selectorReplicaField, buf[offset:], r.selector)
return buf
}
func (r *Replica) StableSize() (size int) {
size += protoutil.UInt32Size(countReplicaField, r.count)
size += protoutil.StringSize(selectorReplicaField, r.selector)
return size
}
func (r *Replica) Unmarshal(data []byte) error {
return message.Unmarshal(r, data, new(netmap.Replica))
}
func (p *PlacementPolicy) StableMarshal(buf []byte) []byte {
if p == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, p.StableSize())
}
var offset int
for i := range p.replicas {
offset += protoutil.NestedStructureMarshal(replicasPolicyField, buf[offset:], &p.replicas[i])
}
offset += protoutil.UInt32Marshal(backupPolicyField, buf[offset:], p.backupFactor)
for i := range p.selectors {
offset += protoutil.NestedStructureMarshal(selectorsPolicyField, buf[offset:], &p.selectors[i])
}
for i := range p.filters {
offset += protoutil.NestedStructureMarshal(filtersPolicyField, buf[offset:], &p.filters[i])
}
protoutil.BoolMarshal(uniquePolicyField, buf[offset:], p.unique)
return buf
}
func (p *PlacementPolicy) StableSize() (size int) {
for i := range p.replicas {
size += protoutil.NestedStructureSize(replicasPolicyField, &p.replicas[i])
}
size += protoutil.UInt32Size(backupPolicyField, p.backupFactor)
for i := range p.selectors {
size += protoutil.NestedStructureSize(selectorsPolicyField, &p.selectors[i])
}
for i := range p.filters {
size += protoutil.NestedStructureSize(filtersPolicyField, &p.filters[i])
}
size += protoutil.BoolSize(uniquePolicyField, p.unique)
return size
}
func (p *PlacementPolicy) Unmarshal(data []byte) error {
return message.Unmarshal(p, data, new(netmap.PlacementPolicy))
}
func (a *Attribute) StableMarshal(buf []byte) []byte {
if a == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, a.StableSize())
}
var offset int
offset += protoutil.StringMarshal(keyAttributeField, buf[offset:], a.key)
offset += protoutil.StringMarshal(valueAttributeField, buf[offset:], a.value)
for i := range a.parents {
offset += protoutil.StringMarshal(parentsAttributeField, buf[offset:], a.parents[i])
}
return buf
}
func (a *Attribute) StableSize() (size int) {
if a == nil {
return 0
}
size += protoutil.StringSize(keyAttributeField, a.key)
size += protoutil.StringSize(valueAttributeField, a.value)
for i := range a.parents {
size += protoutil.StringSize(parentsAttributeField, a.parents[i])
}
return size
}
func (a *Attribute) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(netmap.NodeInfo_Attribute))
}
func (ni *NodeInfo) StableMarshal(buf []byte) []byte {
if ni == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, ni.StableSize())
}
var offset int
offset += protoutil.BytesMarshal(keyNodeInfoField, buf[offset:], ni.publicKey)
offset += protoutil.RepeatedStringMarshal(addressNodeInfoField, buf[offset:], ni.addresses)
for i := range ni.attributes {
offset += protoutil.NestedStructureMarshal(attributesNodeInfoField, buf[offset:], &ni.attributes[i])
}
protoutil.EnumMarshal(stateNodeInfoField, buf[offset:], int32(ni.state))
return buf
}
func (ni *NodeInfo) StableSize() (size int) {
if ni == nil {
return 0
}
size += protoutil.BytesSize(keyNodeInfoField, ni.publicKey)
size += protoutil.RepeatedStringSize(addressNodeInfoField, ni.addresses)
for i := range ni.attributes {
size += protoutil.NestedStructureSize(attributesNodeInfoField, &ni.attributes[i])
}
size += protoutil.EnumSize(stateNodeInfoField, int32(ni.state))
return size
}
func (ni *NodeInfo) Unmarshal(data []byte) error {
return message.Unmarshal(ni, data, new(netmap.NodeInfo))
}
func (l *LocalNodeInfoRequestBody) StableMarshal(_ []byte) []byte {
return nil
}
func (l *LocalNodeInfoRequestBody) StableSize() (size int) {
return 0
}
func (l *LocalNodeInfoRequestBody) Unmarshal([]byte) error {
return nil
}
func (l *LocalNodeInfoResponseBody) StableMarshal(buf []byte) []byte {
if l == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, l.StableSize())
}
var offset int
offset += protoutil.NestedStructureMarshal(versionInfoResponseBodyField, buf[offset:], l.version)
protoutil.NestedStructureMarshal(nodeInfoResponseBodyField, buf[offset:], l.nodeInfo)
return buf
}
func (l *LocalNodeInfoResponseBody) StableSize() (size int) {
if l == nil {
return 0
}
size += protoutil.NestedStructureSize(versionInfoResponseBodyField, l.version)
size += protoutil.NestedStructureSize(nodeInfoResponseBodyField, l.nodeInfo)
return size
}
func (l *LocalNodeInfoResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(l, data, new(netmap.LocalNodeInfoResponse_Body))
}
const (
_ = iota
netPrmKeyFNum
netPrmValFNum
)
func (x *NetworkParameter) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
offset += protoutil.BytesMarshal(netPrmKeyFNum, buf[offset:], x.k)
protoutil.BytesMarshal(netPrmValFNum, buf[offset:], x.v)
return buf
}
func (x *NetworkParameter) StableSize() (size int) {
if x == nil {
return 0
}
size += protoutil.BytesSize(netPrmKeyFNum, x.k)
size += protoutil.BytesSize(netPrmValFNum, x.v)
return size
}
const (
_ = iota
netCfgPrmsFNum
)
func (x *NetworkConfig) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
for i := range x.ps {
offset += protoutil.NestedStructureMarshal(netCfgPrmsFNum, buf[offset:], &x.ps[i])
}
return buf
}
func (x *NetworkConfig) StableSize() (size int) {
if x == nil {
return 0
}
for i := range x.ps {
size += protoutil.NestedStructureSize(netCfgPrmsFNum, &x.ps[i])
}
return size
}
const (
_ = iota
netInfoCurEpochFNum
netInfoMagicNumFNum
netInfoMSPerBlockFNum
netInfoCfgFNum
)
func (i *NetworkInfo) StableMarshal(buf []byte) []byte {
if i == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, i.StableSize())
}
var offset int
offset += protoutil.UInt64Marshal(netInfoCurEpochFNum, buf[offset:], i.curEpoch)
offset += protoutil.UInt64Marshal(netInfoMagicNumFNum, buf[offset:], i.magicNum)
offset += protoutil.Int64Marshal(netInfoMSPerBlockFNum, buf[offset:], i.msPerBlock)
protoutil.NestedStructureMarshal(netInfoCfgFNum, buf[offset:], i.netCfg)
return buf
}
func (i *NetworkInfo) StableSize() (size int) {
if i == nil {
return 0
}
size += protoutil.UInt64Size(netInfoCurEpochFNum, i.curEpoch)
size += protoutil.UInt64Size(netInfoMagicNumFNum, i.magicNum)
size += protoutil.Int64Size(netInfoMSPerBlockFNum, i.msPerBlock)
size += protoutil.NestedStructureSize(netInfoCfgFNum, i.netCfg)
return size
}
func (i *NetworkInfo) Unmarshal(data []byte) error {
return message.Unmarshal(i, data, new(netmap.NetworkInfo))
}
func (l *NetworkInfoRequestBody) StableMarshal(_ []byte) []byte {
return nil
}
func (l *NetworkInfoRequestBody) StableSize() (size int) {
return 0
}
func (l *NetworkInfoRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(l, data, new(netmap.NetworkInfoRequest_Body))
}
const (
_ = iota
netInfoRespBodyNetInfoFNum
)
func (i *NetworkInfoResponseBody) StableMarshal(buf []byte) []byte {
if i == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, i.StableSize())
}
protoutil.NestedStructureMarshal(netInfoRespBodyNetInfoFNum, buf, i.netInfo)
return buf
}
func (i *NetworkInfoResponseBody) StableSize() (size int) {
if i == nil {
return 0
}
size += protoutil.NestedStructureSize(netInfoRespBodyNetInfoFNum, i.netInfo)
return size
}
func (i *NetworkInfoResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(i, data, new(netmap.NetworkInfoResponse_Body))
}
const (
_ = iota
fNumNetMapEpoch
fNumNetMapNodes
)
func (x *NetMap) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
offset := protoutil.UInt64Marshal(fNumNetMapEpoch, buf, x.epoch)
for i := range x.nodes {
offset += protoutil.NestedStructureMarshal(fNumNetMapNodes, buf[offset:], &x.nodes[i])
}
return buf
}
func (x *NetMap) StableSize() (size int) {
if x != nil {
size = protoutil.UInt64Size(fNumNetMapEpoch, x.epoch)
for i := range x.nodes {
size += protoutil.NestedStructureSize(fNumNetMapNodes, &x.nodes[i])
}
}
return
}
func (x *SnapshotRequestBody) StableMarshal([]byte) []byte {
return nil
}
func (x *SnapshotRequestBody) StableSize() int {
return 0
}
const (
_ = iota
fNumSnapshotResponseBodyNetMap
)
func (x *SnapshotResponseBody) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
protoutil.NestedStructureMarshal(fNumSnapshotResponseBodyNetMap, buf, x.netMap)
return buf
}
func (x *SnapshotResponseBody) StableSize() (size int) {
if x != nil {
size = protoutil.NestedStructureSize(fNumSnapshotResponseBodyNetMap, x.netMap)
}
return
}

View file

@ -4,29 +4,29 @@ import (
"testing"
netmaptest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
"google.golang.org/protobuf/proto"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return netmaptest.GenerateFilter(empty) },
func(empty bool) message.Message { return netmaptest.GenerateSelector(empty) },
func(empty bool) message.Message { return netmaptest.GenerateReplica(empty) },
func(empty bool) message.Message { return netmaptest.GeneratePlacementPolicy(empty) },
func(empty bool) message.Message { return netmaptest.GenerateAttribute(empty) },
func(empty bool) message.Message { return netmaptest.GenerateNodeInfo(empty) },
func(empty bool) message.Message { return netmaptest.GenerateLocalNodeInfoRequest(empty) },
func(empty bool) message.Message { return netmaptest.GenerateLocalNodeInfoResponseBody(empty) },
func(empty bool) message.Message { return netmaptest.GenerateNetworkParameter(empty) },
func(empty bool) message.Message { return netmaptest.GenerateNetworkConfig(empty) },
func(empty bool) message.Message { return netmaptest.GenerateNetworkInfo(empty) },
func(empty bool) message.Message { return netmaptest.GenerateNetworkInfoRequest(empty) },
func(empty bool) message.Message { return netmaptest.GenerateNetworkInfoResponseBody(empty) },
func(empty bool) message.Message { return netmaptest.GenerateNetMap(empty) },
func(empty bool) message.Message { return netmaptest.GenerateSnapshotRequestBody(empty) },
func(empty bool) message.Message { return netmaptest.GenerateSnapshotRequest(empty) },
func(empty bool) message.Message { return netmaptest.GenerateSnapshotResponseBody(empty) },
func(empty bool) message.Message { return netmaptest.GenerateSnapshotResponse(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateFilter(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateSelector(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateReplica(empty) },
func(empty bool) proto.Message { return netmaptest.GeneratePlacementPolicy(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateAttribute(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateNodeInfo(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateLocalNodeInfoRequest(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateLocalNodeInfoResponseBody(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateNetworkParameter(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateNetworkConfig(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateNetworkInfo(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateNetworkInfoRequest(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateNetworkInfoResponseBody(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateNetMap(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateSnapshotRequestBody(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateSnapshotRequest(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateSnapshotResponseBody(empty) },
func(empty bool) proto.Message { return netmaptest.GenerateSnapshotResponse(empty) },
)
}

View file

@ -1,68 +0,0 @@
package netmap
import (
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
)
// String returns string representation of Clause.
func (x Clause) String() string {
return ClauseToGRPCMessage(x).String()
}
// FromString parses Clause from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Clause) FromString(s string) bool {
var g netmap.Clause
ok := g.FromString(s)
if ok {
*x = ClauseFromGRPCMessage(g)
}
return ok
}
// String returns string representation of Operation.
func (x Operation) String() string {
return OperationToGRPCMessage(x).String()
}
// FromString parses Operation from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Operation) FromString(s string) bool {
var g netmap.Operation
ok := g.FromString(s)
if ok {
*x = OperationFromGRPCMessage(g)
}
return ok
}
// String returns string representation of NodeState.
func (x NodeState) String() string {
return NodeStateToGRPCMessage(x).String()
}
// FromString parses NodeState from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *NodeState) FromString(s string) bool {
var g netmap.NodeInfo_State
ok := g.FromString(s)
if ok {
*x = NodeStateFromRPCMessage(g)
}
return ok
}

View file

@ -1,7 +1,7 @@
package netmaptest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test"
)
@ -20,9 +20,9 @@ func generateFilter(empty, withSub bool) *netmap.Filter {
m.SetOp(1)
if withSub {
m.SetFilters([]netmap.Filter{
*generateFilter(empty, false),
*generateFilter(empty, false),
m.SetFilters([]*netmap.Filter{
generateFilter(empty, false),
generateFilter(empty, false),
})
}
}
@ -30,13 +30,13 @@ func generateFilter(empty, withSub bool) *netmap.Filter {
return m
}
func GenerateFilters(empty bool) []netmap.Filter {
var res []netmap.Filter
func GenerateFilters(empty bool) []*netmap.Filter {
var res []*netmap.Filter
if !empty {
res = append(res,
*GenerateFilter(false),
*GenerateFilter(false),
GenerateFilter(false),
GenerateFilter(false),
)
}
@ -57,13 +57,13 @@ func GenerateSelector(empty bool) *netmap.Selector {
return m
}
func GenerateSelectors(empty bool) []netmap.Selector {
var res []netmap.Selector
func GenerateSelectors(empty bool) []*netmap.Selector {
var res []*netmap.Selector
if !empty {
res = append(res,
*GenerateSelector(false),
*GenerateSelector(false),
GenerateSelector(false),
GenerateSelector(false),
)
}
@ -81,13 +81,13 @@ func GenerateReplica(empty bool) *netmap.Replica {
return m
}
func GenerateReplicas(empty bool) []netmap.Replica {
var res []netmap.Replica
func GenerateReplicas(empty bool) []*netmap.Replica {
var res []*netmap.Replica
if !empty {
res = append(res,
*GenerateReplica(false),
*GenerateReplica(false),
GenerateReplica(false),
GenerateReplica(false),
)
}
@ -107,8 +107,8 @@ func GeneratePlacementPolicy(empty bool) *netmap.PlacementPolicy {
return m
}
func GenerateAttribute(empty bool) *netmap.Attribute {
m := new(netmap.Attribute)
func GenerateAttribute(empty bool) *netmap.NodeInfo_Attribute {
m := new(netmap.NodeInfo_Attribute)
if !empty {
m.SetKey("attribute key")
@ -118,13 +118,13 @@ func GenerateAttribute(empty bool) *netmap.Attribute {
return m
}
func GenerateAttributes(empty bool) []netmap.Attribute {
var res []netmap.Attribute
func GenerateAttributes(empty bool) []*netmap.NodeInfo_Attribute {
var res []*netmap.NodeInfo_Attribute
if !empty {
res = append(res,
*GenerateAttribute(false),
*GenerateAttribute(false),
GenerateAttribute(false),
GenerateAttribute(false),
)
}
@ -135,7 +135,7 @@ func GenerateNodeInfo(empty bool) *netmap.NodeInfo {
m := new(netmap.NodeInfo)
if !empty {
m.SetAddresses("node address", "node address 2")
m.SetAddresses([]string{"node address", "node address 2"})
m.SetPublicKey([]byte{1, 2, 3})
m.SetState(33)
m.SetAttributes(GenerateAttributes(empty))
@ -144,8 +144,8 @@ func GenerateNodeInfo(empty bool) *netmap.NodeInfo {
return m
}
func GenerateLocalNodeInfoRequestBody(_ bool) *netmap.LocalNodeInfoRequestBody {
m := new(netmap.LocalNodeInfoRequestBody)
func GenerateLocalNodeInfoRequestBody(_ bool) *netmap.LocalNodeInfoRequest_Body {
m := new(netmap.LocalNodeInfoRequest_Body)
return m
}
@ -158,13 +158,13 @@ func GenerateLocalNodeInfoRequest(empty bool) *netmap.LocalNodeInfoRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateLocalNodeInfoResponseBody(empty bool) *netmap.LocalNodeInfoResponseBody {
m := new(netmap.LocalNodeInfoResponseBody)
func GenerateLocalNodeInfoResponseBody(empty bool) *netmap.LocalNodeInfoResponse_Body {
m := new(netmap.LocalNodeInfoResponse_Body)
if !empty {
m.SetNodeInfo(GenerateNodeInfo(false))
@ -183,13 +183,13 @@ func GenerateLocalNodeInfoResponse(empty bool) *netmap.LocalNodeInfoResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateNetworkParameter(empty bool) *netmap.NetworkParameter {
m := new(netmap.NetworkParameter)
func GenerateNetworkParameter(empty bool) *netmap.NetworkConfig_Parameter {
m := new(netmap.NetworkConfig_Parameter)
if !empty {
m.SetKey([]byte("key"))
@ -203,10 +203,10 @@ func GenerateNetworkConfig(empty bool) *netmap.NetworkConfig {
m := new(netmap.NetworkConfig)
if !empty {
m.SetParameters(
*GenerateNetworkParameter(empty),
*GenerateNetworkParameter(empty),
)
m.SetParameters([]*netmap.NetworkConfig_Parameter{
GenerateNetworkParameter(empty),
GenerateNetworkParameter(empty),
})
}
return m
@ -225,8 +225,8 @@ func GenerateNetworkInfo(empty bool) *netmap.NetworkInfo {
return m
}
func GenerateNetworkInfoRequestBody(_ bool) *netmap.NetworkInfoRequestBody {
m := new(netmap.NetworkInfoRequestBody)
func GenerateNetworkInfoRequestBody(_ bool) *netmap.NetworkInfoRequest_Body {
m := new(netmap.NetworkInfoRequest_Body)
return m
}
@ -239,13 +239,13 @@ func GenerateNetworkInfoRequest(empty bool) *netmap.NetworkInfoRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateNetworkInfoResponseBody(empty bool) *netmap.NetworkInfoResponseBody {
m := new(netmap.NetworkInfoResponseBody)
func GenerateNetworkInfoResponseBody(empty bool) *netmap.NetworkInfoResponse_Body {
m := new(netmap.NetworkInfoResponse_Body)
if !empty {
m.SetNetworkInfo(GenerateNetworkInfo(false))
@ -262,61 +262,61 @@ func GenerateNetworkInfoResponse(empty bool) *netmap.NetworkInfoResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateNetMap(empty bool) *netmap.NetMap {
m := new(netmap.NetMap)
func GenerateNetMap(empty bool) *netmap.Netmap {
m := new(netmap.Netmap)
if !empty {
m.SetEpoch(987)
m.SetNodes([]netmap.NodeInfo{
*GenerateNodeInfo(false),
*GenerateNodeInfo(false),
m.SetNodes([]*netmap.NodeInfo{
GenerateNodeInfo(false),
GenerateNodeInfo(false),
})
}
return m
}
func GenerateSnapshotRequestBody(_ bool) *netmap.SnapshotRequestBody {
return new(netmap.SnapshotRequestBody)
func GenerateSnapshotRequestBody(_ bool) *netmap.NetmapSnapshotRequest_Body {
return new(netmap.NetmapSnapshotRequest_Body)
}
func GenerateSnapshotRequest(empty bool) *netmap.SnapshotRequest {
m := new(netmap.SnapshotRequest)
func GenerateSnapshotRequest(empty bool) *netmap.NetmapSnapshotRequest {
m := new(netmap.NetmapSnapshotRequest)
if !empty {
m.SetBody(GenerateSnapshotRequestBody(false))
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateSnapshotResponseBody(empty bool) *netmap.SnapshotResponseBody {
m := new(netmap.SnapshotResponseBody)
func GenerateSnapshotResponseBody(empty bool) *netmap.NetmapSnapshotResponse_Body {
m := new(netmap.NetmapSnapshotResponse_Body)
if !empty {
m.SetNetMap(GenerateNetMap(false))
m.SetNetmap(GenerateNetMap(false))
}
return m
}
func GenerateSnapshotResponse(empty bool) *netmap.SnapshotResponse {
m := new(netmap.SnapshotResponse)
func GenerateSnapshotResponse(empty bool) *netmap.NetmapSnapshotResponse {
m := new(netmap.NetmapSnapshotResponse)
if !empty {
m.SetBody(GenerateSnapshotResponseBody(false))
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}

View file

@ -1,751 +0,0 @@
package netmap
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
)
type LocalNodeInfoRequest struct {
body *LocalNodeInfoRequestBody
session.RequestHeaders
}
type LocalNodeInfoResponse struct {
body *LocalNodeInfoResponseBody
session.ResponseHeaders
}
// NetworkInfoRequest is a structure of NetworkInfo request.
type NetworkInfoRequest struct {
body *NetworkInfoRequestBody
session.RequestHeaders
}
// NetworkInfoResponse is a structure of NetworkInfo response.
type NetworkInfoResponse struct {
body *NetworkInfoResponseBody
session.ResponseHeaders
}
type Filter struct {
name string
key string
op Operation
value string
filters []Filter
}
type Selector struct {
name string
count uint32
clause Clause
attribute string
filter string
}
type Replica struct {
count uint32
selector string
}
type Operation uint32
type PlacementPolicy struct {
replicas []Replica
backupFactor uint32
selectors []Selector
filters []Filter
unique bool
}
// Attribute of storage node.
type Attribute struct {
key string
value string
parents []string
}
// NodeInfo of storage node.
type NodeInfo struct {
publicKey []byte
addresses []string
attributes []Attribute
state NodeState
}
// NodeState of storage node.
type NodeState uint32
// Clause of placement selector.
type Clause uint32
type LocalNodeInfoRequestBody struct{}
type LocalNodeInfoResponseBody struct {
version *refs.Version
nodeInfo *NodeInfo
}
const (
UnspecifiedState NodeState = iota
Online
Offline
Maintenance
)
const (
UnspecifiedOperation Operation = iota
EQ
NE
GT
GE
LT
LE
OR
AND
NOT
)
const (
UnspecifiedClause Clause = iota
Same
Distinct
)
func (f *Filter) GetFilters() []Filter {
if f != nil {
return f.filters
}
return nil
}
func (f *Filter) SetFilters(filters []Filter) {
f.filters = filters
}
func (f *Filter) GetValue() string {
if f != nil {
return f.value
}
return ""
}
func (f *Filter) SetValue(value string) {
f.value = value
}
func (f *Filter) GetOp() Operation {
if f != nil {
return f.op
}
return UnspecifiedOperation
}
func (f *Filter) SetOp(op Operation) {
f.op = op
}
func (f *Filter) GetKey() string {
if f != nil {
return f.key
}
return ""
}
func (f *Filter) SetKey(key string) {
f.key = key
}
func (f *Filter) GetName() string {
if f != nil {
return f.name
}
return ""
}
func (f *Filter) SetName(name string) {
f.name = name
}
func (s *Selector) GetFilter() string {
if s != nil {
return s.filter
}
return ""
}
func (s *Selector) SetFilter(filter string) {
s.filter = filter
}
func (s *Selector) GetAttribute() string {
if s != nil {
return s.attribute
}
return ""
}
func (s *Selector) SetAttribute(attribute string) {
s.attribute = attribute
}
func (s *Selector) GetClause() Clause {
if s != nil {
return s.clause
}
return UnspecifiedClause
}
func (s *Selector) SetClause(clause Clause) {
s.clause = clause
}
func (s *Selector) GetCount() uint32 {
if s != nil {
return s.count
}
return 0
}
func (s *Selector) SetCount(count uint32) {
s.count = count
}
func (s *Selector) GetName() string {
if s != nil {
return s.name
}
return ""
}
func (s *Selector) SetName(name string) {
s.name = name
}
func (r *Replica) GetSelector() string {
if r != nil {
return r.selector
}
return ""
}
func (r *Replica) SetSelector(selector string) {
r.selector = selector
}
func (r *Replica) GetCount() uint32 {
if r != nil {
return r.count
}
return 0
}
func (r *Replica) SetCount(count uint32) {
r.count = count
}
func (p *PlacementPolicy) GetUnique() bool {
if p != nil {
return p.unique
}
return false
}
func (p *PlacementPolicy) SetUnique(unique bool) {
p.unique = unique
}
func (p *PlacementPolicy) GetFilters() []Filter {
if p != nil {
return p.filters
}
return nil
}
func (p *PlacementPolicy) SetFilters(filters []Filter) {
p.filters = filters
}
func (p *PlacementPolicy) GetSelectors() []Selector {
if p != nil {
return p.selectors
}
return nil
}
func (p *PlacementPolicy) SetSelectors(selectors []Selector) {
p.selectors = selectors
}
func (p *PlacementPolicy) GetContainerBackupFactor() uint32 {
if p != nil {
return p.backupFactor
}
return 0
}
func (p *PlacementPolicy) SetContainerBackupFactor(backupFactor uint32) {
p.backupFactor = backupFactor
}
func (p *PlacementPolicy) GetReplicas() []Replica {
return p.replicas
}
func (p *PlacementPolicy) SetReplicas(replicas []Replica) {
p.replicas = replicas
}
func (a *Attribute) GetKey() string {
if a != nil {
return a.key
}
return ""
}
func (a *Attribute) SetKey(v string) {
a.key = v
}
func (a *Attribute) GetValue() string {
if a != nil {
return a.value
}
return ""
}
func (a *Attribute) SetValue(v string) {
a.value = v
}
func (a *Attribute) GetParents() []string {
if a != nil {
return a.parents
}
return nil
}
func (a *Attribute) SetParents(parent []string) {
a.parents = parent
}
func (ni *NodeInfo) GetPublicKey() []byte {
if ni != nil {
return ni.publicKey
}
return nil
}
func (ni *NodeInfo) SetPublicKey(v []byte) {
ni.publicKey = v
}
// GetAddress returns node's network address.
//
// Deprecated: use IterateAddresses.
func (ni *NodeInfo) GetAddress() (addr string) {
ni.IterateAddresses(func(s string) bool {
addr = s
return true
})
return
}
// SetAddress sets node's network address.
//
// Deprecated: use SetAddresses.
func (ni *NodeInfo) SetAddress(v string) {
ni.SetAddresses(v)
}
// SetAddresses sets list of network addresses of the node.
func (ni *NodeInfo) SetAddresses(v ...string) {
ni.addresses = v
}
// NumberOfAddresses returns number of network addresses of the node.
func (ni *NodeInfo) NumberOfAddresses() int {
if ni != nil {
return len(ni.addresses)
}
return 0
}
// IterateAddresses iterates over network addresses of the node.
// Breaks iteration on f's true return.
//
// Handler should not be nil.
func (ni *NodeInfo) IterateAddresses(f func(string) bool) {
if ni != nil {
for i := range ni.addresses {
if f(ni.addresses[i]) {
break
}
}
}
}
func (ni *NodeInfo) GetAttributes() []Attribute {
if ni != nil {
return ni.attributes
}
return nil
}
func (ni *NodeInfo) SetAttributes(v []Attribute) {
ni.attributes = v
}
func (ni *NodeInfo) GetState() NodeState {
if ni != nil {
return ni.state
}
return UnspecifiedState
}
func (ni *NodeInfo) SetState(state NodeState) {
ni.state = state
}
func (l *LocalNodeInfoResponseBody) GetVersion() *refs.Version {
if l != nil {
return l.version
}
return nil
}
func (l *LocalNodeInfoResponseBody) SetVersion(version *refs.Version) {
l.version = version
}
func (l *LocalNodeInfoResponseBody) GetNodeInfo() *NodeInfo {
if l != nil {
return l.nodeInfo
}
return nil
}
func (l *LocalNodeInfoResponseBody) SetNodeInfo(nodeInfo *NodeInfo) {
l.nodeInfo = nodeInfo
}
func (l *LocalNodeInfoRequest) GetBody() *LocalNodeInfoRequestBody {
if l != nil {
return l.body
}
return nil
}
func (l *LocalNodeInfoRequest) SetBody(body *LocalNodeInfoRequestBody) {
l.body = body
}
func (l *LocalNodeInfoResponse) GetBody() *LocalNodeInfoResponseBody {
if l != nil {
return l.body
}
return nil
}
func (l *LocalNodeInfoResponse) SetBody(body *LocalNodeInfoResponseBody) {
l.body = body
}
// NetworkParameter represents NeoFS network parameter.
type NetworkParameter struct {
k, v []byte
}
// GetKey returns parameter key.
func (x *NetworkParameter) GetKey() []byte {
if x != nil {
return x.k
}
return nil
}
// SetKey sets parameter key.
func (x *NetworkParameter) SetKey(k []byte) {
x.k = k
}
// GetValue returns parameter value.
func (x *NetworkParameter) GetValue() []byte {
if x != nil {
return x.v
}
return nil
}
// SetValue sets parameter value.
func (x *NetworkParameter) SetValue(v []byte) {
x.v = v
}
// NetworkConfig represents NeoFS network configuration.
type NetworkConfig struct {
ps []NetworkParameter
}
// NumberOfParameters returns number of network parameters.
func (x *NetworkConfig) NumberOfParameters() int {
if x != nil {
return len(x.ps)
}
return 0
}
// IterateParameters iterates over network parameters.
// Breaks iteration on f's true return.
//
// Handler must not be nil.
func (x *NetworkConfig) IterateParameters(f func(*NetworkParameter) bool) {
if x != nil {
for i := range x.ps {
if f(&x.ps[i]) {
break
}
}
}
}
// SetParameters sets list of network parameters.
func (x *NetworkConfig) SetParameters(v ...NetworkParameter) {
x.ps = v
}
// NetworkInfo groups information about
// NeoFS network.
type NetworkInfo struct {
curEpoch, magicNum uint64
msPerBlock int64
netCfg *NetworkConfig
}
// GetCurrentEpoch returns number of the current epoch.
func (i *NetworkInfo) GetCurrentEpoch() uint64 {
if i != nil {
return i.curEpoch
}
return 0
}
// SetCurrentEpoch sets number of the current epoch.
func (i *NetworkInfo) SetCurrentEpoch(epoch uint64) {
i.curEpoch = epoch
}
// GetMagicNumber returns magic number of the sidechain.
func (i *NetworkInfo) GetMagicNumber() uint64 {
if i != nil {
return i.magicNum
}
return 0
}
// SetMagicNumber sets magic number of the sidechain.
func (i *NetworkInfo) SetMagicNumber(magic uint64) {
i.magicNum = magic
}
// GetMsPerBlock returns MillisecondsPerBlock network parameter.
func (i *NetworkInfo) GetMsPerBlock() int64 {
if i != nil {
return i.msPerBlock
}
return 0
}
// SetMsPerBlock sets MillisecondsPerBlock network parameter.
func (i *NetworkInfo) SetMsPerBlock(v int64) {
i.msPerBlock = v
}
// GetNetworkConfig returns NeoFS network configuration.
func (i *NetworkInfo) GetNetworkConfig() *NetworkConfig {
if i != nil {
return i.netCfg
}
return nil
}
// SetNetworkConfig sets NeoFS network configuration.
func (i *NetworkInfo) SetNetworkConfig(v *NetworkConfig) {
i.netCfg = v
}
// NetworkInfoRequestBody is a structure of NetworkInfo request body.
type NetworkInfoRequestBody struct{}
// NetworkInfoResponseBody is a structure of NetworkInfo response body.
type NetworkInfoResponseBody struct {
netInfo *NetworkInfo
}
// GetNetworkInfo returns information about the NeoFS network.
func (i *NetworkInfoResponseBody) GetNetworkInfo() *NetworkInfo {
if i != nil {
return i.netInfo
}
return nil
}
// SetNetworkInfo sets information about the NeoFS network.
func (i *NetworkInfoResponseBody) SetNetworkInfo(netInfo *NetworkInfo) {
i.netInfo = netInfo
}
func (l *NetworkInfoRequest) GetBody() *NetworkInfoRequestBody {
if l != nil {
return l.body
}
return nil
}
func (l *NetworkInfoRequest) SetBody(body *NetworkInfoRequestBody) {
l.body = body
}
func (l *NetworkInfoResponse) GetBody() *NetworkInfoResponseBody {
if l != nil {
return l.body
}
return nil
}
func (l *NetworkInfoResponse) SetBody(body *NetworkInfoResponseBody) {
l.body = body
}
// NetMap represents structure of NeoFS network map.
type NetMap struct {
epoch uint64
nodes []NodeInfo
}
// Epoch returns revision number of the NetMap.
func (x *NetMap) Epoch() uint64 {
if x != nil {
return x.epoch
}
return 0
}
// SetEpoch sets revision number of the NetMap.
func (x *NetMap) SetEpoch(v uint64) {
x.epoch = v
}
// Nodes returns nodes presented in the NetMap.
func (x *NetMap) Nodes() []NodeInfo {
if x != nil {
return x.nodes
}
return nil
}
// SetNodes sets nodes presented in the NetMap.
func (x *NetMap) SetNodes(v []NodeInfo) {
x.nodes = v
}
// SnapshotRequestBody represents structure of Snapshot request body.
type SnapshotRequestBody struct{}
// SnapshotRequest represents structure of Snapshot request.
type SnapshotRequest struct {
body *SnapshotRequestBody
session.RequestHeaders
}
func (x *SnapshotRequest) GetBody() *SnapshotRequestBody {
if x != nil {
return x.body
}
return nil
}
func (x *SnapshotRequest) SetBody(body *SnapshotRequestBody) {
x.body = body
}
// SnapshotResponseBody represents structure of Snapshot response body.
type SnapshotResponseBody struct {
netMap *NetMap
}
// NetMap returns current NetMap.
func (x *SnapshotResponseBody) NetMap() *NetMap {
if x != nil {
return x.netMap
}
return nil
}
// SetNetMap sets current NetMap.
func (x *SnapshotResponseBody) SetNetMap(netMap *NetMap) {
x.netMap = netMap
}
// SnapshotResponse represents structure of Snapshot response.
type SnapshotResponse struct {
body *SnapshotResponseBody
session.ResponseHeaders
}
func (x *SnapshotResponse) GetBody() *SnapshotResponseBody {
if x != nil {
return x.body
}
return nil
}
func (x *SnapshotResponse) SetBody(body *SnapshotResponseBody) {
x.body = body
}

View file

@ -4,6 +4,8 @@ import (
"errors"
"fmt"
"strconv"
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
)
// SysAttributePrefix is a prefix of key to system attribute.
@ -85,10 +87,10 @@ func (n *NotificationInfo) SetTopic(topic string) {
// WriteNotificationInfo writes NotificationInfo to the Object via attributes. Object must not be nil.
//
// Existing notification attributes are expected to be key-unique, otherwise undefined behavior.
func WriteNotificationInfo(o *Object, ni NotificationInfo) {
func WriteNotificationInfo(o *object.Object, ni NotificationInfo) {
h := o.GetHeader()
if h == nil {
h = new(Header)
h = new(object.Header)
o.SetHeader(h)
}
@ -134,14 +136,16 @@ func WriteNotificationInfo(o *Object, ni NotificationInfo) {
if !changedEpoch {
index := len(attrs)
attrs = append(attrs, Attribute{})
attr := new(object.Header_Attribute)
attrs = append(attrs, attr)
attrs[index].SetKey(SysAttributeTickEpoch)
attrs[index].SetValue(epoch)
}
if !changedTopic && topic != "" {
index := len(attrs)
attrs = append(attrs, Attribute{})
attr := new(object.Header_Attribute)
attrs = append(attrs, attr)
attrs[index].SetKey(SysAttributeTickTopic)
attrs[index].SetValue(topic)
}
@ -157,7 +161,7 @@ var ErrNotificationNotSet = errors.New("notification for object is not set")
// were found.
//
// Existing notification attributes are expected to be key-unique, otherwise undefined behavior.
func GetNotificationInfo(o *Object) (*NotificationInfo, error) {
func GetNotificationInfo(o *object.Object) (*NotificationInfo, error) {
var (
foundEpoch bool
ni = new(NotificationInfo)

View file

@ -4,11 +4,12 @@ import (
"strconv"
"testing"
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
"github.com/stretchr/testify/require"
)
func TestSetNotification(t *testing.T) {
o := new(Object)
o := new(object.Object)
var ni = NotificationInfo{
epoch: 10,
@ -40,14 +41,18 @@ func TestSetNotification(t *testing.T) {
}
func TestGetNotification(t *testing.T) {
o := new(Object)
o := new(object.Object)
attr := []Attribute{
{SysAttributeTickEpoch, "10"},
{SysAttributeTickTopic, "test"},
attr := []*object.Header_Attribute{
{
Key: SysAttributeTickEpoch, Value: "10",
},
{
Key: SysAttributeTickTopic, Value: "test",
},
}
h := new(Header)
h := new(object.Header)
h.SetAttributes(attr)
o.SetHeader(h)
@ -62,7 +67,7 @@ func TestGetNotification(t *testing.T) {
}
func TestIntegration(t *testing.T) {
o := new(Object)
o := new(object.Object)
var (
ni1 = NotificationInfo{

View file

@ -1,45 +0,0 @@
package object
import (
"math/rand"
"testing"
"github.com/stretchr/testify/require"
)
func randString(n int) string {
x := make([]byte, n)
for i := range x {
x[i] = byte('a' + rand.Intn('z'-'a'))
}
return string(x)
}
func BenchmarkAttributesMarshal(b *testing.B) {
attrs := make([]Attribute, 50)
for i := range attrs {
attrs[i].key = SysAttributePrefix + randString(10)
attrs[i].val = randString(10)
}
raw := AttributesToGRPC(attrs)
require.Equal(b, len(raw), len(attrs))
b.Run("marshal", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
res := AttributesToGRPC(attrs)
if len(res) != len(raw) {
b.FailNow()
}
}
})
b.Run("unmarshal", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
res, err := AttributesFromGRPC(raw)
if err != nil || len(res) != len(raw) {
b.FailNow()
}
}
})
}

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,12 @@ import (
session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
)
type GetResponseBodyObjectPart = isGetResponse_Body_ObjectPart
type GetRangeResponseBodyRangePart = isGetRangeResponse_Body_RangePart
type HeadResponseBodyHead = isHeadResponse_Body_Head
// SetAddress sets address of the requested object.
func (m *GetRequest_Body) SetAddress(v *refs.Address) {
m.Address = v
@ -535,3 +541,11 @@ func (m *PutSingleResponse) SetMetaHeader(v *session.ResponseMetaHeader) {
func (m *PutSingleResponse) SetVerifyHeader(v *session.ResponseVerificationHeader) {
m.VerifyHeader = v
}
func (r *PutRequest_Body_Init_) GetCopiesNumber() []uint32 {
if r != nil {
return r.Init.CopiesNumber
}
return nil
}

Binary file not shown.

BIN
object/grpc/service_frostfs.pb.go generated Normal file

Binary file not shown.

Binary file not shown.

BIN
object/grpc/types.pb.go generated

Binary file not shown.

BIN
object/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,78 +0,0 @@
package object
import (
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (h *ShortHeader) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(h)
}
func (h *ShortHeader) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(h, data, new(object.ShortHeader))
}
func (a *Attribute) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(a)
}
func (a *Attribute) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(a, data, new(object.Header_Attribute))
}
func (h *SplitHeader) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(h)
}
func (h *SplitHeader) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(h, data, new(object.Header_Split))
}
func (h *Header) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(h)
}
func (h *Header) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(h, data, new(object.Header))
}
func (h *HeaderWithSignature) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(h)
}
func (h *HeaderWithSignature) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(h, data, new(object.HeaderWithSignature))
}
func (o *Object) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(o)
}
func (o *Object) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(o, data, new(object.Object))
}
func (s *SplitInfo) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(s)
}
func (s *SplitInfo) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(s, data, new(object.SplitInfo))
}
func (f *SearchFilter) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(f)
}
func (f *SearchFilter) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(f, data, new(object.SearchRequest_Body_Filter))
}
func (r *Range) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(r)
}
func (r *Range) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(r, data, new(object.Range))
}

View file

@ -1,160 +0,0 @@
package object
import (
"errors"
"fmt"
lock "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refsGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
// Lock represents object Lock message from NeoFS API V2 protocol.
type Lock struct {
members []refs.ObjectID
}
// NumberOfMembers returns length of lock list.
func (x *Lock) NumberOfMembers() int {
if x != nil {
return len(x.members)
}
return 0
}
// IterateMembers passes members of the lock list to f.
func (x *Lock) IterateMembers(f func(refs.ObjectID)) {
if x != nil {
for i := range x.members {
f(x.members[i])
}
}
}
// SetMembers sets list of locked members.
// Arg must not be mutated for the duration of the Lock.
func (x *Lock) SetMembers(ids []refs.ObjectID) {
x.members = ids
}
const (
_ = iota
fNumLockMembers
)
// StableMarshal encodes the Lock into Protocol Buffers binary format
// with direct field order.
func (x *Lock) StableMarshal(buf []byte) []byte {
if x == nil || len(x.members) == 0 {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
for i := range x.members {
offset += proto.NestedStructureMarshal(fNumLockMembers, buf[offset:], &x.members[i])
}
return buf
}
// StableSize size of the buffer required to write the Lock in Protocol Buffers
// binary format.
func (x *Lock) StableSize() (sz int) {
if x != nil {
for i := range x.members {
sz += proto.NestedStructureSize(fNumLockMembers, &x.members[i])
}
}
return
}
// Unmarshal decodes the Lock from its Protocol Buffers binary format.
func (x *Lock) Unmarshal(data []byte) error {
return message.Unmarshal(x, data, new(lock.Lock))
}
func (x *Lock) ToGRPCMessage() grpc.Message {
var m *lock.Lock
if x != nil {
m = new(lock.Lock)
var members []*refsGRPC.ObjectID
if x.members != nil {
members = make([]*refsGRPC.ObjectID, len(x.members))
for i := range x.members {
members[i] = x.members[i].ToGRPCMessage().(*refsGRPC.ObjectID)
}
}
m.SetMembers(members)
}
return m
}
func (x *Lock) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*lock.Lock)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
members := v.GetMembers()
if members == nil {
x.members = nil
} else {
x.members = make([]refs.ObjectID, len(members))
var err error
for i := range x.members {
err = x.members[i].FromGRPCMessage(members[i])
if err != nil {
return err
}
}
}
return nil
}
// WriteLock writes Lock to the Object as a payload content.
// The object must not be nil.
func WriteLock(obj *Object, lock Lock) {
hdr := obj.GetHeader()
if hdr == nil {
hdr = new(Header)
obj.SetHeader(hdr)
}
hdr.SetObjectType(TypeLock)
payload := lock.StableMarshal(nil)
obj.SetPayload(payload)
}
// ReadLock reads Lock from the Object payload content.
func ReadLock(lock *Lock, obj Object) error {
payload := obj.GetPayload()
if len(payload) == 0 {
return errors.New("empty payload")
}
err := lock.Unmarshal(payload)
if err != nil {
return fmt.Errorf("decode lock content from payload: %w", err)
}
return nil
}

View file

@ -1,26 +0,0 @@
package object_test
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
objecttest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/test"
"github.com/stretchr/testify/require"
)
func TestLockRW(t *testing.T) {
var l object.Lock
var obj object.Object
require.Error(t, object.ReadLock(&l, obj))
l = *objecttest.GenerateLock(false)
object.WriteLock(&obj, l)
var l2 object.Lock
require.NoError(t, object.ReadLock(&l2, obj))
require.Equal(t, l, l2)
}

File diff suppressed because it is too large Load diff

View file

@ -4,54 +4,58 @@ import (
"testing"
objecttest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
"google.golang.org/protobuf/proto"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return objecttest.GenerateShortHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateAttribute(empty) },
func(empty bool) message.Message { return objecttest.GenerateSplitHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeader(empty) },
func(empty bool) message.Message { return objecttest.GenerateObject(empty) },
func(empty bool) message.Message { return objecttest.GenerateSplitInfo(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRequest(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetObjectPartInit(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetObjectPartChunk(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetResponse(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutObjectPartInit(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutObjectPartChunk(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutRequest(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutResponse(empty) },
func(empty bool) message.Message { return objecttest.GenerateDeleteRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateDeleteRequest(empty) },
func(empty bool) message.Message { return objecttest.GenerateDeleteResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateDeleteResponse(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeadRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeadRequest(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeadResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateHeadResponse(empty) },
func(empty bool) message.Message { return objecttest.GenerateSearchFilter(empty) },
func(empty bool) message.Message { return objecttest.GenerateSearchRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateSearchRequest(empty) },
func(empty bool) message.Message { return objecttest.GenerateSearchResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateSearchResponse(empty) },
func(empty bool) message.Message { return objecttest.GenerateRange(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeRequest(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeResponse(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeHashRequestBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeHashRequest(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeHashResponseBody(empty) },
func(empty bool) message.Message { return objecttest.GenerateGetRangeHashResponse(empty) },
func(empty bool) message.Message { return objecttest.GenerateLock(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutSingleRequest(empty) },
func(empty bool) message.Message { return objecttest.GeneratePutSingleResponse(empty) },
)
func(empty bool) proto.Message { return objecttest.GenerateShortHeader(empty) },
func(empty bool) proto.Message { return objecttest.GenerateAttribute(empty) },
func(empty bool) proto.Message { return objecttest.GenerateSplitHeader(empty) },
func(empty bool) proto.Message { return objecttest.GenerateHeader(empty) },
func(empty bool) proto.Message { return objecttest.GenerateObject(empty) },
func(empty bool) proto.Message { return objecttest.GenerateSplitInfo(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRequestBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRequest(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetObjectPartInit(empty) },
func(empty bool) proto.Message {
return objecttest.GenerateGetResponseBodyWithBodyType(objecttest.InitType)
},
func(empty bool) proto.Message {
return objecttest.GenerateGetResponseBodyWithBodyType(objecttest.ChunkType)
},
func(empty bool) proto.Message {
return objecttest.GenerateGetResponseBodyWithBodyType(objecttest.SplitInfoType)
},
func(empty bool) proto.Message { return objecttest.GenerateGetResponse(empty) },
func(empty bool) proto.Message { return objecttest.GeneratePutObjectPartInit(empty) },
func(empty bool) proto.Message { return objecttest.GeneratePutRequestBody(empty) },
func(empty bool) proto.Message { return objecttest.GeneratePutRequest(empty) },
func(empty bool) proto.Message { return objecttest.GeneratePutResponseBody(empty) },
func(empty bool) proto.Message { return objecttest.GeneratePutResponse(empty) },
func(empty bool) proto.Message { return objecttest.GenerateDeleteRequestBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateDeleteRequest(empty) },
func(empty bool) proto.Message { return objecttest.GenerateDeleteResponseBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateDeleteResponse(empty) },
func(empty bool) proto.Message { return objecttest.GenerateHeadRequestBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateHeadRequest(empty) },
func(empty bool) proto.Message { return objecttest.GenerateHeadResponseBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateHeadResponse(empty) },
func(empty bool) proto.Message { return objecttest.GenerateSearchFilter(empty) },
func(empty bool) proto.Message { return objecttest.GenerateSearchRequestBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateSearchRequest(empty) },
func(empty bool) proto.Message { return objecttest.GenerateSearchResponseBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateSearchResponse(empty) },
func(empty bool) proto.Message { return objecttest.GenerateRange(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeRequestBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeRequest(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeResponseBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeResponse(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashRequestBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashRequest(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashResponseBody(empty) },
func(empty bool) proto.Message { return objecttest.GenerateGetRangeHashResponse(empty) },
func(empty bool) proto.Message { return objecttest.GeneratePutSingleRequest(empty) },
func(empty bool) proto.Message { return objecttest.GeneratePutSingleResponse(empty) })
}

View file

@ -53,11 +53,11 @@ const (
// into status.Status as a detail. The status must not be nil.
//
// Existing details are expected to be ID-unique, otherwise undefined behavior.
func WriteAccessDeniedDesc(st *status.Status, desc string) {
func WriteAccessDeniedDesc(st *statusgrpc.Status, desc string) {
var found bool
st.IterateDetails(func(d *status.Detail) bool {
if d.ID() == detailAccessDeniedDesc {
st.IterateDetails(func(d *statusgrpc.Status_Detail) bool {
if d.GetId() == detailAccessDeniedDesc {
found = true
d.SetValue([]byte(desc))
}
@ -66,9 +66,9 @@ func WriteAccessDeniedDesc(st *status.Status, desc string) {
})
if !found {
var d status.Detail
d := new(statusgrpc.Status_Detail)
d.SetID(detailAccessDeniedDesc)
d.SetId(detailAccessDeniedDesc)
d.SetValue([]byte(desc))
st.AppendDetails(d)
@ -77,10 +77,10 @@ func WriteAccessDeniedDesc(st *status.Status, desc string) {
// ReadAccessDeniedDesc looks up for status detail with human-readable description
// of StatusAccessDenied. Returns empty string if detail is missing.
func ReadAccessDeniedDesc(st status.Status) (desc string) {
st.IterateDetails(func(d *status.Detail) bool {
if d.ID() == detailAccessDeniedDesc {
desc = string(d.Value())
func ReadAccessDeniedDesc(st *statusgrpc.Status) (desc string) {
st.IterateDetails(func(d *statusgrpc.Status_Detail) bool {
if d.GetId() == detailAccessDeniedDesc {
desc = string(d.GetValue())
return true
}

View file

@ -4,7 +4,7 @@ import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test"
"github.com/stretchr/testify/require"
)
@ -21,15 +21,15 @@ func TestStatusCodes(t *testing.T) {
}
func TestAccessDeniedDesc(t *testing.T) {
var st status.Status
st := new(statusgrpc.Status)
require.Empty(t, object.ReadAccessDeniedDesc(st))
const desc = "some description"
object.WriteAccessDeniedDesc(&st, desc)
object.WriteAccessDeniedDesc(st, desc)
require.Equal(t, desc, object.ReadAccessDeniedDesc(st))
object.WriteAccessDeniedDesc(&st, desc+"1")
object.WriteAccessDeniedDesc(st, desc+"1")
require.Equal(t, desc+"1", object.ReadAccessDeniedDesc(st))
}

View file

@ -1,55 +0,0 @@
package object
import (
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
)
// String returns string representation of Type.
func (t Type) String() string {
return TypeToGRPCField(t).String()
}
// FromString parses Type from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (t *Type) FromString(s string) bool {
var g object.ObjectType
ok := g.FromString(s)
if ok {
*t = TypeFromGRPCField(g)
}
return ok
}
// TypeFromString converts string to Type.
//
// Deprecated: use FromString method.
func TypeFromString(s string) (t Type) {
t.FromString(s)
return
}
// String returns string representation of MatchType.
func (t MatchType) String() string {
return MatchTypeToGRPCField(t).String()
}
// FromString parses MatchType from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (t *MatchType) FromString(s string) bool {
var g object.MatchType
ok := g.FromString(s)
if ok {
*t = MatchTypeFromGRPCField(g)
}
return ok
}

View file

@ -2,8 +2,7 @@ package objecttest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/internal/random"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test"
)
@ -15,7 +14,7 @@ func GenerateShortHeader(empty bool) *object.ShortHeader {
m.SetObjectType(13)
m.SetCreationEpoch(100)
m.SetPayloadLength(12321)
m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetOwnerId(refstest.GenerateOwnerID(false))
}
m.SetVersion(refstest.GenerateVersion(empty))
@ -25,8 +24,8 @@ func GenerateShortHeader(empty bool) *object.ShortHeader {
return m
}
func GenerateAttribute(empty bool) *object.Attribute {
m := new(object.Attribute)
func GenerateAttribute(empty bool) *object.Header_Attribute {
m := new(object.Header_Attribute)
if !empty {
m.SetKey("object key")
@ -36,28 +35,28 @@ func GenerateAttribute(empty bool) *object.Attribute {
return m
}
func GenerateAttributes(empty bool) []object.Attribute {
var res []object.Attribute
func GenerateAttributes(empty bool) []*object.Header_Attribute {
var res []*object.Header_Attribute
if !empty {
res = append(res,
*GenerateAttribute(false),
*GenerateAttribute(false),
GenerateAttribute(false),
GenerateAttribute(false),
)
}
return res
}
func GenerateSplitHeader(empty bool) *object.SplitHeader {
func GenerateSplitHeader(empty bool) *object.Header_Split {
return generateSplitHeader(empty, true)
}
func generateSplitHeader(empty, withPar bool) *object.SplitHeader {
m := new(object.SplitHeader)
func generateSplitHeader(empty, withPar bool) *object.Header_Split {
m := new(object.Header_Split)
if !empty {
m.SetSplitID([]byte{1, 3, 5})
m.SetSplitId([]byte{1, 3, 5})
m.SetParent(refstest.GenerateObjectID(false))
m.SetPrevious(refstest.GenerateObjectID(false))
m.SetChildren(refstest.GenerateObjectIDs(false))
@ -83,8 +82,8 @@ func generateHeader(empty, withSplit bool) *object.Header {
m.SetPayloadLength(777)
m.SetCreationEpoch(432)
m.SetObjectType(111)
m.SetOwnerID(refstest.GenerateOwnerID(false))
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetOwnerId(refstest.GenerateOwnerID(false))
m.SetContainerId(refstest.GenerateContainerID(false))
m.SetAttributes(GenerateAttributes(false))
}
@ -114,7 +113,7 @@ func GenerateObject(empty bool) *object.Object {
if !empty {
m.SetPayload([]byte{7, 8, 9})
m.SetObjectID(refstest.GenerateObjectID(false))
m.SetObjectId(refstest.GenerateObjectID(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
@ -127,7 +126,7 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo {
m := new(object.SplitInfo)
if !empty {
m.SetSplitID([]byte("splitID"))
m.SetSplitId([]byte("splitID"))
m.SetLastPart(refstest.GenerateObjectID(false))
m.SetLink(refstest.GenerateObjectID(false))
}
@ -135,8 +134,8 @@ func GenerateSplitInfo(empty bool) *object.SplitInfo {
return m
}
func GenerateGetRequestBody(empty bool) *object.GetRequestBody {
m := new(object.GetRequestBody)
func GenerateGetRequestBody(empty bool) *object.GetRequest_Body {
m := new(object.GetRequest_Body)
if !empty {
m.SetRaw(true)
@ -154,16 +153,16 @@ func GenerateGetRequest(empty bool) *object.GetRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit {
m := new(object.GetObjectPartInit)
func GenerateGetObjectPartInit(empty bool) *object.GetResponse_Body_Init {
m := new(object.GetResponse_Body_Init)
if !empty {
m.SetObjectID(refstest.GenerateObjectID(false))
m.SetObjectId(refstest.GenerateObjectID(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
@ -172,8 +171,8 @@ func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit {
return m
}
func GenerateGetObjectPartChunk(empty bool) *object.GetObjectPartChunk {
m := new(object.GetObjectPartChunk)
func GenerateGetObjectPartChunk(empty bool) *object.GetResponse_Body_Chunk {
m := new(object.GetResponse_Body_Chunk)
if !empty {
m.SetChunk([]byte("get chunk"))
@ -182,23 +181,48 @@ func GenerateGetObjectPartChunk(empty bool) *object.GetObjectPartChunk {
return m
}
func GenerateGetResponseBody(empty bool) *object.GetResponseBody {
m := new(object.GetResponseBody)
func GenerateGetResponseBody(empty bool) *object.GetResponse_Body {
m := new(object.GetResponse_Body)
if !empty {
switch random.Uint32(3) {
case 0:
m.SetObjectPart(GenerateGetObjectPartInit(false))
m.SetInit(GenerateGetObjectPartInit(false))
case 1:
m.SetObjectPart(GenerateGetObjectPartChunk(false))
m.SetChunk(GenerateGetObjectPartChunk(false))
case 2:
m.SetObjectPart(GenerateSplitInfo(false))
m.SetSplitInfo(GenerateSplitInfo(false))
}
}
return m
}
type GetResponseBodyType uint
const (
InitType GetResponseBodyType = iota
ChunkType
SplitInfoType
)
func GenerateGetResponseBodyWithBodyType(bt GetResponseBodyType) *object.GetResponse_Body {
m := new(object.GetResponse_Body)
switch bt {
case 0:
m.SetInit(GenerateGetObjectPartInit(false))
case 1:
m.SetChunk(GenerateGetObjectPartChunk(false))
case 2:
m.SetSplitInfo(GenerateSplitInfo(false))
default:
panic("undefined body type")
}
return m
}
func GenerateGetResponse(empty bool) *object.GetResponse {
m := new(object.GetResponse)
@ -207,17 +231,17 @@ func GenerateGetResponse(empty bool) *object.GetResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit {
m := new(object.PutObjectPartInit)
func GeneratePutObjectPartInit(empty bool) *object.PutRequest_Body_Init {
m := new(object.PutRequest_Body_Init)
if !empty {
m.SetCopiesNumber([]uint32{234})
m.SetObjectID(refstest.GenerateObjectID(false))
m.SetObjectId(refstest.GenerateObjectID(false))
}
m.SetSignature(refstest.GenerateSignature(empty))
@ -226,8 +250,8 @@ func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit {
return m
}
func GeneratePutObjectPartChunk(empty bool) *object.PutObjectPartChunk {
m := new(object.PutObjectPartChunk)
func GeneratePutObjectPartChunk(empty bool) *object.PutRequest_Body_Chunk {
m := new(object.PutRequest_Body_Chunk)
if !empty {
m.SetChunk([]byte("put chunk"))
@ -236,15 +260,15 @@ func GeneratePutObjectPartChunk(empty bool) *object.PutObjectPartChunk {
return m
}
func GeneratePutRequestBody(empty bool) *object.PutRequestBody {
m := new(object.PutRequestBody)
func GeneratePutRequestBody(empty bool) *object.PutRequest_Body {
m := new(object.PutRequest_Body)
if !empty {
switch random.Uint32(2) {
case 0:
m.SetObjectPart(GeneratePutObjectPartInit(false))
m.SetInit(GeneratePutObjectPartInit(false))
case 1:
m.SetObjectPart(GeneratePutObjectPartChunk(false))
m.SetChunk(GeneratePutObjectPartChunk(false))
}
}
@ -259,16 +283,16 @@ func GeneratePutRequest(empty bool) *object.PutRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GeneratePutResponseBody(empty bool) *object.PutResponseBody {
m := new(object.PutResponseBody)
func GeneratePutResponseBody(empty bool) *object.PutResponse_Body {
m := new(object.PutResponse_Body)
if !empty {
m.SetObjectID(refstest.GenerateObjectID(false))
m.SetObjectId(refstest.GenerateObjectID(false))
}
return m
@ -282,13 +306,13 @@ func GeneratePutResponse(empty bool) *object.PutResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateDeleteRequestBody(empty bool) *object.DeleteRequestBody {
m := new(object.DeleteRequestBody)
func GenerateDeleteRequestBody(empty bool) *object.DeleteRequest_Body {
m := new(object.DeleteRequest_Body)
if !empty {
m.SetAddress(refstest.GenerateAddress(false))
@ -305,13 +329,13 @@ func GenerateDeleteRequest(empty bool) *object.DeleteRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateDeleteResponseBody(empty bool) *object.DeleteResponseBody {
m := new(object.DeleteResponseBody)
func GenerateDeleteResponseBody(empty bool) *object.DeleteResponse_Body {
m := new(object.DeleteResponse_Body)
if !empty {
m.SetTombstone(refstest.GenerateAddress(false))
@ -328,13 +352,13 @@ func GenerateDeleteResponse(empty bool) *object.DeleteResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateHeadRequestBody(empty bool) *object.HeadRequestBody {
m := new(object.HeadRequestBody)
func GenerateHeadRequestBody(empty bool) *object.HeadRequest_Body {
m := new(object.HeadRequest_Body)
if !empty {
m.SetRaw(true)
@ -353,22 +377,22 @@ func GenerateHeadRequest(empty bool) *object.HeadRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateHeadResponseBody(empty bool) *object.HeadResponseBody {
m := new(object.HeadResponseBody)
func GenerateHeadResponseBody(empty bool) *object.HeadResponse_Body {
m := new(object.HeadResponse_Body)
if !empty {
switch random.Uint32(3) {
case 0:
m.SetHeaderPart(GenerateHeaderWithSignature(false))
m.SetHeader(GenerateHeaderWithSignature(false))
case 1:
m.SetHeaderPart(GenerateShortHeader(false))
m.SetShortHeader(GenerateShortHeader(false))
case 2:
m.SetHeaderPart(GenerateSplitInfo(false))
m.SetSplitInfo(GenerateSplitInfo(false))
}
}
@ -383,13 +407,13 @@ func GenerateHeadResponse(empty bool) *object.HeadResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateSearchFilter(empty bool) *object.SearchFilter {
m := new(object.SearchFilter)
func GenerateSearchFilter(empty bool) *object.SearchRequest_Body_Filter {
m := new(object.SearchRequest_Body_Filter)
if !empty {
m.SetKey("search filter key")
@ -400,25 +424,25 @@ func GenerateSearchFilter(empty bool) *object.SearchFilter {
return m
}
func GenerateSearchFilters(empty bool) []object.SearchFilter {
var res []object.SearchFilter
func GenerateSearchFilters(empty bool) []*object.SearchRequest_Body_Filter {
var res []*object.SearchRequest_Body_Filter
if !empty {
res = append(res,
*GenerateSearchFilter(false),
*GenerateSearchFilter(false),
GenerateSearchFilter(false),
GenerateSearchFilter(false),
)
}
return res
}
func GenerateSearchRequestBody(empty bool) *object.SearchRequestBody {
m := new(object.SearchRequestBody)
func GenerateSearchRequestBody(empty bool) *object.SearchRequest_Body {
m := new(object.SearchRequest_Body)
if !empty {
m.SetVersion(555)
m.SetContainerID(refstest.GenerateContainerID(false))
m.SetContainerId(refstest.GenerateContainerID(false))
m.SetFilters(GenerateSearchFilters(false))
}
@ -433,16 +457,16 @@ func GenerateSearchRequest(empty bool) *object.SearchRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateSearchResponseBody(empty bool) *object.SearchResponseBody {
m := new(object.SearchResponseBody)
func GenerateSearchResponseBody(empty bool) *object.SearchResponse_Body {
m := new(object.SearchResponse_Body)
if !empty {
m.SetIDList(refstest.GenerateObjectIDs(false))
m.SetIdList(refstest.GenerateObjectIDs(false))
}
return m
@ -456,7 +480,7 @@ func GenerateSearchResponse(empty bool) *object.SearchResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
@ -472,21 +496,21 @@ func GenerateRange(empty bool) *object.Range {
return m
}
func GenerateRanges(empty bool) []object.Range {
var res []object.Range
func GenerateRanges(empty bool) []*object.Range {
var res []*object.Range
if !empty {
res = append(res,
*GenerateRange(false),
*GenerateRange(false),
GenerateRange(false),
GenerateRange(false),
)
}
return res
}
func GenerateGetRangeRequestBody(empty bool) *object.GetRangeRequestBody {
m := new(object.GetRangeRequestBody)
func GenerateGetRangeRequestBody(empty bool) *object.GetRangeRequest_Body {
m := new(object.GetRangeRequest_Body)
if !empty {
m.SetRaw(true)
@ -505,13 +529,13 @@ func GenerateGetRangeRequest(empty bool) *object.GetRangeRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateGetRangePartChunk(empty bool) *object.GetRangePartChunk {
m := new(object.GetRangePartChunk)
func GenerateGetRangePartChunk(empty bool) *object.GetRangeResponse_Body_Chunk {
m := new(object.GetRangeResponse_Body_Chunk)
if !empty {
m.SetChunk([]byte("get range chunk"))
@ -520,15 +544,15 @@ func GenerateGetRangePartChunk(empty bool) *object.GetRangePartChunk {
return m
}
func GenerateGetRangeResponseBody(empty bool) *object.GetRangeResponseBody {
m := new(object.GetRangeResponseBody)
func GenerateGetRangeResponseBody(empty bool) *object.GetRangeResponse_Body {
m := new(object.GetRangeResponse_Body)
if !empty {
switch random.Uint32(2) {
case 0:
m.SetRangePart(GenerateGetRangePartChunk(false))
m.SetChunk(GenerateGetRangePartChunk(false))
case 1:
m.SetRangePart(GenerateSplitInfo(false))
m.SetSplitInfo(GenerateSplitInfo(false))
}
}
@ -543,13 +567,13 @@ func GenerateGetRangeResponse(empty bool) *object.GetRangeResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateGetRangeHashRequestBody(empty bool) *object.GetRangeHashRequestBody {
m := new(object.GetRangeHashRequestBody)
func GenerateGetRangeHashRequestBody(empty bool) *object.GetRangeHashRequest_Body {
m := new(object.GetRangeHashRequest_Body)
if !empty {
m.SetSalt([]byte("range hash salt"))
@ -569,13 +593,13 @@ func GenerateGetRangeHashRequest(empty bool) *object.GetRangeHashRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponseBody {
m := new(object.GetRangeHashResponseBody)
func GenerateGetRangeHashResponseBody(empty bool) *object.GetRangeHashResponse_Body {
m := new(object.GetRangeHashResponse_Body)
if !empty {
m.SetType(678)
@ -593,20 +617,7 @@ func GenerateGetRangeHashResponse(empty bool) *object.GetRangeHashResponse {
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
func GenerateLock(empty bool) *object.Lock {
m := new(object.Lock)
if !empty {
m.SetMembers([]refs.ObjectID{
*refstest.GenerateObjectID(false),
*refstest.GenerateObjectID(false),
})
}
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}
@ -619,13 +630,13 @@ func GeneratePutSingleRequest(empty bool) *object.PutSingleRequest {
}
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateRequestVerificationHeader(empty))
return m
}
func GeneratePutSingleRequestBody(empty bool) *object.PutSingleRequestBody {
b := new(object.PutSingleRequestBody)
func GeneratePutSingleRequestBody(empty bool) *object.PutSingleRequest_Body {
b := new(object.PutSingleRequest_Body)
if !empty {
b.SetObject(GenerateObject(empty))
b.SetCopiesNumber([]uint32{12345})
@ -636,9 +647,9 @@ func GeneratePutSingleRequestBody(empty bool) *object.PutSingleRequestBody {
func GeneratePutSingleResponse(empty bool) *object.PutSingleResponse {
m := new(object.PutSingleResponse)
if !empty {
m.SetBody(new(object.PutSingleResponseBody))
m.SetBody(new(object.PutSingleResponse_Body))
}
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
m.SetVerifyHeader(sessiontest.GenerateResponseVerificationHeader(empty))
return m
}

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,11 @@
package refs
import (
"math/rand"
"strconv"
"testing"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
func BenchmarkObjectIDSlice(b *testing.B) {
@ -15,37 +17,23 @@ func BenchmarkObjectIDSlice(b *testing.B) {
}
func benchmarkObjectIDSlice(b *testing.B, size int) {
ids := make([]ObjectID, size)
for i := range ids {
ids[i].val = make([]byte, 32)
rand.Read(ids[i].val)
}
raw := ObjectIDListToGRPCMessage(ids)
ids := refstest.GenerateObjectIDs(false)
b.Run("to grpc message", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
raw := ObjectIDListToGRPCMessage(ids)
if len(raw) != len(ids) {
b.FailNow()
}
}
})
b.Run("from grpc message", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ids, err := ObjectIDListFromGRPCMessage(raw)
if err != nil || len(raw) != len(ids) {
b.FailNow()
}
}
})
b.Run("marshal", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
buf := make([]byte, ObjectIDNestedListSize(1, ids))
n := ObjectIDNestedListMarshal(1, buf, ids)
if n != len(buf) {
size := 0
for _, id := range ids {
size += proto.NestedStructureSize(9, id)
}
buf := make([]byte, size)
offset := 0
for _, id := range ids {
offset += proto.NestedStructureMarshal(9, buf[offset:], id)
}
if offset != len(buf) {
b.FailNow()
}
}

View file

@ -1,268 +0,0 @@
package refs
import (
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (o *OwnerID) ToGRPCMessage() grpc.Message {
var m *refs.OwnerID
if o != nil {
m = new(refs.OwnerID)
m.SetValue(o.val)
}
return m
}
func (o *OwnerID) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*refs.OwnerID)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
o.val = v.GetValue()
return nil
}
func (c *ContainerID) ToGRPCMessage() grpc.Message {
var m *refs.ContainerID
if c != nil {
m = new(refs.ContainerID)
m.SetValue(c.val)
}
return m
}
func (c *ContainerID) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*refs.ContainerID)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
c.val = v.GetValue()
return nil
}
func ContainerIDsToGRPCMessage(ids []ContainerID) (res []*refs.ContainerID) {
if ids != nil {
res = make([]*refs.ContainerID, 0, len(ids))
for i := range ids {
res = append(res, ids[i].ToGRPCMessage().(*refs.ContainerID))
}
}
return
}
func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []ContainerID, err error) {
if idsV2 != nil {
res = make([]ContainerID, len(idsV2))
for i := range idsV2 {
if idsV2[i] != nil {
err = res[i].FromGRPCMessage(idsV2[i])
if err != nil {
return
}
}
}
}
return
}
func (o *ObjectID) ToGRPCMessage() grpc.Message {
var m *refs.ObjectID
if o != nil {
m = new(refs.ObjectID)
m.SetValue(o.val)
}
return m
}
func (o *ObjectID) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*refs.ObjectID)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
o.val = v.GetValue()
return nil
}
func ObjectIDListToGRPCMessage(ids []ObjectID) (res []*refs.ObjectID) {
if ids != nil {
res = make([]*refs.ObjectID, 0, len(ids))
for i := range ids {
res = append(res, ids[i].ToGRPCMessage().(*refs.ObjectID))
}
}
return
}
func ObjectIDListFromGRPCMessage(idsV2 []*refs.ObjectID) (res []ObjectID, err error) {
if idsV2 != nil {
res = make([]ObjectID, len(idsV2))
for i := range idsV2 {
if idsV2[i] != nil {
err = res[i].FromGRPCMessage(idsV2[i])
if err != nil {
return
}
}
}
}
return
}
func (a *Address) ToGRPCMessage() grpc.Message {
var m *refs.Address
if a != nil {
m = new(refs.Address)
m.SetContainerId(a.cid.ToGRPCMessage().(*refs.ContainerID))
m.SetObjectId(a.oid.ToGRPCMessage().(*refs.ObjectID))
}
return m
}
func (a *Address) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*refs.Address)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
var err error
cid := v.GetContainerId()
if cid == nil {
a.cid = nil
} else {
if a.cid == nil {
a.cid = new(ContainerID)
}
err = a.cid.FromGRPCMessage(cid)
if err != nil {
return err
}
}
oid := v.GetObjectId()
if oid == nil {
a.oid = nil
} else {
if a.oid == nil {
a.oid = new(ObjectID)
}
err = a.oid.FromGRPCMessage(oid)
}
return err
}
func ChecksumTypeToGRPC(t ChecksumType) refs.ChecksumType {
return refs.ChecksumType(t)
}
func ChecksumTypeFromGRPC(t refs.ChecksumType) ChecksumType {
return ChecksumType(t)
}
func (c *Checksum) ToGRPCMessage() grpc.Message {
var m *refs.Checksum
if c != nil {
m = new(refs.Checksum)
m.SetChecksumType(ChecksumTypeToGRPC(c.typ))
m.SetSum(c.sum)
}
return m
}
func (c *Checksum) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*refs.Checksum)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
c.typ = ChecksumTypeFromGRPC(v.GetType())
c.sum = v.GetSum()
return nil
}
func (v *Version) ToGRPCMessage() grpc.Message {
var m *refs.Version
if v != nil {
m = new(refs.Version)
m.SetMajor(v.major)
m.SetMinor(v.minor)
}
return m
}
func (v *Version) FromGRPCMessage(m grpc.Message) error {
ver, ok := m.(*refs.Version)
if !ok {
return message.NewUnexpectedMessageType(m, v)
}
v.major = ver.GetMajor()
v.minor = ver.GetMinor()
return nil
}
func (s *Signature) ToGRPCMessage() grpc.Message {
var m *refs.Signature
if s != nil {
m = new(refs.Signature)
m.SetKey(s.key)
m.SetSign(s.sign)
m.SetScheme(refs.SignatureScheme(s.scheme))
}
return m
}
func (s *Signature) FromGRPCMessage(m grpc.Message) error {
v, ok := m.(*refs.Signature)
if !ok {
return message.NewUnexpectedMessageType(m, s)
}
s.key = v.GetKey()
s.sign = v.GetSign()
s.scheme = SignatureScheme(v.GetScheme())
return nil
}

View file

@ -95,3 +95,27 @@ func (x *ChecksumType) FromString(s string) bool {
return ok
}
func (s *Signature) ToRFC6979() *SignatureRFC6979 {
var res *SignatureRFC6979
if s != nil {
res = new(SignatureRFC6979)
res.SetKey(s.GetKey())
res.SetSign(s.GetSign())
}
return res
}
func (s *SignatureRFC6979) FromRFC6979() *Signature {
var res *Signature
if s != nil {
res = new(Signature)
res.SetKey(s.GetKey())
res.SetSign(s.GetSign())
}
return res
}

BIN
refs/grpc/types.pb.go generated

Binary file not shown.

BIN
refs/grpc/types_frostfs.pb.go generated Normal file

Binary file not shown.

View file

@ -1,62 +0,0 @@
package refs
import (
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (a *Address) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(a)
}
func (a *Address) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(a, data, new(refs.Address))
}
func (o *ObjectID) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(o)
}
func (o *ObjectID) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(o, data, new(refs.ObjectID))
}
func (c *ContainerID) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(c)
}
func (c *ContainerID) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(c, data, new(refs.ContainerID))
}
func (o *OwnerID) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(o)
}
func (o *OwnerID) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(o, data, new(refs.OwnerID))
}
func (v *Version) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(v)
}
func (v *Version) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(v, data, new(refs.Version))
}
func (s *Signature) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(s)
}
func (s *Signature) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(s, data, new(refs.Signature))
}
func (c *Checksum) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(c)
}
func (c *Checksum) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(c, data, new(refs.Checksum))
}

View file

@ -1,263 +0,0 @@
package refs
import (
"encoding/binary"
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
)
const (
ownerIDValField = 1
containerIDValField = 1
objectIDValField = 1
addressContainerField = 1
addressObjectField = 2
checksumTypeField = 1
checksumValueField = 2
signatureKeyField = 1
signatureValueField = 2
signatureSchemeField = 3
versionMajorField = 1
versionMinorField = 2
)
func (o *OwnerID) StableMarshal(buf []byte) []byte {
if o == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, o.StableSize())
}
proto.BytesMarshal(ownerIDValField, buf, o.val)
return buf
}
func (o *OwnerID) StableSize() int {
if o == nil {
return 0
}
return proto.BytesSize(ownerIDValField, o.val)
}
func (o *OwnerID) Unmarshal(data []byte) error {
return message.Unmarshal(o, data, new(refs.OwnerID))
}
func (c *ContainerID) StableMarshal(buf []byte) []byte {
if c == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, c.StableSize())
}
proto.BytesMarshal(containerIDValField, buf, c.val)
return buf
}
func (c *ContainerID) StableSize() int {
if c == nil {
return 0
}
return proto.BytesSize(containerIDValField, c.val)
}
func (c *ContainerID) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(refs.ContainerID))
}
func (o *ObjectID) StableMarshal(buf []byte) []byte {
if o == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, o.StableSize())
}
proto.BytesMarshal(objectIDValField, buf, o.val)
return buf
}
// ObjectIDNestedListSize returns byte length of nested
// repeated ObjectID field with fNum number.
func ObjectIDNestedListSize(fNum int64, ids []ObjectID) (sz int) {
for i := range ids {
sz += proto.NestedStructureSize(fNum, &ids[i])
}
return
}
func (o *ObjectID) StableSize() int {
if o == nil {
return 0
}
return proto.BytesSize(objectIDValField, o.val)
}
// ObjectIDNestedListMarshal writes protobuf repeated ObjectID field
// with fNum number to buf.
func ObjectIDNestedListMarshal(fNum int64, buf []byte, ids []ObjectID) (off int) {
prefix, _ := proto.NestedStructurePrefix(fNum)
for i := range ids {
off += binary.PutUvarint(buf[off:], prefix)
n := ids[i].StableSize()
off += binary.PutUvarint(buf[off:], uint64(n))
off += proto.BytesMarshal(objectIDValField, buf[off:], ids[i].val)
}
return
}
func (o *ObjectID) Unmarshal(data []byte) error {
return message.Unmarshal(o, data, new(refs.ObjectID))
}
func (a *Address) StableMarshal(buf []byte) []byte {
if a == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, a.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(addressContainerField, buf[offset:], a.cid)
proto.NestedStructureMarshal(addressObjectField, buf[offset:], a.oid)
return buf
}
func (a *Address) StableSize() (size int) {
if a == nil {
return 0
}
size += proto.NestedStructureSize(addressContainerField, a.cid)
size += proto.NestedStructureSize(addressObjectField, a.oid)
return size
}
func (a *Address) Unmarshal(data []byte) error {
return message.Unmarshal(a, data, new(refs.Address))
}
func (c *Checksum) StableMarshal(buf []byte) []byte {
if c == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, c.StableSize())
}
var offset int
offset += proto.EnumMarshal(checksumTypeField, buf[offset:], int32(c.typ))
proto.BytesMarshal(checksumValueField, buf[offset:], c.sum)
return buf
}
func (c *Checksum) StableSize() (size int) {
if c == nil {
return 0
}
size += proto.EnumSize(checksumTypeField, int32(c.typ))
size += proto.BytesSize(checksumValueField, c.sum)
return size
}
func (c *Checksum) Unmarshal(data []byte) error {
return message.Unmarshal(c, data, new(refs.Checksum))
}
func (s *Signature) StableMarshal(buf []byte) []byte {
if s == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, s.StableSize())
}
var offset int
offset += proto.BytesMarshal(signatureKeyField, buf[offset:], s.key)
offset += proto.BytesMarshal(signatureValueField, buf[offset:], s.sign)
proto.EnumMarshal(signatureSchemeField, buf[offset:], int32(s.scheme))
return buf
}
func (s *Signature) StableSize() (size int) {
if s == nil {
return 0
}
size += proto.BytesSize(signatureKeyField, s.key)
size += proto.BytesSize(signatureValueField, s.sign)
size += proto.EnumSize(signatureSchemeField, int32(s.scheme))
return size
}
func (s *Signature) Unmarshal(data []byte) error {
return message.Unmarshal(s, data, new(refs.Signature))
}
func (v *Version) StableMarshal(buf []byte) []byte {
if v == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, v.StableSize())
}
var offset int
offset += proto.UInt32Marshal(versionMajorField, buf[offset:], v.major)
proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor)
return buf
}
func (v *Version) StableSize() (size int) {
if v == nil {
return 0
}
size += proto.UInt32Size(versionMajorField, v.major)
size += proto.UInt32Size(versionMinorField, v.minor)
return size
}
func (v *Version) Unmarshal(data []byte) error {
return message.Unmarshal(v, data, new(refs.Version))
}

View file

@ -4,18 +4,18 @@ import (
"testing"
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test"
"google.golang.org/protobuf/proto"
)
func TestMessageConvert(t *testing.T) {
messagetest.TestRPCMessage(t,
func(empty bool) message.Message { return refstest.GenerateOwnerID(empty) },
func(empty bool) message.Message { return refstest.GenerateObjectID(empty) },
func(empty bool) message.Message { return refstest.GenerateContainerID(empty) },
func(empty bool) message.Message { return refstest.GenerateAddress(empty) },
func(empty bool) message.Message { return refstest.GenerateChecksum(empty) },
func(empty bool) message.Message { return refstest.GenerateSignature(empty) },
func(empty bool) message.Message { return refstest.GenerateVersion(empty) },
func(empty bool) proto.Message { return refstest.GenerateOwnerID(empty) },
func(empty bool) proto.Message { return refstest.GenerateObjectID(empty) },
func(empty bool) proto.Message { return refstest.GenerateContainerID(empty) },
func(empty bool) proto.Message { return refstest.GenerateAddress(empty) },
func(empty bool) proto.Message { return refstest.GenerateChecksum(empty) },
func(empty bool) proto.Message { return refstest.GenerateSignature(empty) },
func(empty bool) proto.Message { return refstest.GenerateVersion(empty) },
)
}

View file

@ -1,47 +0,0 @@
package refs
import (
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
)
// String returns string representation of ChecksumType.
func (t ChecksumType) String() string {
return ChecksumTypeToGRPC(t).String()
}
// FromString parses ChecksumType from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (t *ChecksumType) FromString(s string) bool {
var g refs.ChecksumType
ok := g.FromString(s)
if ok {
*t = ChecksumTypeFromGRPC(g)
}
return ok
}
// String returns string representation of SignatureScheme.
func (t SignatureScheme) String() string {
return refs.SignatureScheme(t).String()
}
// FromString parses SignatureScheme from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (t *SignatureScheme) FromString(s string) bool {
var g refs.SignatureScheme
ok := g.FromString(s)
if ok {
*t = SignatureScheme(g)
}
return ok
}

View file

@ -3,7 +3,7 @@ package refstest
import (
"math/rand"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
refs "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc"
)
func GenerateVersion(empty bool) *refs.Version {
@ -31,8 +31,8 @@ func GenerateAddress(empty bool) *refs.Address {
m := new(refs.Address)
if !empty {
m.SetObjectID(GenerateObjectID(false))
m.SetContainerID(GenerateContainerID(false))
m.SetObjectId(GenerateObjectID(false))
m.SetContainerId(GenerateContainerID(false))
}
return m
@ -48,13 +48,13 @@ func GenerateObjectID(empty bool) *refs.ObjectID {
return m
}
func GenerateObjectIDs(empty bool) []refs.ObjectID {
var ids []refs.ObjectID
func GenerateObjectIDs(empty bool) []*refs.ObjectID {
var ids []*refs.ObjectID
if !empty {
ids = append(ids,
*GenerateObjectID(false),
*GenerateObjectID(false),
GenerateObjectID(false),
GenerateObjectID(false),
)
}
@ -71,13 +71,13 @@ func GenerateContainerID(empty bool) *refs.ContainerID {
return m
}
func GenerateContainerIDs(empty bool) []refs.ContainerID {
var res []refs.ContainerID
func GenerateContainerIDs(empty bool) []*refs.ContainerID {
var res []*refs.ContainerID
if !empty {
res = append(res,
*GenerateContainerID(false),
*GenerateContainerID(false),
GenerateContainerID(false),
GenerateContainerID(false),
)
}
@ -96,11 +96,22 @@ func GenerateSignature(empty bool) *refs.Signature {
return m
}
func GenerateSignatureRFC6979(empty bool) *refs.SignatureRFC6979 {
m := new(refs.SignatureRFC6979)
if !empty {
m.SetKey([]byte{1})
m.SetSign([]byte{2})
}
return m
}
func GenerateChecksum(empty bool) *refs.Checksum {
m := new(refs.Checksum)
if !empty {
m.SetType(1)
m.SetChecksumType(1)
m.SetSum([]byte{1, 2, 3})
}

View file

@ -1,194 +0,0 @@
package refs
type OwnerID struct {
val []byte
}
type ContainerID struct {
val []byte
}
type ObjectID struct {
val []byte
}
type Address struct {
cid *ContainerID
oid *ObjectID
}
type Checksum struct {
typ ChecksumType
sum []byte
}
type ChecksumType uint32
type SignatureScheme uint32
//nolint:revive
const (
ECDSA_SHA512 SignatureScheme = iota
ECDSA_RFC6979_SHA256
ECDSA_RFC6979_SHA256_WALLET_CONNECT
)
type Signature struct {
key, sign []byte
scheme SignatureScheme
}
type Version struct {
major, minor uint32
}
const (
UnknownChecksum ChecksumType = iota
TillichZemor
SHA256
)
func (o *OwnerID) GetValue() []byte {
if o != nil {
return o.val
}
return nil
}
func (o *OwnerID) SetValue(v []byte) {
o.val = v
}
func (c *ContainerID) GetValue() []byte {
if c != nil {
return c.val
}
return nil
}
func (c *ContainerID) SetValue(v []byte) {
c.val = v
}
func (o *ObjectID) GetValue() []byte {
if o != nil {
return o.val
}
return nil
}
func (o *ObjectID) SetValue(v []byte) {
o.val = v
}
func (a *Address) GetContainerID() *ContainerID {
if a != nil {
return a.cid
}
return nil
}
func (a *Address) SetContainerID(v *ContainerID) {
a.cid = v
}
func (a *Address) GetObjectID() *ObjectID {
if a != nil {
return a.oid
}
return nil
}
func (a *Address) SetObjectID(v *ObjectID) {
a.oid = v
}
func (c *Checksum) GetType() ChecksumType {
if c != nil {
return c.typ
}
return UnknownChecksum
}
func (c *Checksum) SetType(v ChecksumType) {
c.typ = v
}
func (c *Checksum) GetSum() []byte {
if c != nil {
return c.sum
}
return nil
}
func (c *Checksum) SetSum(v []byte) {
c.sum = v
}
func (s *Signature) GetKey() []byte {
if s != nil {
return s.key
}
return nil
}
func (s *Signature) SetKey(v []byte) {
s.key = v
}
func (s *Signature) GetSign() []byte {
if s != nil {
return s.sign
}
return nil
}
func (s *Signature) SetSign(v []byte) {
s.sign = v
}
func (s *Signature) GetScheme() SignatureScheme {
if s != nil {
return s.scheme
}
return 0
}
func (s *Signature) SetScheme(scheme SignatureScheme) {
s.scheme = scheme
}
func (v *Version) GetMajor() uint32 {
if v != nil {
return v.major
}
return 0
}
func (v *Version) SetMajor(val uint32) {
v.major = val
}
func (v *Version) GetMinor() uint32 {
if v != nil {
return v.minor
}
return 0
}
func (v *Version) SetMinor(val uint32) {
v.minor = val
}

View file

@ -1,7 +1,7 @@
package rpc
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting"
accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
)

View file

@ -6,12 +6,12 @@ import (
"sync"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"google.golang.org/protobuf/proto"
)
// SendUnary initializes communication session by RPC info, performs unary RPC
// and closes the session.
func SendUnary(cli *Client, info common.CallMethodInfo, req, resp message.Message, opts ...CallOption) error {
func SendUnary(cli *Client, info common.CallMethodInfo, req, resp proto.Message, opts ...CallOption) error {
rw, err := cli.Init(info, opts...)
if err != nil {
return err
@ -40,7 +40,7 @@ type MessageWriterCloser interface {
type clientStreamWriterCloser struct {
MessageReadWriter
resp message.Message
resp proto.Message
}
func (c *clientStreamWriterCloser) Close() error {
@ -56,7 +56,7 @@ func (c *clientStreamWriterCloser) Close() error {
// and returns its interface.
//
// All stream writes must be performed before the closing. Close must be called once.
func OpenClientStream(cli *Client, info common.CallMethodInfo, resp message.Message, opts ...CallOption) (MessageWriterCloser, error) {
func OpenClientStream(cli *Client, info common.CallMethodInfo, resp proto.Message, opts ...CallOption) (MessageWriterCloser, error) {
rw, err := cli.Init(info, opts...)
if err != nil {
return nil, err
@ -80,10 +80,10 @@ type serverStreamReaderCloser struct {
once sync.Once
req message.Message
req proto.Message
}
func (s *serverStreamReaderCloser) ReadMessage(msg message.Message) error {
func (s *serverStreamReaderCloser) ReadMessage(msg proto.Message) error {
var err error
s.once.Do(func() {
@ -111,7 +111,7 @@ func (s *serverStreamReaderCloser) ReadMessage(msg message.Message) error {
// and returns its interface.
//
// All stream reads must be performed before the closing. Close must be called once.
func OpenServerStream(cli *Client, info common.CallMethodInfo, req message.Message, opts ...CallOption) (MessageReader, error) {
func OpenServerStream(cli *Client, info common.CallMethodInfo, req proto.Message, opts ...CallOption) (MessageReader, error) {
rw, err := cli.Init(info, opts...)
if err != nil {
return nil, err

View file

@ -5,8 +5,8 @@ import (
"io"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
// MessageReader is an interface of the Message reader.
@ -15,7 +15,7 @@ type MessageReader interface {
//
// Returns io.EOF if there are no more messages to read.
// ReadMessage should not be called after io.EOF occasion.
ReadMessage(message.Message) error
ReadMessage(proto.Message) error
}
// MessageWriter is an interface of the Message writer.
@ -23,7 +23,7 @@ type MessageWriter interface {
// WriteMessage writers the next Message.
//
// WriteMessage should not be called after any error.
WriteMessage(message.Message) error
WriteMessage(proto.Message) error
}
// MessageReadWriter is a component interface

View file

@ -4,8 +4,8 @@ import (
"context"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
)
type streamWrapper struct {
@ -14,23 +14,15 @@ type streamWrapper struct {
cancel context.CancelFunc
}
func (w streamWrapper) ReadMessage(m message.Message) error {
// Can be optimized: we can create blank message here.
gm := m.ToGRPCMessage()
err := w.withTimeout(func() error {
return w.ClientStream.RecvMsg(gm)
func (w streamWrapper) ReadMessage(m proto.Message) error {
return w.withTimeout(func() error {
return w.ClientStream.RecvMsg(m)
})
if err != nil {
return err
}
return m.FromGRPCMessage(gm)
}
func (w streamWrapper) WriteMessage(m message.Message) error {
func (w streamWrapper) WriteMessage(m proto.Message) error {
return w.withTimeout(func() error {
return w.ClientStream.SendMsg(m.ToGRPCMessage())
return w.ClientStream.SendMsg(m)
})
}

View file

@ -1,7 +1,7 @@
package rpc
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
)

View file

@ -1,65 +1,44 @@
package messagetest
import (
"encoding/json"
"errors"
"fmt"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
utilproto "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
type jsonMessage interface {
json.Marshaler
json.Unmarshaler
}
type binaryMessage interface {
StableMarshal([]byte) []byte
Unmarshal([]byte) error
}
func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) message.Message) {
func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) proto.Message) {
for _, msgGen := range msgGens {
msg := msgGen(false)
t.Run(fmt.Sprintf("convert_%T", msg), func(t *testing.T) {
msg := msgGen(false)
err := msg.FromGRPCMessage(100)
require.True(t, errors.As(err, new(message.ErrUnexpectedMessageType)))
msg2 := msgGen(true)
err = msg2.FromGRPCMessage(msg.ToGRPCMessage())
require.NoError(t, err)
require.Equal(t, msg, msg2)
})
msg1 := msgGen(false)
t.Run("encoding", func(t *testing.T) {
if jm, ok := msg.(jsonMessage); ok {
t.Run(fmt.Sprintf("JSON_%T", msg), func(t *testing.T) {
data, err := jm.MarshalJSON()
require.NoError(t, err)
t.Run(fmt.Sprintf("JSON_%T", msg1), func(t *testing.T) {
data, err := protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
msg1,
)
require.NoError(t, err)
jm2 := msgGen(true).(jsonMessage)
require.NoError(t, jm2.UnmarshalJSON(data))
msg2 := msgGen(true)
require.NoError(t, protojson.Unmarshal(data, msg2))
require.Equal(t, jm, jm2)
})
}
require.True(t, proto.Equal(msg1, msg2))
})
if bm, ok := msg.(binaryMessage); ok {
t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) {
if bm, ok := msg1.(utilproto.StableMarshaller); ok {
t.Run(fmt.Sprintf("Stable_%T", msg1), func(t *testing.T) {
data := bm.StableMarshal(nil)
bm2 := msgGen(true).(binaryMessage)
require.NoError(t, bm2.Unmarshal(data))
require.Len(t, data, bm.StableSize())
require.Equal(t, bm, bm2)
msg2 := msgGen(true)
require.NoError(t, proto.Unmarshal(data, msg2))
require.True(t, proto.Equal(msg1, msg2))
})
}
})

View file

@ -1,7 +1,7 @@
package rpc
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
)
@ -49,10 +49,10 @@ func NetworkInfo(
// NetMapSnapshot executes NetmapService.NetmapSnapshot RPC.
func NetMapSnapshot(
cli *client.Client,
req *netmap.SnapshotRequest,
req *netmap.NetmapSnapshotRequest,
opts ...client.CallOption,
) (*netmap.SnapshotResponse, error) {
resp := new(netmap.SnapshotResponse)
) (*netmap.NetmapSnapshotResponse, error) {
resp := new(netmap.NetmapSnapshotResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceNetmap, rpcNetmapSnapshot), req, resp, opts...)
if err != nil {

View file

@ -1,10 +1,10 @@
package rpc
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
object "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
"google.golang.org/protobuf/proto"
)
const serviceObject = serviceNamePrefix + "object.ObjectService"
@ -25,7 +25,7 @@ const (
type PutRequestWriter struct {
wc client.MessageWriterCloser
resp message.Message
resp proto.Message
}
// Write writes req to the stream.

View file

@ -3,7 +3,7 @@ package rpc
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
)
const serviceSession = serviceNamePrefix + "session.SessionService"

Some files were not shown because too many files have changed in this diff Show more