diff --git a/api/accounting/encoding.go b/api/accounting/encoding.go new file mode 100644 index 00000000..e12cd396 --- /dev/null +++ b/api/accounting/encoding.go @@ -0,0 +1,82 @@ +package accounting + +import ( + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +const ( + _ = iota + fieldDecimalValue + fieldDecimalPrecision +) + +// MarshaledSize returns size of the Decimal in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Decimal) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldDecimalValue, x.Value) + + proto.SizeVarint(fieldDecimalPrecision, x.Precision) + } + return sz +} + +// MarshalStable writes the Decimal in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Decimal.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Decimal) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldDecimalValue, x.Value) + proto.MarshalToVarint(b[off:], fieldDecimalPrecision, x.Precision) + } +} + +const ( + _ = iota + fieldBalanceReqOwner +) + +// MarshaledSize returns size of the BalanceRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *BalanceRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldBalanceReqOwner, x.OwnerId) + } + return sz +} + +// MarshalStable writes the BalanceRequest_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [BalanceRequest_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *BalanceRequest_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldBalanceReqOwner, x.OwnerId) + } +} + +const ( + _ = iota + fieldBalanceRespBalance +) + +// MarshaledSize returns size of the BalanceResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *BalanceResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldBalanceRespBalance, x.Balance) + } + return sz +} + +// MarshalStable writes the BalanceResponse_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [BalanceResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *BalanceResponse_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldBalanceRespBalance, x.Balance) + } +} diff --git a/api/accounting/encoding_test.go b/api/accounting/encoding_test.go new file mode 100644 index 00000000..e361fe64 --- /dev/null +++ b/api/accounting/encoding_test.go @@ -0,0 +1,54 @@ +package accounting_test + +import ( + "testing" + + "github.com/nspcc-dev/neofs-sdk-go/api/accounting" + apitest "github.com/nspcc-dev/neofs-sdk-go/api/internal/test" + "github.com/nspcc-dev/neofs-sdk-go/api/refs" + "github.com/stretchr/testify/require" +) + +func assertEqualDecimals(t testing.TB, v1, v2 *accounting.Decimal, msg string) { + require.Equal(t, v1.GetValue(), v2.GetValue(), msg) + require.Equal(t, v1.GetPrecision(), v2.GetPrecision(), msg) +} + +func TestDecimal_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, assertEqualDecimals, []*accounting.Decimal{ + nil, + new(accounting.Decimal), + { + Value: apitest.RandomInteger[int64](), + Precision: apitest.RandomInteger[uint32](), + }, + }) +} + +func assertEqualBalanceRequestBodies(t testing.TB, v1, v2 *accounting.BalanceRequest_Body, msg string) { + apitest.AssertEqualOwnerIDs(t, v1.OwnerId, v2.OwnerId, msg) +} + +func TestBalanceRequest_Body_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, assertEqualBalanceRequestBodies, []*accounting.BalanceRequest_Body{ + nil, + new(accounting.BalanceRequest_Body), + {OwnerId: new(refs.OwnerID)}, + }) +} + +func assertEqualBalanceResponseBodies(t testing.TB, v1, v2 *accounting.BalanceResponse_Body, msg string) { + assertEqualDecimals(t, v1.Balance, v2.Balance, msg) +} + +func TestBalanceResponse_Body_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, assertEqualBalanceResponseBodies, []*accounting.BalanceResponse_Body{ + nil, + new(accounting.BalanceResponse_Body), + {Balance: new(accounting.Decimal)}, + {Balance: &accounting.Decimal{ + Value: apitest.RandomInteger[int64](), + Precision: apitest.RandomInteger[uint32](), + }}, + }) +} diff --git a/api/acl/encoding.go b/api/acl/encoding.go new file mode 100644 index 00000000..4750f30a --- /dev/null +++ b/api/acl/encoding.go @@ -0,0 +1,233 @@ +package acl + +import ( + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +const ( + _ = iota + fieldEACLVersion + fieldEACLContainer + fieldEACLRecords +) + +// MarshaledSize returns size of the EACLTable in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *EACLTable) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldEACLVersion, x.Version) + + proto.SizeEmbedded(fieldEACLContainer, x.ContainerId) + for i := range x.Records { + sz += proto.SizeEmbedded(fieldEACLRecords, x.Records[i]) + } + } + return sz +} + +// MarshalStable writes the EACLTable in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [EACLTable.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *EACLTable) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldEACLVersion, x.Version) + off += proto.MarshalToEmbedded(b[off:], fieldEACLContainer, x.ContainerId) + for i := range x.Records { + off += proto.MarshalToEmbedded(b[off:], fieldEACLRecords, x.Records[i]) + } + } +} + +const ( + _ = iota + fieldEACLOp + fieldEACLAction + fieldEACLFilters + fieldEACLTargets +) + +// MarshaledSize returns size of the EACLRecord in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *EACLRecord) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldEACLOp, int32(x.Operation)) + + proto.SizeVarint(fieldEACLAction, int32(x.Action)) + for i := range x.Filters { + sz += proto.SizeEmbedded(fieldEACLFilters, x.Filters[i]) + } + for i := range x.Targets { + sz += proto.SizeEmbedded(fieldEACLTargets, x.Targets[i]) + } + } + return sz +} + +// MarshalStable writes the EACLRecord in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [EACLRecord.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *EACLRecord) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldEACLOp, int32(x.Operation)) + off += proto.MarshalToVarint(b[off:], fieldEACLAction, int32(x.Action)) + for i := range x.Filters { + off += proto.MarshalToEmbedded(b[off:], fieldEACLFilters, x.Filters[i]) + } + for i := range x.Targets { + off += proto.MarshalToEmbedded(b[off:], fieldEACLTargets, x.Targets[i]) + } + } +} + +const ( + _ = iota + fieldEACLHeader + fieldEACLMatcher + fieldEACLKey + fieldEACLValue +) + +// MarshaledSize returns size of the EACLRecord_Filter in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *EACLRecord_Filter) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldEACLHeader, int32(x.HeaderType)) + + proto.SizeVarint(fieldEACLMatcher, int32(x.MatchType)) + + proto.SizeBytes(fieldEACLKey, x.Key) + + proto.SizeBytes(fieldEACLValue, x.Value) + } + return sz +} + +// MarshalStable writes the EACLRecord_Filter in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [EACLRecord_Filter.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *EACLRecord_Filter) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldEACLHeader, int32(x.HeaderType)) + off += proto.MarshalToVarint(b[off:], fieldEACLMatcher, int32(x.MatchType)) + off += proto.MarshalToBytes(b[off:], fieldEACLKey, x.Key) + proto.MarshalToBytes(b[off:], fieldEACLValue, x.Value) + } +} + +const ( + _ = iota + fieldEACLRole + fieldEACLTargetKeys +) + +// MarshaledSize returns size of the EACLRecord_Target in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *EACLRecord_Target) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldEACLRole, int32(x.Role)) + + proto.SizeRepeatedBytes(fieldEACLTargetKeys, x.Keys) + } + return sz +} + +// MarshalStable writes the EACLRecord_Target in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [EACLRecord_Target.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *EACLRecord_Target) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldEACLRole, int32(x.Role)) + proto.MarshalToRepeatedBytes(b[off:], fieldEACLTargetKeys, x.Keys) + } +} + +const ( + _ = iota + fieldBearerExp + fieldBearerNbf + fieldBearerIat +) + +// MarshaledSize returns size of the BearerToken_Body_TokenLifetime in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *BearerToken_Body_TokenLifetime) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldBearerExp, x.Exp) + + proto.SizeVarint(fieldBearerNbf, x.Nbf) + + proto.SizeVarint(fieldBearerIat, x.Iat) + } + return sz +} + +// MarshalStable writes the BearerToken_Body_TokenLifetime in Protocol Buffers +// V3 format with ascending order of fields by number into b. MarshalStable uses +// exactly [BearerToken_Body_TokenLifetime.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *BearerToken_Body_TokenLifetime) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldBearerExp, x.Exp) + off += proto.MarshalToVarint(b[off:], fieldBearerNbf, x.Nbf) + proto.MarshalToVarint(b[off:], fieldBearerIat, x.Iat) + } +} + +const ( + _ = iota + fieldBearerEACL + fieldBearerOwner + fieldBearerLifetime + fieldBearerIssuer +) + +// MarshaledSize returns size of the BearerToken_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *BearerToken_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldBearerEACL, x.EaclTable) + + proto.SizeEmbedded(fieldBearerOwner, x.OwnerId) + + proto.SizeEmbedded(fieldBearerLifetime, x.Lifetime) + + proto.SizeEmbedded(fieldBearerIssuer, x.Issuer) + } + return sz +} + +// MarshalStable writes the BearerToken_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [BearerToken_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *BearerToken_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldBearerEACL, x.EaclTable) + off += proto.MarshalToEmbedded(b[off:], fieldBearerOwner, x.OwnerId) + off += proto.MarshalToEmbedded(b[off:], fieldBearerLifetime, x.Lifetime) + proto.MarshalToEmbedded(b[off:], fieldBearerIssuer, x.Issuer) + } +} + +const ( + _ = iota + fieldBearerBody + fieldBearerSignature +) + +// MarshaledSize returns size of the BearerToken in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *BearerToken) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldBearerBody, x.Body) + + proto.SizeEmbedded(fieldBearerSignature, x.Signature) + } + return sz +} + +// MarshalStable writes the BearerToken in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [BearerToken.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *BearerToken) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldBearerBody, x.Body) + proto.MarshalToEmbedded(b[off:], fieldBearerSignature, x.Signature) + } +} diff --git a/api/acl/encoding_test.go b/api/acl/encoding_test.go new file mode 100644 index 00000000..8a28a543 --- /dev/null +++ b/api/acl/encoding_test.go @@ -0,0 +1,3 @@ +package acl_test + +// TODO diff --git a/api/audit/encoding.go b/api/audit/encoding.go new file mode 100644 index 00000000..4cefa41f --- /dev/null +++ b/api/audit/encoding.go @@ -0,0 +1,74 @@ +package audit + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldResultVersion + fieldResultEpoch + fieldResultContainer + fieldResultPubKey + fieldResultCompleted + fieldResultRequests + fieldResultRetries + fieldResultPassedSG + fieldResultFailedSG + fieldResultHits + fieldResultMisses + fieldResultFailures + fieldResultPassedNodes + fieldResultFailedNodes +) + +// MarshaledSize returns size of the DataAuditResult in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *DataAuditResult) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldResultVersion, x.Version) + sz += proto.SizeFixed64(fieldResultEpoch, x.AuditEpoch) + sz += proto.SizeEmbedded(fieldResultContainer, x.ContainerId) + sz += proto.SizeBytes(fieldResultPubKey, x.PublicKey) + sz += proto.SizeBool(fieldResultCompleted, x.Complete) + sz += proto.SizeVarint(fieldResultRequests, x.Requests) + sz += proto.SizeVarint(fieldResultRetries, x.Retries) + sz += proto.SizeVarint(fieldResultHits, x.Hit) + sz += proto.SizeVarint(fieldResultMisses, x.Miss) + sz += proto.SizeVarint(fieldResultFailures, x.Fail) + sz += proto.SizeRepeatedBytes(fieldResultPassedNodes, x.PassNodes) + sz += proto.SizeRepeatedBytes(fieldResultFailedNodes, x.FailNodes) + for i := range x.PassSg { + sz += proto.SizeEmbedded(fieldResultPassedSG, x.PassSg[i]) + } + for i := range x.FailSg { + sz += proto.SizeEmbedded(fieldResultFailedSG, x.FailSg[i]) + } + } + return sz +} + +// MarshalStable writes the DataAuditResult in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [DataAuditResult.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *DataAuditResult) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldResultVersion, x.Version) + off += proto.MarshalToFixed64(b[off:], fieldResultEpoch, x.AuditEpoch) + off += proto.MarshalToEmbedded(b[off:], fieldResultContainer, x.ContainerId) + off += proto.MarshalToBytes(b[off:], fieldResultPubKey, x.PublicKey) + off += proto.MarshalToBool(b[off:], fieldResultCompleted, x.Complete) + off += proto.MarshalToVarint(b[off:], fieldResultRequests, x.Requests) + off += proto.MarshalToVarint(b[off:], fieldResultRetries, x.Retries) + for i := range x.PassSg { + off += proto.MarshalToEmbedded(b[off:], fieldResultPassedSG, x.PassSg[i]) + } + for i := range x.FailSg { + off += proto.MarshalToEmbedded(b[off:], fieldResultFailedSG, x.FailSg[i]) + } + off += proto.MarshalToVarint(b[off:], fieldResultHits, x.Hit) + off += proto.MarshalToVarint(b[off:], fieldResultMisses, x.Miss) + off += proto.MarshalToVarint(b[off:], fieldResultFailures, x.Fail) + off += proto.MarshalToRepeatedBytes(b[off:], fieldResultPassedNodes, x.PassNodes) + proto.MarshalToRepeatedBytes(b[off:], fieldResultFailedNodes, x.FailNodes) + } +} diff --git a/api/audit/encoding_test.go b/api/audit/encoding_test.go new file mode 100644 index 00000000..f6ff1967 --- /dev/null +++ b/api/audit/encoding_test.go @@ -0,0 +1,3 @@ +package audit_test + +// TODO diff --git a/api/container/encoding.go b/api/container/encoding.go new file mode 100644 index 00000000..a9abd01b --- /dev/null +++ b/api/container/encoding.go @@ -0,0 +1,437 @@ +package container + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldContainerAttrKey + fieldContainerAttrVal +) + +// MarshaledSize returns size of the Container_Attribute in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *Container_Attribute) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldContainerAttrKey, x.Key) + + proto.SizeBytes(fieldContainerAttrVal, x.Value) + } + return sz +} + +// MarshalStable writes the Container_Attribute in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [Container_Attribute.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *Container_Attribute) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldContainerAttrKey, x.Key) + proto.MarshalToBytes(b[off:], fieldContainerAttrVal, x.Value) + } +} + +const ( + _ = iota + fieldContainerVersion + fieldContainerOwner + fieldContainerNonce + fieldContainerBasicACL + fieldContainerAttributes + fieldContainerPolicy +) + +// MarshaledSize returns size of the Container in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Container) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldContainerVersion, x.Version) + + proto.SizeEmbedded(fieldContainerOwner, x.OwnerId) + + proto.SizeBytes(fieldContainerNonce, x.Nonce) + + proto.SizeVarint(fieldContainerBasicACL, x.BasicAcl) + + proto.SizeEmbedded(fieldContainerPolicy, x.PlacementPolicy) + for i := range x.Attributes { + sz += proto.SizeEmbedded(fieldContainerAttributes, x.Attributes[i]) + } + } + return sz +} + +// MarshalStable writes the Container in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Container.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Container) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldContainerVersion, x.Version) + off += proto.MarshalToEmbedded(b[off:], fieldContainerOwner, x.OwnerId) + off += proto.MarshalToBytes(b[off:], fieldContainerNonce, x.Nonce) + off += proto.MarshalToVarint(b[off:], fieldContainerBasicACL, x.BasicAcl) + for i := range x.Attributes { + off += proto.MarshalToEmbedded(b[off:], fieldContainerAttributes, x.Attributes[i]) + } + proto.MarshalToEmbedded(b[off:], fieldContainerPolicy, x.PlacementPolicy) + } +} + +const ( + _ = iota + fieldPutReqContainer + fieldPutReqSignature +) + +// MarshaledSize returns size of the PutRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *PutRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldPutReqContainer, x.Container) + + proto.SizeEmbedded(fieldPutReqSignature, x.Signature) + } + return sz +} + +// MarshalStable writes the PutRequest_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [PutRequest_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *PutRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldPutReqContainer, x.Container) + proto.MarshalToEmbedded(b[off:], fieldPutReqSignature, x.Signature) + } +} + +const ( + _ = iota + fieldPutRespID +) + +// MarshaledSize returns size of the PutResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *PutResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldPutRespID, x.ContainerId) + } + return sz +} + +// MarshalStable writes the PutResponse_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [PutResponse_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *PutResponse_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldPutRespID, x.ContainerId) + } +} + +const ( + _ = iota + fieldDeleteReqContainer + fieldDeleteReqSignature +) + +// MarshaledSize returns size of the DeleteRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *DeleteRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldDeleteReqContainer, x.ContainerId) + + proto.SizeEmbedded(fieldDeleteReqSignature, x.Signature) + } + return sz +} + +// MarshalStable writes the DeleteRequest_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [DeleteRequest_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *DeleteRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldDeleteReqContainer, x.ContainerId) + proto.MarshalToEmbedded(b[off:], fieldDeleteReqSignature, x.Signature) + } +} + +// MarshaledSize returns size of the DeleteResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *DeleteResponse_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the DeleteResponse_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [DeleteResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *DeleteResponse_Body) MarshalStable([]byte) {} + +const ( + _ = iota + fieldGetReqContainer +) + +// MarshaledSize returns size of the GetRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *GetRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldGetReqContainer, x.ContainerId) + } + return sz +} + +// MarshalStable writes the GetRequest_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [GetRequest_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *GetRequest_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldGetReqContainer, x.ContainerId) + } +} + +const ( + _ = iota + fieldGetRespContainer + fieldGetRespSignature + fieldGetRespSession +) + +// MarshaledSize returns size of the GetResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *GetResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldGetRespContainer, x.Container) + + proto.SizeEmbedded(fieldGetRespSignature, x.Signature) + + proto.SizeEmbedded(fieldGetRespSession, x.SessionToken) + } + return sz +} + +// MarshalStable writes the GetResponse_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [GetResponse_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *GetResponse_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldGetRespContainer, x.Container) + off += proto.MarshalToEmbedded(b[off:], fieldGetRespSignature, x.Signature) + proto.MarshalToEmbedded(b[off:], fieldGetRespSession, x.SessionToken) + } +} + +const ( + _ = iota + fieldListReqOwner +) + +// MarshaledSize returns size of the ListRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *ListRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldListReqOwner, x.OwnerId) + } + return sz +} + +// MarshalStable writes the ListRequest_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [ListRequest_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *ListRequest_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldListReqOwner, x.OwnerId) + } +} + +const ( + _ = iota + fieldListRespIDs +) + +// MarshaledSize returns size of the ListResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *ListResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + for i := range x.ContainerIds { + sz += proto.SizeEmbedded(fieldListRespIDs, x.ContainerIds[i]) + } + } + return sz +} + +// MarshalStable writes the ListResponse_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [ListResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *ListResponse_Body) MarshalStable(b []byte) { + if x != nil { + var off int + for i := range x.ContainerIds { + off += proto.MarshalToEmbedded(b[off:], fieldListRespIDs, x.ContainerIds[i]) + } + } +} + +const ( + _ = iota + fieldSetEACLReqTable + fieldSetEACLReqSignature +) + +// MarshaledSize returns size of the SetExtendedACLRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *SetExtendedACLRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldSetEACLReqTable, x.Eacl) + + proto.SizeEmbedded(fieldSetEACLReqSignature, x.Signature) + } + return sz +} + +// MarshalStable writes the SetExtendedACLRequest_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [SetExtendedACLRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *SetExtendedACLRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldSetEACLReqTable, x.Eacl) + proto.MarshalToEmbedded(b[off:], fieldSetEACLReqSignature, x.Signature) + } +} + +// MarshaledSize returns size of the SetExtendedACLResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *SetExtendedACLResponse_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the SetExtendedACLResponse_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [SetExtendedACLResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *SetExtendedACLResponse_Body) MarshalStable([]byte) {} + +const ( + _ = iota + fieldGetEACLReqContainer +) + +// MarshaledSize returns size of the GetExtendedACLRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *GetExtendedACLRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldGetEACLReqContainer, x.ContainerId) + } + return sz +} + +// MarshalStable writes the GetExtendedACLRequest_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [GetExtendedACLRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *GetExtendedACLRequest_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldGetEACLReqContainer, x.ContainerId) + } +} + +const ( + _ = iota + fieldGetEACLRespTable + fieldGetEACLRespSignature + fieldGetEACLRespSession +) + +// MarshaledSize returns size of the GetExtendedACLResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *GetExtendedACLResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldGetEACLRespTable, x.Eacl) + + proto.SizeEmbedded(fieldGetEACLRespSignature, x.Signature) + + proto.SizeEmbedded(fieldGetEACLRespSession, x.SessionToken) + } + return sz +} + +// MarshalStable writes the GetExtendedACLResponse_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [GetExtendedACLResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *GetExtendedACLResponse_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldGetEACLRespTable, x.Eacl) + off += proto.MarshalToEmbedded(b[off:], fieldGetEACLRespSignature, x.Signature) + proto.MarshalToEmbedded(b[off:], fieldGetEACLRespSession, x.SessionToken) + } +} + +const ( + _ = iota + fieldUsedSpaceEpoch + fieldUsedSpaceContainer + fieldUsedSpaceValue +) + +// MarshaledSize returns size of the AnnounceUsedSpaceRequest_Body_Announcement +// in Protocol Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *AnnounceUsedSpaceRequest_Body_Announcement) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldUsedSpaceEpoch, x.Epoch) + + proto.SizeEmbedded(fieldUsedSpaceContainer, x.ContainerId) + + proto.SizeVarint(fieldUsedSpaceValue, x.UsedSpace) + } + return sz +} + +// MarshalStable writes the AnnounceUsedSpaceRequest_Body_Announcement in +// Protocol Buffers V3 format with ascending order of fields by number into b. +// MarshalStable uses exactly +// [AnnounceUsedSpaceRequest_Body_Announcement.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *AnnounceUsedSpaceRequest_Body_Announcement) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldUsedSpaceEpoch, x.Epoch) + off += proto.MarshalToEmbedded(b[off:], fieldUsedSpaceContainer, x.ContainerId) + proto.MarshalToVarint(b[off:], fieldUsedSpaceValue, x.UsedSpace) + } +} + +const ( + _ = iota + fieldAnnounceReqList +) + +// MarshaledSize returns size of the AnnounceUsedSpaceRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *AnnounceUsedSpaceRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + for i := range x.Announcements { + sz += proto.SizeEmbedded(fieldAnnounceReqList, x.Announcements[i]) + } + } + return sz +} + +// MarshalStable writes the AnnounceUsedSpaceRequest_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [AnnounceUsedSpaceRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *AnnounceUsedSpaceRequest_Body) MarshalStable(b []byte) { + if x != nil { + var off int + for i := range x.Announcements { + off += proto.MarshalToEmbedded(b[off:], fieldAnnounceReqList, x.Announcements[i]) + } + } +} + +// MarshaledSize returns size of the AnnounceUsedSpaceResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *AnnounceUsedSpaceResponse_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the AnnounceUsedSpaceResponse_Body in Protocol Buffers +// V3 format with ascending order of fields by number into b. MarshalStable uses +// exactly [AnnounceUsedSpaceResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *AnnounceUsedSpaceResponse_Body) MarshalStable([]byte) {} diff --git a/api/container/encoding_test.go b/api/container/encoding_test.go new file mode 100644 index 00000000..e20c2a6c --- /dev/null +++ b/api/container/encoding_test.go @@ -0,0 +1,3 @@ +package container_test + +// TODO diff --git a/api/internal/test/assert.go b/api/internal/test/assert.go new file mode 100644 index 00000000..ab2d80c0 --- /dev/null +++ b/api/internal/test/assert.go @@ -0,0 +1,60 @@ +package apitest + +import ( + "bytes" + "testing" + + "github.com/nspcc-dev/neofs-sdk-go/api/refs" + "github.com/stretchr/testify/require" +) + +// AssertEqualVersions asserts that two refs.Version are essentially the same. +func AssertEqualVersions(t testing.TB, v1, v2 *refs.Version, msg string) { + require.Equal(t, v1.Major, v2.Major, msg) + require.Equal(t, v1.Minor, v2.Minor, msg) +} + +// AssertEqualOwnerIDs asserts that two refs.OwnerID are essentially the same. +func AssertEqualOwnerIDs(t testing.TB, v1, v2 *refs.OwnerID, msg string) { + require.True(t, bytes.Equal(v1.GetValue(), v2.GetValue()), msg) +} + +// AssertEqualContainerIDs asserts that two refs.ContainerID are essentially the +// same. +func AssertEqualContainerIDs(t testing.TB, v1, v2 *refs.ContainerID, msg string) { + require.True(t, bytes.Equal(v1.GetValue(), v2.GetValue()), msg) +} + +// AssertEqualObjectIDs asserts that two refs.ObjectID are essentially the same. +func AssertEqualObjectIDs(t testing.TB, v1, v2 *refs.ObjectID, msg string) { + require.True(t, bytes.Equal(v1.GetValue(), v2.GetValue()), msg) +} + +// AssertEqualObjectAddresses asserts that two refs.Address are essentially the +// same. +func AssertEqualObjectAddresses(t testing.TB, v1, v2 *refs.Address, msg string) { + AssertEqualContainerIDs(t, v1.GetContainerId(), v2.GetContainerId(), msg) + AssertEqualObjectIDs(t, v1.GetObjectId(), v2.GetObjectId(), msg) +} + +// AssertEqualSignatures asserts that two refs.Signature are essentially the +// same. +func AssertEqualSignatures(t testing.TB, v1, v2 *refs.Signature, msg string) { + require.Equal(t, v1.GetScheme(), v2.GetScheme(), msg) + require.True(t, bytes.Equal(v1.GetKey(), v2.GetKey()), msg) + require.True(t, bytes.Equal(v1.GetSign(), v2.GetSign()), msg) +} + +// AssertEqualSignaturesRFC6979 asserts that two refs.SignatureRFC6979 are +// essentially the same. +func AssertEqualSignaturesRFC6979(t testing.TB, v1, v2 *refs.SignatureRFC6979, msg string) { + require.True(t, bytes.Equal(v1.GetKey(), v2.GetKey()), msg) + require.True(t, bytes.Equal(v1.GetSign(), v2.GetSign()), msg) +} + +// AssertEqualChecksums asserts that two refs.Checksum are essentially the +// same. +func AssertEqualChecksums(t testing.TB, v1, v2 *refs.Checksum, msg string) { + require.Equal(t, v1.GetType(), v2.GetType(), msg) + require.True(t, bytes.Equal(v1.GetSum(), v2.GetSum()), msg) +} diff --git a/api/internal/test/encoding.go b/api/internal/test/encoding.go new file mode 100644 index 00000000..d50164d4 --- /dev/null +++ b/api/internal/test/encoding.go @@ -0,0 +1,61 @@ +package apitest + +import ( + "strconv" + "testing" + + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protowire" + stdproto "google.golang.org/protobuf/proto" +) + +// TestMarshalStable tests that all given proto.Message instances encode into +// Protocol Buffers V3 correctly. TestMarshalStable also checks that +// [proto.Message.MarshalStable] panics if buffer length is less than +// [proto.Message.MarshaledSize]. The equality assert func should check that all +// protocol fields in both instances are equal. It is called only when v is +// non-nil. Note that simple v1 == v2 check will most likely fail due to gRPC +// service fields. +func TestMarshalStable[T any, PTR interface { + *T + proto.Message + stdproto.Message +}](t testing.TB, assertEqual func(t testing.TB, v1, v2 PTR, msg string), vs []PTR) { + require.NotEmpty(t, vs) + for i := range vs { + sz := vs[i].MarshaledSize() + if vs[i] == nil { + require.Zero(t, sz, i) + require.NotPanics(t, func() { vs[i].MarshalStable(nil) }, i) + continue + } + if sz > 0 { + require.Panics(t, func() { vs[i].MarshalStable(make([]byte, sz-1)) }, i) + } + + b := make([]byte, sz) + vs[i].MarshalStable(b) + + // assert ascending field order + var off int + prevNum := protowire.Number(-1) + for len(b[off:]) > 0 { + num, _, ln := protowire.ConsumeField(b[off:]) + require.NoError(t, protowire.ParseError(ln), i) + require.True(t, num >= 0, i) + if prevNum >= 0 { + require.GreaterOrEqual(t, num, prevNum, i) // may equal for repeated fields + } else { + prevNum = num + } + off += ln + } + + var v2 PTR = new(T) + err := stdproto.Unmarshal(b, v2) + require.NoError(t, err, i) + require.Empty(t, v2.ProtoReflect().GetUnknown(), i) + assertEqual(t, vs[i], v2, strconv.Itoa(i)) + } +} diff --git a/api/internal/test/rand.go b/api/internal/test/rand.go new file mode 100644 index 00000000..da25c908 --- /dev/null +++ b/api/internal/test/rand.go @@ -0,0 +1,28 @@ +package apitest + +import ( + "math/rand" + + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +// RandomBytes random non-empty byte array up to 1024. +func RandomBytes[T proto.Bytes]() T { + var ln uint32 + for ln == 0 { + ln = RandomInteger[uint32]() % 1025 + } + b := make([]byte, ln) + //nolint:staticcheck + rand.Read(b) + return T(b) +} + +// RandomInteger returns random positive integer. +func RandomInteger[T proto.Varint]() T { + for { + if i := T(rand.Uint64()); i > 0 { + return i + } + } +} diff --git a/api/link/encoding.go b/api/link/encoding.go new file mode 100644 index 00000000..fe0d571e --- /dev/null +++ b/api/link/encoding.go @@ -0,0 +1,60 @@ +package link + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldLinkMeasuredObjectID + fieldLinkMeasuredObjectSize +) + +// MarshaledSize returns size of the Link_MeasuredObject in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *Link_MeasuredObject) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldLinkMeasuredObjectID, x.Id) + + proto.SizeVarint(fieldLinkMeasuredObjectSize, x.Size) + } + return sz +} + +// MarshalStable writes the Link_MeasuredObject in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [Link_MeasuredObject.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *Link_MeasuredObject) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldLinkMeasuredObjectID, x.Id) + proto.MarshalToVarint(b[off:], fieldLinkMeasuredObjectSize, x.Size) + } +} + +const ( + _ = iota + fieldLinkChildren +) + +// MarshaledSize returns size of the Link in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Link) MarshaledSize() int { + var sz int + if x != nil { + for i := range x.Children { + sz += proto.SizeEmbedded(fieldLinkChildren, x.Children[i]) + } + } + return sz +} + +// MarshalStable writes the Link in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Link.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Link) MarshalStable(b []byte) { + if x != nil { + var off int + for i := range x.Children { + off += proto.MarshalToEmbedded(b[off:], fieldLinkChildren, x.Children[i]) + } + } +} diff --git a/api/link/encoding_test.go b/api/link/encoding_test.go new file mode 100644 index 00000000..05e4bb47 --- /dev/null +++ b/api/link/encoding_test.go @@ -0,0 +1,3 @@ +package link_test + +// TODO diff --git a/api/lock/encoding.go b/api/lock/encoding.go new file mode 100644 index 00000000..567920b4 --- /dev/null +++ b/api/lock/encoding.go @@ -0,0 +1,32 @@ +package lock + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldLockMembers +) + +// MarshaledSize returns size of the Lock in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Lock) MarshaledSize() int { + var sz int + if x != nil { + for i := range x.Members { + sz += proto.SizeEmbedded(fieldLockMembers, x.Members[i]) + } + } + return sz +} + +// MarshalStable writes the Lock in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Lock.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Lock) MarshalStable(b []byte) { + if x != nil { + var off int + for i := range x.Members { + off += proto.MarshalToEmbedded(b[off:], fieldLockMembers, x.Members[i]) + } + } +} diff --git a/api/lock/encoding_test.go b/api/lock/encoding_test.go new file mode 100644 index 00000000..c00e8a6d --- /dev/null +++ b/api/lock/encoding_test.go @@ -0,0 +1,3 @@ +package lock_test + +// TODO diff --git a/api/netmap/encoding.go b/api/netmap/encoding.go new file mode 100644 index 00000000..a75ae08c --- /dev/null +++ b/api/netmap/encoding.go @@ -0,0 +1,454 @@ +package netmap + +import ( + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +const ( + _ = iota + fieldReplicaCount + fieldReplicaSelector +) + +// MarshaledSize returns size of the Replica in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Replica) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldReplicaCount, x.Count) + + proto.SizeBytes(fieldReplicaSelector, x.Selector) + } + return sz +} + +// MarshalStable writes the Replica in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Replica.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Replica) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldReplicaCount, x.Count) + proto.MarshalToBytes(b[off:], fieldReplicaSelector, x.Selector) + } +} + +const ( + _ = iota + fieldSelectorName + fieldSelectorCount + fieldSelectorClause + fieldSelectorAttribute + fieldSelectorFilter +) + +// MarshaledSize returns size of the Selector in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Selector) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldSelectorName, x.Name) + + proto.SizeVarint(fieldSelectorCount, x.Count) + + proto.SizeVarint(fieldSelectorClause, int32(x.Clause)) + + proto.SizeBytes(fieldSelectorAttribute, x.Attribute) + + proto.SizeBytes(fieldSelectorFilter, x.Filter) + } + return sz +} + +// MarshalStable writes the Selector in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Selector.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Selector) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldSelectorName, x.Name) + off += proto.MarshalToVarint(b[off:], fieldSelectorCount, x.Count) + off += proto.MarshalToVarint(b[off:], fieldSelectorClause, int32(x.Clause)) + off += proto.MarshalToBytes(b[off:], fieldSelectorAttribute, x.Attribute) + proto.MarshalToBytes(b[off:], fieldSelectorFilter, x.Filter) + } +} + +const ( + _ = iota + fieldFilterName + fieldFilterKey + fieldFilterOp + fieldFilterVal + fieldFilterSubs +) + +// MarshaledSize returns size of the Filter in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Filter) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldFilterName, x.Name) + + proto.SizeBytes(fieldFilterKey, x.Key) + + proto.SizeVarint(fieldFilterOp, int32(x.Op)) + + proto.SizeBytes(fieldFilterVal, x.Value) + for i := range x.Filters { + sz += proto.SizeEmbedded(fieldFilterSubs, x.Filters[i]) + } + } + return sz +} + +// MarshalStable writes the Filter in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Filter.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Filter) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldFilterName, x.Name) + off += proto.MarshalToBytes(b[off:], fieldFilterKey, x.Key) + off += proto.MarshalToVarint(b[off:], fieldFilterOp, int32(x.Op)) + off += proto.MarshalToBytes(b[off:], fieldFilterVal, x.Value) + for i := range x.Filters { + off += proto.MarshalToEmbedded(b[off:], fieldFilterSubs, x.Filters[i]) + } + } +} + +const ( + _ = iota + fieldPolicyReplicas + fieldPolicyBackupFactor + fieldPolicySelectors + fieldPolicyFilters + fieldPolicySubnet +) + +// MarshaledSize returns size of the PlacementPolicy in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *PlacementPolicy) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldPolicyBackupFactor, x.ContainerBackupFactor) + + proto.SizeEmbedded(fieldPolicySubnet, x.SubnetId) + for i := range x.Replicas { + sz += proto.SizeEmbedded(fieldPolicyReplicas, x.Replicas[i]) + } + for i := range x.Selectors { + sz += proto.SizeEmbedded(fieldPolicySelectors, x.Selectors[i]) + } + for i := range x.Filters { + sz += proto.SizeEmbedded(fieldPolicyFilters, x.Filters[i]) + } + } + return sz +} + +// MarshalStable writes the PlacementPolicy in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [PlacementPolicy.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *PlacementPolicy) MarshalStable(b []byte) { + if x != nil { + var off int + for i := range x.Replicas { + off += proto.MarshalToEmbedded(b[off:], fieldPolicyReplicas, x.Replicas[i]) + } + off += proto.MarshalToVarint(b[off:], fieldPolicyBackupFactor, x.ContainerBackupFactor) + for i := range x.Selectors { + off += proto.MarshalToEmbedded(b[off:], fieldPolicySelectors, x.Selectors[i]) + } + for i := range x.Filters { + off += proto.MarshalToEmbedded(b[off:], fieldPolicyFilters, x.Filters[i]) + } + proto.MarshalToEmbedded(b[off:], fieldPolicySubnet, x.SubnetId) + } +} + +const ( + _ = iota + fieldNetPrmKey + fieldNetPrmVal +) + +// MarshaledSize returns size of the NetworkConfig_Parameter in Protocol Buffers +// V3 format in bytes. MarshaledSize is NPE-safe. +func (x *NetworkConfig_Parameter) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldNetPrmKey, x.Key) + + proto.SizeBytes(fieldNetPrmVal, x.Value) + } + return sz +} + +// MarshalStable writes the NetworkConfig_Parameter in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [NetworkConfig_Parameter.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *NetworkConfig_Parameter) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldNetPrmKey, x.Key) + proto.MarshalToBytes(b[off:], fieldNetPrmVal, x.Value) + } +} + +const ( + _ = iota + fieldNetConfigPrms +) + +// MarshaledSize returns size of the NetworkConfig in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *NetworkConfig) MarshaledSize() int { + var sz int + if x != nil { + for i := range x.Parameters { + sz += proto.SizeEmbedded(fieldNetConfigPrms, x.Parameters[i]) + } + } + return sz +} + +// MarshalStable writes the NetworkConfig in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [NetworkConfig.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *NetworkConfig) MarshalStable(b []byte) { + if x != nil { + var off int + for i := range x.Parameters { + off += proto.MarshalToEmbedded(b[off:], fieldNetConfigPrms, x.Parameters[i]) + } + } +} + +const ( + _ = iota + fieldNetInfoCurEpoch + fieldNetInfoMagic + fieldNetInfoMSPerBlock + fieldNetInfoConfig +) + +// MarshaledSize returns size of the NetworkInfo in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *NetworkInfo) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldNetInfoCurEpoch, x.CurrentEpoch) + + proto.SizeVarint(fieldNetInfoMagic, x.MagicNumber) + + proto.SizeVarint(fieldNetInfoMSPerBlock, x.MsPerBlock) + + proto.SizeEmbedded(fieldNetInfoConfig, x.NetworkConfig) + } + return sz +} + +// MarshalStable writes the NetworkInfo in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [NetworkInfo.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *NetworkInfo) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldNetInfoCurEpoch, x.CurrentEpoch) + off += proto.MarshalToVarint(b[off:], fieldNetInfoMagic, x.MagicNumber) + off += proto.MarshalToVarint(b[off:], fieldNetInfoMSPerBlock, x.MsPerBlock) + proto.MarshalToEmbedded(b[off:], fieldNetInfoConfig, x.NetworkConfig) + } +} + +const ( + _ = iota + fieldNumNodeAttrKey + fieldNumNodeAttrVal + fieldNumNodeAttrParents +) + +// MarshaledSize returns size of the NodeInfo_Attribute in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *NodeInfo_Attribute) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldNumNodeAttrKey, x.Key) + + proto.SizeBytes(fieldNumNodeAttrVal, x.Value) + + proto.SizeRepeatedBytes(fieldNumNodeAttrParents, x.Parents) + } + return sz +} + +// MarshalStable writes the NodeInfo_Attribute in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [NodeInfo_Attribute.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *NodeInfo_Attribute) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldNumNodeAttrKey, x.Key) + off += proto.MarshalToBytes(b[off:], fieldNumNodeAttrVal, x.Value) + proto.MarshalToRepeatedBytes(b[off:], fieldNumNodeAttrParents, x.Parents) + } +} + +const ( + _ = iota + fieldNodeInfoPubKey + fieldNodeInfoAddresses + fieldNodeInfoAttributes + fieldNodeInfoState +) + +// MarshaledSize returns size of the NodeInfo in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *NodeInfo) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldNodeInfoPubKey, x.PublicKey) + + proto.SizeRepeatedBytes(fieldNodeInfoAddresses, x.Addresses) + + proto.SizeVarint(fieldNodeInfoState, int32(x.State)) + for i := range x.Attributes { + sz += proto.SizeEmbedded(fieldNodeInfoAttributes, x.Attributes[i]) + } + } + return sz +} + +// MarshalStable writes the NodeInfo in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [NodeInfo.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *NodeInfo) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldNodeInfoPubKey, x.PublicKey) + off += proto.MarshalToRepeatedBytes(b[off:], fieldNodeInfoAddresses, x.Addresses) + for i := range x.Attributes { + off += proto.MarshalToEmbedded(b[off:], fieldNodeInfoAttributes, x.Attributes[i]) + } + proto.MarshalToVarint(b[off:], fieldNodeInfoState, int32(x.State)) + } +} + +const ( + _ = iota + fieldNetmapEpoch + fieldNetmapNodes +) + +// MarshaledSize returns size of the Netmap in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Netmap) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldNetmapEpoch, x.Epoch) + for i := range x.Nodes { + sz += proto.SizeEmbedded(fieldNetmapNodes, x.Nodes[i]) + } + } + return sz +} + +// MarshalStable writes the Netmap in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Netmap.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Netmap) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldNetmapEpoch, x.Epoch) + for i := range x.Nodes { + off += proto.MarshalToEmbedded(b[off:], fieldNetmapNodes, x.Nodes[i]) + } + } +} + +// MarshaledSize returns size of the LocalNodeInfoRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *LocalNodeInfoRequest_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the LocalNodeInfoRequest_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [LocalNodeInfoRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *LocalNodeInfoRequest_Body) MarshalStable([]byte) {} + +const ( + _ = iota + fieldNodeInfoRespVersion + fieldNodeInfoRespInfo +) + +// MarshaledSize returns size of the LocalNodeInfoResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *LocalNodeInfoResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldNodeInfoRespVersion, x.Version) + + proto.SizeEmbedded(fieldNodeInfoRespInfo, x.NodeInfo) + } + return sz +} + +// MarshalStable writes the LocalNodeInfoResponse_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [LocalNodeInfoResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *LocalNodeInfoResponse_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldNodeInfoRespVersion, x.Version) + proto.MarshalToEmbedded(b[off:], fieldNodeInfoRespInfo, x.NodeInfo) + } +} + +// MarshaledSize returns size of the NetworkInfoRequest_Body in Protocol Buffers +// V3 format in bytes. MarshaledSize is NPE-safe. +func (x *NetworkInfoRequest_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the NetworkInfoRequest_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [NetworkInfoRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *NetworkInfoRequest_Body) MarshalStable([]byte) {} + +const ( + _ = iota + fieldNetInfoRespInfo +) + +// MarshaledSize returns size of the NetworkInfoResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *NetworkInfoResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldNetInfoRespInfo, x.NetworkInfo) + } + return sz +} + +// MarshalStable writes the NetworkInfoResponse_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [NetworkInfoResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *NetworkInfoResponse_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldNetInfoRespInfo, x.NetworkInfo) + } +} + +// MarshaledSize returns size of the NetmapSnapshotRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *NetmapSnapshotRequest_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the NetmapSnapshotRequest_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [NetmapSnapshotRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *NetmapSnapshotRequest_Body) MarshalStable([]byte) {} + +const ( + _ = iota + fieldNetmapRespNetmap +) + +// MarshaledSize returns size of the NetmapSnapshotResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *NetmapSnapshotResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldNetmapRespNetmap, x.Netmap) + } + return sz +} + +// MarshalStable writes the NetmapSnapshotResponse_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [NetmapSnapshotResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *NetmapSnapshotResponse_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldNetmapRespNetmap, x.Netmap) + } +} diff --git a/api/netmap/encoding_test.go b/api/netmap/encoding_test.go new file mode 100644 index 00000000..62e30dbb --- /dev/null +++ b/api/netmap/encoding_test.go @@ -0,0 +1,3 @@ +package netmap_test + +// TODO diff --git a/api/object/encoding.go b/api/object/encoding.go new file mode 100644 index 00000000..f124749f --- /dev/null +++ b/api/object/encoding.go @@ -0,0 +1,898 @@ +package object + +import ( + "fmt" + + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +const ( + _ = iota + fieldSplitParent + fieldSplitPrevious + fieldSplitParentSignature + fieldSplitParentHeader + fieldSplitChildren + fieldSplitID + fieldSplitFirst +) + +// MarshaledSize returns size of the Header_Split in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *Header_Split) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldSplitParent, x.Parent) + + proto.SizeEmbedded(fieldSplitPrevious, x.Previous) + + proto.SizeEmbedded(fieldSplitParentSignature, x.ParentSignature) + + proto.SizeEmbedded(fieldSplitParentHeader, x.ParentHeader) + + proto.SizeBytes(fieldSplitID, x.SplitId) + + proto.SizeEmbedded(fieldSplitFirst, x.First) + for i := range x.Children { + sz += proto.SizeEmbedded(fieldSplitChildren, x.Children[i]) + } + } + return sz +} + +// MarshalStable writes the Header_Split in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Header_Split.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Header_Split) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldSplitParent, x.Parent) + off += proto.MarshalToEmbedded(b[off:], fieldSplitPrevious, x.Previous) + off += proto.MarshalToEmbedded(b[off:], fieldSplitParentSignature, x.ParentSignature) + off += proto.MarshalToEmbedded(b[off:], fieldSplitParentHeader, x.ParentHeader) + off += proto.MarshalToBytes(b[off:], fieldSplitID, x.SplitId) + for i := range x.Children { + off += proto.MarshalToEmbedded(b[off:], fieldSplitChildren, x.Children[i]) + } + proto.MarshalToEmbedded(b[off:], fieldSplitFirst, x.First) + } +} + +const ( + _ = iota + fieldAttributeKey + fieldAttributeValue +) + +// MarshaledSize returns size of the Header_Attribute in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *Header_Attribute) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldAttributeKey, x.Key) + + proto.SizeBytes(fieldAttributeValue, x.Value) + } + return sz +} + +// MarshalStable writes the Header_Attribute in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Header_Attribute.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Header_Attribute) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldAttributeKey, x.Key) + proto.MarshalToBytes(b[off:], fieldAttributeValue, x.Value) + } +} + +const ( + _ = iota + fieldShortHeaderVersion + fieldShortHeaderCreationEpoch + fieldShortHeaderOwner + fieldShortHeaderType + fieldShortHeaderLen + fieldShortHeaderChecksum + fieldShortHeaderHomomorphic +) + +// MarshaledSize returns size of the ShortHeader in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *ShortHeader) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldShortHeaderVersion, x.Version) + + proto.SizeVarint(fieldShortHeaderCreationEpoch, x.CreationEpoch) + + proto.SizeEmbedded(fieldShortHeaderOwner, x.OwnerId) + + proto.SizeVarint(fieldShortHeaderType, int32(x.ObjectType)) + + proto.SizeVarint(fieldShortHeaderLen, x.PayloadLength) + + proto.SizeEmbedded(fieldShortHeaderChecksum, x.PayloadHash) + + proto.SizeEmbedded(fieldShortHeaderHomomorphic, x.HomomorphicHash) + } + return sz +} + +// MarshalStable writes the ShortHeader in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [ShortHeader.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *ShortHeader) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldShortHeaderVersion, x.Version) + off += proto.MarshalToVarint(b[off:], fieldShortHeaderCreationEpoch, x.CreationEpoch) + off += proto.MarshalToEmbedded(b[off:], fieldShortHeaderOwner, x.OwnerId) + off += proto.MarshalToVarint(b[off:], fieldShortHeaderType, int32(x.ObjectType)) + off += proto.MarshalToVarint(b[off:], fieldShortHeaderLen, x.PayloadLength) + off += proto.MarshalToEmbedded(b[off:], fieldShortHeaderChecksum, x.PayloadHash) + off += proto.MarshalToEmbedded(b[off:], fieldShortHeaderHomomorphic, x.HomomorphicHash) + } +} + +const ( + _ = iota + fieldHeaderVersion + fieldHeaderContainer + fieldHeaderOwner + fieldHeaderCreationEpoch + fieldHeaderLen + fieldHeaderChecksum + fieldHeaderType + fieldHeaderHomomorphic + fieldHeaderSession + fieldHeaderAttributes + fieldHeaderSplit +) + +// MarshaledSize returns size of the Header in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Header) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldHeaderVersion, x.Version) + + proto.SizeEmbedded(fieldHeaderContainer, x.ContainerId) + + proto.SizeEmbedded(fieldHeaderOwner, x.OwnerId) + + proto.SizeVarint(fieldHeaderCreationEpoch, x.CreationEpoch) + + proto.SizeVarint(fieldHeaderLen, x.PayloadLength) + + proto.SizeEmbedded(fieldHeaderChecksum, x.PayloadHash) + + proto.SizeVarint(fieldHeaderType, int32(x.ObjectType)) + + proto.SizeEmbedded(fieldHeaderHomomorphic, x.HomomorphicHash) + + proto.SizeEmbedded(fieldHeaderSession, x.SessionToken) + + proto.SizeEmbedded(fieldHeaderSplit, x.Split) + for i := range x.Attributes { + sz += proto.SizeEmbedded(fieldHeaderAttributes, x.Attributes[i]) + } + } + return sz +} + +// MarshalStable writes the Header in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Header.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Header) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldHeaderVersion, x.Version) + off += proto.MarshalToEmbedded(b[off:], fieldHeaderContainer, x.ContainerId) + off += proto.MarshalToEmbedded(b[off:], fieldHeaderOwner, x.OwnerId) + off += proto.MarshalToVarint(b[off:], fieldHeaderCreationEpoch, x.CreationEpoch) + off += proto.MarshalToVarint(b[off:], fieldHeaderLen, x.PayloadLength) + off += proto.MarshalToEmbedded(b[off:], fieldHeaderChecksum, x.PayloadHash) + off += proto.MarshalToVarint(b[off:], fieldHeaderType, int32(x.ObjectType)) + off += proto.MarshalToEmbedded(b[off:], fieldHeaderHomomorphic, x.HomomorphicHash) + off += proto.MarshalToEmbedded(b[off:], fieldHeaderSession, x.SessionToken) + for i := range x.Attributes { + off += proto.MarshalToEmbedded(b[off:], fieldHeaderAttributes, x.Attributes[i]) + } + proto.MarshalToEmbedded(b[off:], fieldHeaderSplit, x.Split) + } +} + +const ( + _ = iota + fieldObjectID + fieldObjectSignature + fieldObjectHeader + fieldObjectPayload +) + +// MarshaledSize returns size of the Object in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Object) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldObjectID, x.ObjectId) + + proto.SizeEmbedded(fieldObjectSignature, x.Signature) + + proto.SizeEmbedded(fieldObjectHeader, x.Header) + + proto.SizeBytes(fieldObjectPayload, x.Payload) + } + return sz +} + +// MarshalStable writes the Object in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Object.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Object) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldObjectID, x.ObjectId) + off += proto.MarshalToEmbedded(b[off:], fieldObjectSignature, x.Signature) + off += proto.MarshalToEmbedded(b[off:], fieldObjectHeader, x.Header) + proto.MarshalToBytes(b[off:], fieldObjectPayload, x.Payload) + } +} + +const ( + _ = iota + fieldSplitInfoID + fieldSplitInfoLast + fieldSplitInfoLink + fieldSplitInfoFirst +) + +// MarshaledSize returns size of the SplitInfo in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *SplitInfo) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldSplitInfoID, x.SplitId) + + proto.SizeEmbedded(fieldSplitInfoLast, x.LastPart) + + proto.SizeEmbedded(fieldSplitInfoLink, x.Link) + + proto.SizeEmbedded(fieldSplitInfoFirst, x.FirstPart) + } + return sz +} + +// MarshalStable writes the SplitInfo in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [SplitInfo.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *SplitInfo) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldSplitInfoID, x.SplitId) + off += proto.MarshalToEmbedded(b[off:], fieldSplitInfoLast, x.LastPart) + off += proto.MarshalToEmbedded(b[off:], fieldSplitInfoLink, x.Link) + proto.MarshalToEmbedded(b[off:], fieldSplitInfoFirst, x.FirstPart) + } +} + +const ( + _ = iota + fieldGetReqAddress + fieldGetReqRaw +) + +// MarshaledSize returns size of the GetRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *GetRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldGetReqAddress, x.Address) + + proto.SizeBool(fieldGetReqRaw, x.Raw) + } + return sz +} + +// MarshalStable writes the GetRequest_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [GetRequest_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *GetRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldGetReqAddress, x.Address) + proto.MarshalToBool(b[off:], fieldGetReqRaw, x.Raw) + } +} + +const ( + _ = iota + fieldGetRespInitID + fieldGetRespInitSignature + fieldGetRespInitHeader +) + +// MarshaledSize returns size of the GetResponse_Body_Init in Protocol Buffers +// V3 format in bytes. MarshaledSize is NPE-safe. +func (x *GetResponse_Body_Init) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldGetRespInitID, x.ObjectId) + + proto.SizeEmbedded(fieldGetRespInitSignature, x.Signature) + + proto.SizeEmbedded(fieldGetRespInitHeader, x.Header) + } + return sz +} + +// MarshalStable writes the GetResponse_Body_Init in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [GetResponse_Body_Init.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *GetResponse_Body_Init) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldGetRespInitID, x.ObjectId) + off += proto.MarshalToEmbedded(b[off:], fieldGetRespInitSignature, x.Signature) + proto.MarshalToEmbedded(b[off:], fieldGetRespInitHeader, x.Header) + } +} + +const ( + _ = iota + fieldGetRespInit + fieldGetRespChunk + fieldGetRespSplitInfo +) + +// MarshaledSize returns size of the GetResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *GetResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + switch p := x.ObjectPart.(type) { + default: + panic(fmt.Sprintf("unexpected object part %T", x.ObjectPart)) + case nil: + case *GetResponse_Body_Init_: + if p != nil { + sz = proto.SizeEmbedded(fieldGetRespInit, p.Init) + } + case *GetResponse_Body_Chunk: + if p != nil { + sz = proto.SizeBytes(fieldGetRespChunk, p.Chunk) + } + case *GetResponse_Body_SplitInfo: + if p != nil { + sz = proto.SizeEmbedded(fieldGetRespSplitInfo, p.SplitInfo) + } + } + } + return sz +} + +// MarshalStable writes the GetResponse_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [GetResponse_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *GetResponse_Body) MarshalStable(b []byte) { + if x != nil { + switch p := x.ObjectPart.(type) { + default: + panic(fmt.Sprintf("unexpected object part %T", x.ObjectPart)) + case nil: + case *GetResponse_Body_Init_: + if p != nil { + proto.MarshalToEmbedded(b, fieldGetRespInit, p.Init) + } + case *GetResponse_Body_Chunk: + if p != nil { + proto.MarshalToBytes(b, fieldGetRespChunk, p.Chunk) + } + case *GetResponse_Body_SplitInfo: + if p != nil { + proto.MarshalToEmbedded(b, fieldGetRespSplitInfo, p.SplitInfo) + } + } + } +} + +const ( + _ = iota + fieldHeadReqAddress + fieldHeadReqMain + fieldHeadReqRaw +) + +// MarshaledSize returns size of the HeadRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *HeadRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldHeadReqAddress, x.Address) + + proto.SizeBool(fieldHeadReqMain, x.MainOnly) + + proto.SizeBool(fieldHeadReqRaw, x.Raw) + } + return sz +} + +// MarshalStable writes the HeadRequest_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [HeadRequest_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *HeadRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldHeadReqAddress, x.Address) + off += proto.MarshalToBool(b[off:], fieldHeadReqMain, x.MainOnly) + proto.MarshalToBool(b[off:], fieldHeadReqRaw, x.Raw) + } +} + +const ( + _ = iota + fieldHeaderSignatureHdr + fieldHeaderSignatureSig +) + +// MarshaledSize returns size of the HeaderWithSignature in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *HeaderWithSignature) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldHeaderSignatureHdr, x.Header) + + proto.SizeEmbedded(fieldHeaderSignatureSig, x.Signature) + } + return sz +} + +// MarshalStable writes the HeaderWithSignature in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [HeaderWithSignature.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *HeaderWithSignature) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldHeaderSignatureHdr, x.Header) + proto.MarshalToEmbedded(b[off:], fieldHeaderSignatureSig, x.Signature) + } +} + +const ( + _ = iota + fieldHeadRespHeader + fieldHeadRespShort + fieldHeadRespSplitInfo +) + +// MarshaledSize returns size of the HeadResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *HeadResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + switch h := x.Head.(type) { + default: + panic(fmt.Sprintf("unexpected head part %T", x.Head)) + case nil: + case *HeadResponse_Body_Header: + if h != nil { + sz = proto.SizeEmbedded(fieldHeadRespHeader, h.Header) + } + case *HeadResponse_Body_ShortHeader: + if h != nil { + sz = proto.SizeEmbedded(fieldHeadRespShort, h.ShortHeader) + } + case *HeadResponse_Body_SplitInfo: + if h != nil { + sz = proto.SizeEmbedded(fieldHeadRespSplitInfo, h.SplitInfo) + } + } + } + return sz +} + +// MarshalStable writes the HeadResponse_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [HeadResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *HeadResponse_Body) MarshalStable(b []byte) { + if x != nil { + switch h := x.Head.(type) { + default: + panic(fmt.Sprintf("unexpected head part %T", x.Head)) + case nil: + case *HeadResponse_Body_Header: + if h != nil { + proto.MarshalToEmbedded(b, fieldHeadRespHeader, h.Header) + } + case *HeadResponse_Body_ShortHeader: + if h != nil { + proto.MarshalToEmbedded(b, fieldHeadRespShort, h.ShortHeader) + } + case *HeadResponse_Body_SplitInfo: + if h != nil { + proto.MarshalToEmbedded(b, fieldHeadRespSplitInfo, h.SplitInfo) + } + } + } +} + +const ( + _ = iota + fieldRangeOff + fieldRangeLen +) + +// MarshaledSize returns size of the Range in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Range) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldRangeOff, x.Offset) + + proto.SizeVarint(fieldRangeLen, x.Length) + } + return sz +} + +// MarshalStable writes the Range in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Range.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Range) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldRangeOff, x.Offset) + proto.MarshalToVarint(b[off:], fieldRangeLen, x.Length) + } +} + +const ( + _ = iota + fieldRangeReqAddress + fieldRangeReqRange + fieldRangeReqRaw +) + +// MarshaledSize returns size of the GetRangeRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *GetRangeRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldRangeReqAddress, x.Address) + + proto.SizeEmbedded(fieldRangeReqRange, x.Range) + + proto.SizeBool(fieldRangeReqRaw, x.Raw) + } + return sz +} + +// MarshalStable writes the GetRangeRequest_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [GetRangeRequest_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *GetRangeRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldRangeReqAddress, x.Address) + off += proto.MarshalToEmbedded(b[off:], fieldRangeReqRange, x.Range) + proto.MarshalToBool(b[off:], fieldRangeReqRaw, x.Raw) + } +} + +const ( + _ = iota + fieldRangeRespChunk + fieldRangeRespSplitInfo +) + +// MarshaledSize returns size of the GetRangeResponse_Body in Protocol Buffers +// V3 format in bytes. MarshaledSize is NPE-safe. +func (x *GetRangeResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + switch p := x.RangePart.(type) { + default: + panic(fmt.Sprintf("unexpected range part %T", x.RangePart)) + case nil: + case *GetRangeResponse_Body_Chunk: + if p != nil { + sz = proto.SizeBytes(fieldRangeRespChunk, p.Chunk) + } + case *GetRangeResponse_Body_SplitInfo: + if p != nil { + sz = proto.SizeEmbedded(fieldRangeRespSplitInfo, p.SplitInfo) + } + } + } + return sz +} + +// MarshalStable writes the GetRangeResponse_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [GetRangeResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *GetRangeResponse_Body) MarshalStable(b []byte) { + if x != nil { + switch p := x.RangePart.(type) { + default: + panic(fmt.Sprintf("unexpected range part %T", x.RangePart)) + case nil: + case *GetRangeResponse_Body_Chunk: + if p != nil { + proto.MarshalToBytes(b, fieldRangeRespChunk, p.Chunk) + } + case *GetRangeResponse_Body_SplitInfo: + if p != nil { + proto.MarshalToEmbedded(b, fieldRangeRespSplitInfo, p.SplitInfo) + } + } + } +} + +const ( + _ = iota + fieldRangeHashReqAddress + fieldRangeHashReqRanges + fieldRangeHashReqSalt + fieldRangeHashReqType +) + +// MarshaledSize returns size of the GetRangeHashRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *GetRangeHashRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldRangeHashReqAddress, x.Address) + + proto.SizeBytes(fieldRangeHashReqSalt, x.Salt) + + proto.SizeVarint(fieldRangeHashReqType, int32(x.Type)) + for i := range x.Ranges { + sz += proto.SizeEmbedded(fieldRangeHashReqRanges, x.Ranges[i]) + } + } + return sz +} + +// MarshalStable writes the GetRangeHashRequest_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [GetRangeHashRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *GetRangeHashRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldRangeHashReqAddress, x.Address) + for i := range x.Ranges { + off += proto.MarshalToEmbedded(b[off:], fieldRangeHashReqRanges, x.Ranges[i]) + } + off += proto.MarshalToBytes(b[off:], fieldRangeHashReqSalt, x.Salt) + proto.MarshalToVarint(b[off:], fieldRangeHashReqType, int32(x.Type)) + } +} + +const ( + _ = iota + fieldRangeHashRespType + fieldRangeHashRespHashes +) + +// MarshaledSize returns size of the GetRangeHashResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *GetRangeHashResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldRangeHashRespType, int32(x.Type)) + + proto.SizeRepeatedBytes(fieldRangeHashRespHashes, x.HashList) + } + return sz +} + +// MarshalStable writes the GetRangeHashResponse_Body in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [GetRangeHashResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *GetRangeHashResponse_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldRangeHashRespType, int32(x.Type)) + proto.MarshalToRepeatedBytes(b[off:], fieldRangeHashRespHashes, x.HashList) + } +} + +const ( + _ = iota + fieldPutReqInitID + fieldPutReqInitSignature + fieldPutReqInitHeader + fieldPutReqInitCopies +) + +// MarshaledSize returns size of the PutRequest_Body_Init in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *PutRequest_Body_Init) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldPutReqInitID, x.ObjectId) + + proto.SizeEmbedded(fieldPutReqInitSignature, x.Signature) + + proto.SizeEmbedded(fieldPutReqInitHeader, x.Header) + + proto.SizeVarint(fieldPutReqInitCopies, x.CopiesNumber) + } + return sz +} + +// MarshalStable writes the PutRequest_Body_Init in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [PutRequest_Body_Init.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *PutRequest_Body_Init) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldPutReqInitID, x.ObjectId) + off += proto.MarshalToEmbedded(b[off:], fieldPutReqInitSignature, x.Signature) + off += proto.MarshalToEmbedded(b[off:], fieldPutReqInitHeader, x.Header) + proto.MarshalToVarint(b[off:], fieldPutReqInitCopies, x.CopiesNumber) + } +} + +const ( + _ = iota + fieldPutReqInit + fieldPutReqChunk +) + +// MarshaledSize returns size of the PutRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *PutRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + switch p := x.ObjectPart.(type) { + default: + panic(fmt.Sprintf("unexpected object part %T", x.ObjectPart)) + case nil: + case *PutRequest_Body_Init_: + sz = proto.SizeEmbedded(fieldPutReqInit, p.Init) + case *PutRequest_Body_Chunk: + sz = proto.SizeBytes(fieldPutReqChunk, p.Chunk) + } + } + return sz +} + +// MarshalStable writes the PutRequest_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [PutRequest_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *PutRequest_Body) MarshalStable(b []byte) { + if x != nil { + switch p := x.ObjectPart.(type) { + default: + panic(fmt.Sprintf("unexpected object part %T", x.ObjectPart)) + case nil: + case *PutRequest_Body_Init_: + proto.MarshalToEmbedded(b, fieldPutReqInit, p.Init) + case *PutRequest_Body_Chunk: + proto.MarshalToBytes(b, fieldPutReqChunk, p.Chunk) + } + } +} + +const ( + _ = iota + fieldPutRespID +) + +// MarshaledSize returns size of the PutResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *PutResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldPutRespID, x.ObjectId) + } + return sz +} + +// MarshalStable writes the PutResponse_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [PutResponse_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *PutResponse_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldPutRespID, x.ObjectId) + } +} + +const ( + _ = iota + fieldDeleteReqAddress +) + +// MarshaledSize returns size of the DeleteRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *DeleteRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldDeleteReqAddress, x.Address) + } + return sz +} + +// MarshalStable writes the DeleteRequest_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [DeleteRequest_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *DeleteRequest_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldDeleteReqAddress, x.Address) + } +} + +const ( + _ = iota + fieldDeleteRespTombstone +) + +// MarshaledSize returns size of the DeleteResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *DeleteResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldDeleteRespTombstone, x.Tombstone) + } + return sz +} + +// MarshalStable writes the DeleteResponse_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [DeleteResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *DeleteResponse_Body) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToEmbedded(b, fieldDeleteRespTombstone, x.Tombstone) + } +} + +const ( + _ = iota + fieldSearchFilterMatcher + fieldSearchFilterKey + fieldSearchFilterValue +) + +// MarshaledSize returns size of the SearchRequest_Body_Filter in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *SearchRequest_Body_Filter) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldSearchFilterMatcher, int32(x.MatchType)) + sz += proto.SizeBytes(fieldSearchFilterKey, x.Key) + sz += proto.SizeBytes(fieldSearchFilterValue, x.Value) + } + return sz +} + +// MarshalStable writes the SearchRequest_Body_Filter in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [SearchRequest_Body_Filter.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *SearchRequest_Body_Filter) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldSearchFilterMatcher, int32(x.MatchType)) + off += proto.MarshalToBytes(b[off:], fieldSearchFilterKey, x.Key) + proto.MarshalToBytes(b[off:], fieldSearchFilterValue, x.Value) + } +} + +const ( + _ = iota + fieldSearchReqContainer + fieldSearchReqVersion + fieldSearchReqFilters +) + +// MarshaledSize returns size of the SearchRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *SearchRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldSearchReqContainer, x.ContainerId) + sz += proto.SizeVarint(fieldSearchReqVersion, x.Version) + for i := range x.Filters { + sz += proto.SizeEmbedded(fieldSearchReqFilters, x.Filters[i]) + } + } + return sz +} + +// MarshalStable writes the SearchRequest_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [SearchRequest_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *SearchRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldSearchReqContainer, x.ContainerId) + off += proto.MarshalToVarint(b[off:], fieldSearchReqVersion, x.Version) + for i := range x.Filters { + off += proto.MarshalToEmbedded(b[off:], fieldSearchReqFilters, x.Filters[i]) + } + } +} + +const ( + _ = iota + fieldSearchRespIDList +) + +// MarshaledSize returns size of the SearchResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *SearchResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + for i := range x.IdList { + sz += proto.SizeEmbedded(fieldSearchRespIDList, x.IdList[i]) + } + } + return sz +} + +// MarshalStable writes the SearchResponse_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [SearchResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *SearchResponse_Body) MarshalStable(b []byte) { + if x != nil { + var off int + for i := range x.IdList { + off += proto.MarshalToEmbedded(b[off:], fieldSearchRespIDList, x.IdList[i]) + } + } +} diff --git a/api/object/encoding_test.go b/api/object/encoding_test.go new file mode 100644 index 00000000..4886d321 --- /dev/null +++ b/api/object/encoding_test.go @@ -0,0 +1,3 @@ +package object_test + +// TODO diff --git a/api/refs/encoding.go b/api/refs/encoding.go new file mode 100644 index 00000000..6adb774a --- /dev/null +++ b/api/refs/encoding.go @@ -0,0 +1,239 @@ +package refs + +import ( + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +const ( + _ = iota + fieldOwnerIDValue +) + +// MarshaledSize returns size of the OwnerID in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *OwnerID) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldOwnerIDValue, x.Value) + } + return sz +} + +// MarshalStable writes the OwnerID in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [OwnerID.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *OwnerID) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToBytes(b, fieldOwnerIDValue, x.Value) + } +} + +const ( + _ = iota + fieldContainerIDValue +) + +// MarshaledSize returns size of the ContainerID in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *ContainerID) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldContainerIDValue, x.Value) + } + return sz +} + +// MarshalStable writes the ContainerID in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [ContainerID.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *ContainerID) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToBytes(b, fieldContainerIDValue, x.Value) + } +} + +const ( + _ = iota + fieldObjectIDValue +) + +// MarshaledSize returns size of the ObjectID in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *ObjectID) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldObjectIDValue, x.Value) + } + return sz +} + +// MarshalStable writes the ObjectID in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [ObjectID.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *ObjectID) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToBytes(b, fieldObjectIDValue, x.Value) + } +} + +const ( + _ = iota + fieldAddressContainer + fieldAddressObject +) + +// MarshaledSize returns size of the Address in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Address) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldAddressContainer, x.ContainerId) + + proto.SizeEmbedded(fieldAddressObject, x.ObjectId) + } + return sz +} + +// MarshalStable writes the Address in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Address.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Address) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldAddressContainer, x.ContainerId) + proto.MarshalToEmbedded(b[off:], fieldAddressObject, x.ObjectId) + } +} + +const ( + _ = iota + fieldVersionMajor + fieldVersionMinor +) + +// MarshaledSize returns size of the Version in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Version) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldVersionMajor, x.Major) + + proto.SizeVarint(fieldVersionMinor, x.Minor) + } + return sz +} + +// MarshalStable writes the Version in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Version.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Version) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldVersionMajor, x.Major) + proto.MarshalToVarint(b[off:], fieldVersionMinor, x.Minor) + } +} + +const ( + _ = iota + fieldSignatureKey + fieldSignatureVal + fieldSignatureScheme +) + +// MarshaledSize returns size of the Signature in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Signature) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldSignatureKey, x.Key) + + proto.SizeBytes(fieldSignatureVal, x.Sign) + + proto.SizeVarint(fieldSignatureScheme, int32(x.Scheme)) + } + return sz +} + +// MarshalStable writes the Signature in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Signature.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Signature) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldSignatureKey, x.Key) + off += proto.MarshalToBytes(b[off:], fieldSignatureVal, x.Sign) + proto.MarshalToVarint(b[off:], fieldSignatureScheme, int32(x.Scheme)) + } +} + +const ( + _ = iota + fieldSigRFC6979Key + fieldSigRFC6979Val +) + +// MarshaledSize returns size of the SignatureRFC6979 in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *SignatureRFC6979) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldSigRFC6979Key, x.Key) + + proto.SizeBytes(fieldSigRFC6979Val, x.Sign) + } + return sz +} + +// MarshalStable writes the SignatureRFC6979 in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [SignatureRFC6979.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *SignatureRFC6979) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldSigRFC6979Key, x.Key) + proto.MarshalToBytes(b[off:], fieldSigRFC6979Val, x.Sign) + } +} + +const ( + _ = iota + fieldChecksumType + fieldChecksumValue +) + +// MarshaledSize returns size of the Checksum in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Checksum) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldChecksumType, int32(x.Type)) + + proto.SizeBytes(fieldChecksumValue, x.Sum) + } + return sz +} + +// MarshalStable writes the Checksum in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Checksum.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Checksum) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldChecksumType, int32(x.Type)) + proto.MarshalToBytes(b[off:], fieldChecksumValue, x.Sum) + } +} + +const ( + _ = iota + fieldSubnetVal +) + +// MarshaledSize returns size of the SubnetID in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *SubnetID) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeFixed32(fieldSubnetVal, x.Value) + } + return sz +} + +// MarshalStable writes the SubnetID in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [SubnetID.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *SubnetID) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToFixed32(b, fieldSubnetVal, x.Value) + } +} diff --git a/api/refs/encoding_test.go b/api/refs/encoding_test.go new file mode 100644 index 00000000..4633ec5e --- /dev/null +++ b/api/refs/encoding_test.go @@ -0,0 +1,117 @@ +package refs_test + +import ( + "testing" + + apitest "github.com/nspcc-dev/neofs-sdk-go/api/internal/test" + "github.com/nspcc-dev/neofs-sdk-go/api/refs" + "github.com/stretchr/testify/require" +) + +func TestOwnerID_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualOwnerIDs, []*refs.OwnerID{ + nil, + new(refs.OwnerID), + {Value: []byte{}}, + {Value: apitest.RandomBytes[[]byte]()}, + }) +} + +func TestContainerID_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualContainerIDs, []*refs.ContainerID{ + nil, + new(refs.ContainerID), + {Value: []byte{}}, + {Value: apitest.RandomBytes[[]byte]()}, + }) +} + +func TestObjectID_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualObjectIDs, []*refs.ObjectID{ + nil, + new(refs.ObjectID), + {Value: []byte{}}, + {Value: apitest.RandomBytes[[]byte]()}, + }) +} + +func TestAddress_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualObjectAddresses, []*refs.Address{ + nil, + new(refs.Address), + { + ContainerId: new(refs.ContainerID), + ObjectId: new(refs.ObjectID), + }, + { + ContainerId: &refs.ContainerID{Value: []byte{}}, + ObjectId: &refs.ObjectID{Value: []byte{}}, + }, + { + ContainerId: &refs.ContainerID{Value: apitest.RandomBytes[[]byte]()}, + ObjectId: &refs.ObjectID{Value: apitest.RandomBytes[[]byte]()}, + }, + }) +} + +func TestVersion_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualVersions, []*refs.Version{ + nil, + new(refs.Version), + {Major: apitest.RandomInteger[uint32]()}, + {Minor: apitest.RandomInteger[uint32]()}, + { + Major: apitest.RandomInteger[uint32](), + Minor: apitest.RandomInteger[uint32](), + }, + }) +} + +func TestSignature_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualSignatures, []*refs.Signature{ + nil, + new(refs.Signature), + {Key: []byte{}, Sign: []byte{}}, + { + Key: apitest.RandomBytes[[]byte](), + Sign: apitest.RandomBytes[[]byte](), + Scheme: apitest.RandomInteger[refs.SignatureScheme](), + }, + }) +} + +func TestSignatureRFC6979_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualSignaturesRFC6979, []*refs.SignatureRFC6979{ + nil, + new(refs.SignatureRFC6979), + {Key: []byte{}, Sign: []byte{}}, + { + Key: apitest.RandomBytes[[]byte](), + Sign: apitest.RandomBytes[[]byte](), + }, + }) +} + +func TestChecksum_MarshalStable(t *testing.T) { + apitest.TestMarshalStable(t, apitest.AssertEqualChecksums, []*refs.Checksum{ + nil, + new(refs.Checksum), + {Sum: []byte{}}, + { + Type: apitest.RandomInteger[refs.ChecksumType](), + Sum: apitest.RandomBytes[[]byte](), + }, + }) +} + +func assertEqualSubnetIDs(t testing.TB, v1, v2 *refs.SubnetID, msg string) { + require.Equal(t, v1.GetValue(), v2.GetValue(), msg) +} + +func TestSubnetID(t *testing.T) { + apitest.TestMarshalStable(t, assertEqualSubnetIDs, []*refs.SubnetID{ + nil, + new(refs.SubnetID), + {Value: apitest.RandomInteger[uint32]()}, + }) +} diff --git a/api/reputation/encoding.go b/api/reputation/encoding.go new file mode 100644 index 00000000..1dfd5e77 --- /dev/null +++ b/api/reputation/encoding.go @@ -0,0 +1,193 @@ +package reputation + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldPeerPubKey +) + +// MarshaledSize returns size of the PeerID in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *PeerID) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldPeerPubKey, x.PublicKey) + } + return sz +} + +// MarshalStable writes the PeerID in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [PeerID.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *PeerID) MarshalStable(b []byte) { + if x != nil { + proto.MarshalToBytes(b, fieldPeerPubKey, x.PublicKey) + } +} + +const ( + _ = iota + fieldTrustPeer + fieldTrustValue +) + +// MarshaledSize returns size of the Trust in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Trust) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldTrustPeer, x.Peer) + + proto.SizeDouble(fieldTrustValue, x.Value) + } + return sz +} + +// MarshalStable writes the Trust in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Trust.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Trust) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldTrustPeer, x.Peer) + proto.MarshalToDouble(b[off:], fieldTrustValue, x.Value) + } +} + +const ( + _ = iota + fieldP2PTrustPeer + fieldP2PTrustValue +) + +// MarshaledSize returns size of the PeerToPeerTrust in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *PeerToPeerTrust) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldP2PTrustPeer, x.TrustingPeer) + + proto.SizeEmbedded(fieldP2PTrustValue, x.Trust) + } + return sz +} + +// MarshalStable writes the PeerToPeerTrust in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [PeerToPeerTrust.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *PeerToPeerTrust) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldP2PTrustPeer, x.TrustingPeer) + proto.MarshalToEmbedded(b[off:], fieldP2PTrustValue, x.Trust) + } +} + +const ( + _ = iota + fieldGlobalTrustBodyManager + fieldGlobalTrustBodyValue +) + +// MarshaledSize returns size of the GlobalTrust_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *GlobalTrust_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldGlobalTrustBodyManager, x.Manager) + + proto.SizeEmbedded(fieldGlobalTrustBodyValue, x.Trust) + } + return sz +} + +// MarshalStable writes the GlobalTrust_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [GlobalTrust_Body.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *GlobalTrust_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldGlobalTrustBodyManager, x.Manager) + proto.MarshalToEmbedded(b[off:], fieldGlobalTrustBodyValue, x.Trust) + } +} + +const ( + _ = iota + fieldAnnounceLocalReqEpoch + fieldAnnounceLocalReqTrusts +) + +// MarshaledSize returns size of the AnnounceLocalTrustRequest_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *AnnounceLocalTrustRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldAnnounceLocalReqEpoch, x.Epoch) + for i := range x.Trusts { + sz += proto.SizeEmbedded(fieldAnnounceLocalReqTrusts, x.Trusts[i]) + } + } + return sz +} + +// MarshalStable writes the AnnounceLocalTrustRequest_Body in Protocol Buffers +// V3 format with ascending order of fields by number into b. MarshalStable uses +// exactly [AnnounceLocalTrustRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *AnnounceLocalTrustRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldAnnounceLocalReqEpoch, x.Epoch) + for i := range x.Trusts { + off += proto.MarshalToEmbedded(b[off:], fieldAnnounceLocalReqTrusts, x.Trusts[i]) + } + } +} + +// MarshaledSize returns size of the AnnounceLocalTrustResponse_Body in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *AnnounceLocalTrustResponse_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the AnnounceLocalTrustResponse_Body in Protocol Buffers +// V3 format with ascending order of fields by number into b. MarshalStable uses +// exactly [AnnounceLocalTrustResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *AnnounceLocalTrustResponse_Body) MarshalStable([]byte) {} + +const ( + _ = iota + fieldAnnounceIntermediateReqEpoch + fieldAnnounceIntermediateReqIter + fieldAnnounceIntermediateReqTrust +) + +// MarshaledSize returns size of the AnnounceIntermediateResultRequest_Body in +// Protocol Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *AnnounceIntermediateResultRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldAnnounceIntermediateReqEpoch, x.Epoch) + + proto.SizeVarint(fieldAnnounceIntermediateReqIter, x.Iteration) + + proto.SizeEmbedded(fieldAnnounceIntermediateReqTrust, x.Trust) + } + return sz +} + +// MarshalStable writes the AnnounceIntermediateResultRequest_Body in Protocol +// Buffers V3 format with ascending order of fields by number into b. +// MarshalStable uses exactly +// [AnnounceIntermediateResultRequest_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *AnnounceIntermediateResultRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldAnnounceIntermediateReqEpoch, x.Epoch) + off += proto.MarshalToVarint(b[off:], fieldAnnounceIntermediateReqIter, x.Iteration) + proto.MarshalToEmbedded(b[off:], fieldAnnounceIntermediateReqIter, x.Trust) + } +} + +// MarshaledSize returns size of the AnnounceIntermediateResultResponse_Body in +// Protocol Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *AnnounceIntermediateResultResponse_Body) MarshaledSize() int { return 0 } + +// MarshalStable writes the AnnounceIntermediateResultResponse_Body in Protocol +// Buffers V3 format with ascending order of fields by number into b. +// MarshalStable uses exactly +// [AnnounceIntermediateResultResponse_Body.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *AnnounceIntermediateResultResponse_Body) MarshalStable([]byte) {} diff --git a/api/reputation/encoding_test.go b/api/reputation/encoding_test.go new file mode 100644 index 00000000..8521eba5 --- /dev/null +++ b/api/reputation/encoding_test.go @@ -0,0 +1,3 @@ +package reputation_test + +// TODO diff --git a/api/session/encoding.go b/api/session/encoding.go new file mode 100644 index 00000000..755785c0 --- /dev/null +++ b/api/session/encoding.go @@ -0,0 +1,456 @@ +package session + +import ( + "fmt" + + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +const ( + _ = iota + fieldTokenObjectTargetContainer + fieldTokenObjectTargetIDs +) + +// MarshaledSize returns size of the ObjectSessionContext_Target in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *ObjectSessionContext_Target) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldTokenObjectTargetContainer, x.Container) + for i := range x.Objects { + sz += proto.SizeEmbedded(fieldTokenObjectTargetIDs, x.Objects[i]) + } + } + return sz +} + +// MarshalStable writes the ObjectSessionContext_Target in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [ObjectSessionContext_Target.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *ObjectSessionContext_Target) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldTokenObjectTargetContainer, x.Container) + for i := range x.Objects { + off += proto.MarshalToEmbedded(b[off:], fieldTokenObjectTargetIDs, x.Objects[i]) + } + } +} + +const ( + _ = iota + fieldTokenObjectVerb + fieldTokenObjectTarget +) + +// MarshaledSize returns size of the ObjectSessionContext in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *ObjectSessionContext) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldTokenObjectVerb, int32(x.Verb)) + + proto.SizeEmbedded(fieldTokenObjectTarget, x.Target) + } + return sz +} + +// MarshalStable writes the ObjectSessionContext in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [ObjectSessionContext.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *ObjectSessionContext) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldTokenObjectVerb, int32(x.Verb)) + proto.MarshalToEmbedded(b[off:], fieldTokenObjectTarget, x.Target) + } +} + +const ( + _ = iota + fieldTokenContainerVerb + fieldTokenContainerWildcard + fieldTokenContainerID +) + +// MarshaledSize returns size of the ContainerSessionContext in Protocol Buffers +// V3 format in bytes. MarshaledSize is NPE-safe. +func (x *ContainerSessionContext) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldTokenContainerVerb, int32(x.Verb)) + + proto.SizeBool(fieldTokenContainerWildcard, x.Wildcard) + + proto.SizeEmbedded(fieldTokenContainerID, x.ContainerId) + } + return sz +} + +// MarshalStable writes the ContainerSessionContext in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [ContainerSessionContext.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *ContainerSessionContext) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldTokenContainerVerb, int32(x.Verb)) + off += proto.MarshalToBool(b[off:], fieldTokenContainerWildcard, x.Wildcard) + proto.MarshalToEmbedded(b[off:], fieldTokenContainerID, x.ContainerId) + } +} + +const ( + _ = iota + fieldTokenExp + fieldTokenNbf + fieldTokenIat +) + +// MarshaledSize returns size of the SessionToken_Body_TokenLifetime in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *SessionToken_Body_TokenLifetime) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldTokenExp, x.Exp) + + proto.SizeVarint(fieldTokenNbf, x.Nbf) + + proto.SizeVarint(fieldTokenIat, x.Iat) + + } + return sz +} + +// MarshalStable writes the SessionToken_Body_TokenLifetime in Protocol Buffers +// V3 format with ascending order of fields by number into b. MarshalStable uses +// exactly [SessionToken_Body_TokenLifetime.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *SessionToken_Body_TokenLifetime) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldTokenExp, x.Exp) + off += proto.MarshalToVarint(b[off:], fieldTokenNbf, x.Nbf) + proto.MarshalToVarint(b[off:], fieldTokenIat, x.Iat) + } +} + +const ( + _ = iota + fieldTokenID + fieldTokenOwner + fieldTokenLifetime + fieldTokenSessionKey + fieldTokenContextObject + fieldTokenContextContainer +) + +// MarshaledSize returns size of the SessionToken_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *SessionToken_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldTokenID, x.Id) + + proto.SizeEmbedded(fieldTokenOwner, x.OwnerId) + + proto.SizeEmbedded(fieldTokenLifetime, x.Lifetime) + + proto.SizeBytes(fieldTokenSessionKey, x.SessionKey) + switch c := x.Context.(type) { + default: + panic(fmt.Sprintf("unexpected context %T", x.Context)) + case nil: + case *SessionToken_Body_Object: + sz += proto.SizeEmbedded(fieldTokenContextObject, c.Object) + case *SessionToken_Body_Container: + sz += proto.SizeEmbedded(fieldTokenContextContainer, c.Container) + } + } + return sz +} + +// MarshalStable writes the SessionToken_Body in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [SessionToken_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *SessionToken_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldTokenID, x.Id) + off += proto.MarshalToEmbedded(b[off:], fieldTokenOwner, x.OwnerId) + off += proto.MarshalToEmbedded(b[off:], fieldTokenLifetime, x.Lifetime) + off += proto.MarshalToBytes(b[off:], fieldTokenSessionKey, x.SessionKey) + switch c := x.Context.(type) { + default: + panic(fmt.Sprintf("unexpected context %T", x.Context)) + case nil: + case *SessionToken_Body_Object: + proto.MarshalToEmbedded(b[off:], fieldTokenContextObject, c.Object) + case *SessionToken_Body_Container: + proto.MarshalToEmbedded(b[off:], fieldTokenContextContainer, c.Container) + } + } +} + +const ( + _ = iota + fieldTokenBody + fieldTokenSignature +) + +// MarshaledSize returns size of the SessionToken in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *SessionToken) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldTokenBody, x.Body) + + proto.SizeEmbedded(fieldTokenSignature, x.Signature) + } + return sz +} + +// MarshalStable writes the SessionToken in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [SessionToken.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *SessionToken) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldTokenBody, x.Body) + proto.MarshalToEmbedded(b[off:], fieldTokenSignature, x.Signature) + } +} + +const ( + _ = iota + fieldCreateReqUser + fieldCreateReqExp +) + +// MarshaledSize returns size of the CreateRequest_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *CreateRequest_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldCreateReqUser, x.OwnerId) + + proto.SizeVarint(fieldCreateReqExp, x.Expiration) + } + return sz +} + +// MarshalStable writes the CreateRequest_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [CreateRequest_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *CreateRequest_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldCreateReqUser, x.OwnerId) + proto.MarshalToVarint(b[off:], fieldCreateReqExp, x.Expiration) + } +} + +const ( + _ = iota + fieldCreateRespID + fieldCreateRespSessionKey +) + +// MarshaledSize returns size of the CreateResponse_Body in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *CreateResponse_Body) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldCreateRespID, x.Id) + + proto.SizeBytes(fieldCreateRespSessionKey, x.SessionKey) + } + return sz +} + +// MarshalStable writes the CreateResponse_Body in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [CreateResponse_Body.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *CreateResponse_Body) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldCreateRespID, x.Id) + proto.MarshalToBytes(b[off:], fieldCreateRespSessionKey, x.SessionKey) + } +} + +const ( + _ = iota + fieldXHeaderKey + fieldXHeaderValue +) + +// MarshaledSize returns size of the XHeader in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *XHeader) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeBytes(fieldXHeaderKey, x.Key) + + proto.SizeBytes(fieldXHeaderValue, x.Value) + } + return sz +} + +// MarshalStable writes the XHeader in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [XHeader.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *XHeader) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToBytes(b, fieldXHeaderKey, x.Key) + proto.MarshalToBytes(b[off:], fieldXHeaderValue, x.Value) + } +} + +const ( + _ = iota + fieldReqMetaVersion + fieldReqMetaEpoch + fieldReqMetaTTL + fieldReqMetaXHeaders + fieldReqMetaSession + fieldReqMetaBearer + fieldReqMetaOrigin + fieldReqMetaNetMagic +) + +// MarshaledSize returns size of the RequestMetaHeader in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *RequestMetaHeader) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldReqMetaVersion, x.Version) + + proto.SizeVarint(fieldReqMetaEpoch, x.Epoch) + + proto.SizeVarint(fieldReqMetaTTL, x.Ttl) + + proto.SizeEmbedded(fieldReqMetaSession, x.SessionToken) + + proto.SizeEmbedded(fieldReqMetaBearer, x.BearerToken) + + proto.SizeEmbedded(fieldReqMetaOrigin, x.Origin) + + proto.SizeVarint(fieldReqMetaNetMagic, x.MagicNumber) + for i := range x.XHeaders { + sz += proto.SizeEmbedded(fieldReqMetaXHeaders, x.XHeaders[i]) + } + } + return sz +} + +// MarshalStable writes the RequestMetaHeader in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [RequestMetaHeader.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *RequestMetaHeader) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldReqMetaVersion, x.Version) + off += proto.MarshalToVarint(b[off:], fieldReqMetaEpoch, x.Epoch) + off += proto.MarshalToVarint(b[off:], fieldReqMetaTTL, x.Ttl) + for i := range x.XHeaders { + off += proto.MarshalToEmbedded(b[off:], fieldReqMetaXHeaders, x.XHeaders[i]) + } + off += proto.MarshalToEmbedded(b[off:], fieldReqMetaSession, x.SessionToken) + off += proto.MarshalToEmbedded(b[off:], fieldReqMetaBearer, x.BearerToken) + off += proto.MarshalToEmbedded(b[off:], fieldReqMetaOrigin, x.Origin) + off += proto.MarshalToVarint(b[off:], fieldReqMetaNetMagic, x.MagicNumber) + } +} + +const ( + _ = iota + fieldRespMetaVersion + fieldRespMetaEpoch + fieldRespMetaTTL + fieldRespMetaXHeaders + fieldRespMetaOrigin + fieldRespMetaStatus +) + +// MarshaledSize returns size of the ResponseMetaHeader in Protocol Buffers V3 +// format in bytes. MarshaledSize is NPE-safe. +func (x *ResponseMetaHeader) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldRespMetaVersion, x.Version) + + proto.SizeVarint(fieldRespMetaEpoch, x.Epoch) + + proto.SizeVarint(fieldRespMetaTTL, x.Ttl) + + proto.SizeEmbedded(fieldRespMetaOrigin, x.Origin) + + proto.SizeEmbedded(fieldRespMetaStatus, x.Status) + for i := range x.XHeaders { + sz += proto.SizeEmbedded(fieldRespMetaXHeaders, x.XHeaders[i]) + } + } + return sz +} + +// MarshalStable writes the ResponseMetaHeader in Protocol Buffers V3 format +// with ascending order of fields by number into b. MarshalStable uses exactly +// [ResponseMetaHeader.MarshaledSize] first bytes of b. MarshalStable is +// NPE-safe. +func (x *ResponseMetaHeader) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldRespMetaVersion, x.Version) + off += proto.MarshalToVarint(b[off:], fieldRespMetaEpoch, x.Epoch) + off += proto.MarshalToVarint(b[off:], fieldRespMetaTTL, x.Ttl) + for i := range x.XHeaders { + off += proto.MarshalToEmbedded(b[off:], fieldRespMetaXHeaders, x.XHeaders[i]) + } + off += proto.MarshalToEmbedded(b[off:], fieldRespMetaOrigin, x.Origin) + off += proto.MarshalToEmbedded(b[off:], fieldRespMetaStatus, x.Status) + } +} + +const ( + _ = iota + fieldReqVerifyBodySignature + fieldReqVerifyMetaSignature + fieldReqVerifyOriginSignature + fieldReqVerifyOrigin +) + +// MarshaledSize returns size of the RequestVerificationHeader in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *RequestVerificationHeader) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldReqVerifyBodySignature, x.BodySignature) + + proto.SizeEmbedded(fieldReqVerifyMetaSignature, x.MetaSignature) + + proto.SizeEmbedded(fieldReqVerifyOriginSignature, x.OriginSignature) + + proto.SizeEmbedded(fieldReqVerifyOrigin, x.Origin) + } + return sz +} + +// MarshalStable writes the RequestVerificationHeader in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [RequestVerificationHeader.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *RequestVerificationHeader) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldReqVerifyBodySignature, x.BodySignature) + off += proto.MarshalToEmbedded(b[off:], fieldReqVerifyMetaSignature, x.MetaSignature) + off += proto.MarshalToEmbedded(b[off:], fieldReqVerifyOriginSignature, x.OriginSignature) + proto.MarshalToEmbedded(b[off:], fieldReqVerifyOrigin, x.Origin) + } +} + +const ( + _ = iota + fieldRespVerifyBodySignature + fieldRespVerifyMetaSignature + fieldRespVerifyOriginSignature + fieldRespVerifyOrigin +) + +// MarshaledSize returns size of the ResponseVerificationHeader in Protocol +// Buffers V3 format in bytes. MarshaledSize is NPE-safe. +func (x *ResponseVerificationHeader) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldRespVerifyBodySignature, x.BodySignature) + + proto.SizeEmbedded(fieldRespVerifyMetaSignature, x.MetaSignature) + + proto.SizeEmbedded(fieldRespVerifyOriginSignature, x.OriginSignature) + + proto.SizeEmbedded(fieldRespVerifyOrigin, x.Origin) + } + return sz +} + +// MarshalStable writes the ResponseVerificationHeader in Protocol Buffers V3 +// format with ascending order of fields by number into b. MarshalStable uses +// exactly [ResponseVerificationHeader.MarshaledSize] first bytes of b. +// MarshalStable is NPE-safe. +func (x *ResponseVerificationHeader) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldRespVerifyBodySignature, x.BodySignature) + off += proto.MarshalToEmbedded(b[off:], fieldRespVerifyMetaSignature, x.MetaSignature) + off += proto.MarshalToEmbedded(b[off:], fieldRespVerifyOriginSignature, x.OriginSignature) + proto.MarshalToEmbedded(b[off:], fieldRespVerifyOrigin, x.Origin) + } +} diff --git a/api/session/encoding_test.go b/api/session/encoding_test.go new file mode 100644 index 00000000..81f09f28 --- /dev/null +++ b/api/session/encoding_test.go @@ -0,0 +1,3 @@ +package session_test + +// TODO diff --git a/api/status/encoding.go b/api/status/encoding.go new file mode 100644 index 00000000..1a185146 --- /dev/null +++ b/api/status/encoding.go @@ -0,0 +1,66 @@ +package status + +import ( + "github.com/nspcc-dev/neofs-sdk-go/internal/proto" +) + +const ( + _ = iota + fieldDetailID + fieldDetailValue +) + +// MarshaledSize returns size of the Status_Detail in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *Status_Detail) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldDetailID, x.Id) + + proto.SizeBytes(fieldDetailValue, x.Value) + } + return sz +} + +// MarshalStable writes the Status_Detail in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Status_Detail.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Status_Detail) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldDetailID, x.Id) + proto.MarshalToBytes(b[off:], fieldDetailValue, x.Value) + } +} + +const ( + _ = iota + fieldStatusCode + fieldStatusMessage + fieldStatusDetails +) + +// MarshaledSize returns size of the Status in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Status) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldStatusCode, x.Code) + + proto.SizeBytes(fieldStatusMessage, x.Message) + for i := range x.Details { + sz += proto.SizeEmbedded(fieldStatusDetails, x.Details[i]) + } + } + return sz +} + +// MarshalStable writes the Status in Protocol Buffers V3 format with ascending +// order of fields by number into b. MarshalStable uses exactly +// [Status.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Status) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldStatusCode, x.Code) + off += proto.MarshalToBytes(b[off:], fieldStatusMessage, x.Message) + for i := range x.Details { + off += proto.MarshalToEmbedded(b[off:], fieldStatusDetails, x.Details[i]) + } + } +} diff --git a/api/status/encoding_test.go b/api/status/encoding_test.go new file mode 100644 index 00000000..99cdcf04 --- /dev/null +++ b/api/status/encoding_test.go @@ -0,0 +1,3 @@ +package status_test + +// TODO diff --git a/api/storagegroup/encoding.go b/api/storagegroup/encoding.go new file mode 100644 index 00000000..b25adad4 --- /dev/null +++ b/api/storagegroup/encoding.go @@ -0,0 +1,40 @@ +package storagegroup + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldStorageGroupSize + fieldStorageGroupHash + fieldStorageGroupExp + fieldStorageGroupMembers +) + +// MarshaledSize returns size of the StorageGroup in Protocol Buffers V3 format +// in bytes. MarshaledSize is NPE-safe. +func (x *StorageGroup) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldStorageGroupSize, x.ValidationDataSize) + sz += proto.SizeEmbedded(fieldStorageGroupHash, x.ValidationHash) + sz += proto.SizeVarint(fieldStorageGroupExp, x.ExpirationEpoch) + for i := range x.Members { + sz += proto.SizeEmbedded(fieldStorageGroupMembers, x.Members[i]) + } + } + return sz +} + +// MarshalStable writes the StorageGroup in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [StorageGroup.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *StorageGroup) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldStorageGroupSize, x.ValidationDataSize) + off += proto.MarshalToEmbedded(b[off:], fieldStorageGroupHash, x.ValidationHash) + off += proto.MarshalToVarint(b[off:], fieldStorageGroupExp, x.ExpirationEpoch) + for i := range x.Members { + off += proto.MarshalToEmbedded(b[off:], fieldStorageGroupMembers, x.Members[i]) + } + } +} diff --git a/api/storagegroup/encoding_test.go b/api/storagegroup/encoding_test.go new file mode 100644 index 00000000..f47fab4d --- /dev/null +++ b/api/storagegroup/encoding_test.go @@ -0,0 +1,3 @@ +package storagegroup_test + +// TODO diff --git a/api/subnet/encoding.go b/api/subnet/encoding.go new file mode 100644 index 00000000..255221eb --- /dev/null +++ b/api/subnet/encoding.go @@ -0,0 +1,30 @@ +package subnet + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldSubnetInfoID + fieldSubnetInfoOwner +) + +// MarshaledSize returns size of the SubnetInfo in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *SubnetInfo) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeEmbedded(fieldSubnetInfoID, x.Id) + sz += proto.SizeEmbedded(fieldSubnetInfoOwner, x.Owner) + } + return sz +} + +// MarshalStable writes the SubnetInfo in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [SubnetInfo.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *SubnetInfo) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToEmbedded(b, fieldSubnetInfoID, x.Id) + proto.MarshalToEmbedded(b[off:], fieldSubnetInfoOwner, x.Owner) + } +} diff --git a/api/subnet/encoding_test.go b/api/subnet/encoding_test.go new file mode 100644 index 00000000..fb683660 --- /dev/null +++ b/api/subnet/encoding_test.go @@ -0,0 +1,3 @@ +package subnet_test + +// TODO diff --git a/api/tombstone/encoding.go b/api/tombstone/encoding.go new file mode 100644 index 00000000..accc5d02 --- /dev/null +++ b/api/tombstone/encoding.go @@ -0,0 +1,37 @@ +package tombstone + +import "github.com/nspcc-dev/neofs-sdk-go/internal/proto" + +const ( + _ = iota + fieldTombstoneExp + fieldTombstoneSplitID + fieldTombstoneMembers +) + +// MarshaledSize returns size of the Tombstone in Protocol Buffers V3 format in +// bytes. MarshaledSize is NPE-safe. +func (x *Tombstone) MarshaledSize() int { + var sz int + if x != nil { + sz = proto.SizeVarint(fieldTombstoneExp, x.ExpirationEpoch) + sz += proto.SizeBytes(fieldTombstoneSplitID, x.SplitId) + for i := range x.Members { + sz += proto.SizeEmbedded(fieldTombstoneMembers, x.Members[i]) + } + } + return sz +} + +// MarshalStable writes the Tombstone in Protocol Buffers V3 format with +// ascending order of fields by number into b. MarshalStable uses exactly +// [Tombstone.MarshaledSize] first bytes of b. MarshalStable is NPE-safe. +func (x *Tombstone) MarshalStable(b []byte) { + if x != nil { + off := proto.MarshalToVarint(b, fieldTombstoneExp, x.ExpirationEpoch) + off += proto.MarshalToBytes(b[off:], fieldTombstoneSplitID, x.SplitId) + for i := range x.Members { + off += proto.MarshalToEmbedded(b[off:], fieldTombstoneMembers, x.Members[i]) + } + } +} diff --git a/api/tombstone/encoding_test.go b/api/tombstone/encoding_test.go new file mode 100644 index 00000000..03913b48 --- /dev/null +++ b/api/tombstone/encoding_test.go @@ -0,0 +1,3 @@ +package tombstone_test + +// TODO