Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eacl/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestConstructTable(t *testing.T) {
require.Equal(t, anyValidRecords, tbl.Records())
require.Zero(t, tbl.GetCID())
require.EqualValues(t, 2, tbl.Version().Major())
require.EqualValues(t, 26, tbl.Version().Minor())
require.EqualValues(t, 27, tbl.Version().Minor())
}

func TestNewTableForContainer(t *testing.T) {
Expand All @@ -252,5 +252,5 @@ func TestNewTableForContainer(t *testing.T) {
cnr2 := tbl.GetCID()
require.Equal(t, cnr, cnr2)
require.EqualValues(t, 2, tbl.Version().Major())
require.EqualValues(t, 26, tbl.Version().Minor())
require.EqualValues(t, 27, tbl.Version().Minor())
}
2 changes: 1 addition & 1 deletion proto/accounting/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions proto/accounting/service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/accounting/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/acl/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/audit/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/container/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions proto/container/service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion proto/container/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/link/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/lock/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/netmap/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions proto/netmap/service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/netmap/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions proto/object/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,3 +1293,73 @@ const (
FieldReplicateResponseStatus
FieldReplicateResponseObjectSignature
)

// Field numbers of [ReplicateV2Request_Init] message.
const (
_ = iota
FieldReplicateV2RequestInitObject
FieldReplicateV2RequestInitSignature
FieldReplicateV2RequestInitSignObject
)

// CalculateReplicateV2InitLength calculates length of ReplicateV2 request oneof
// init message with given fields.
func CalculateReplicateV2InitLength(objLen int, sigLen int, signObject bool) int {
ln := protoencoding.SizeEmbeddedLENField(FieldReplicateV2RequestInitObject, objLen)
ln += protoencoding.SizeEmbeddedLENField(FieldReplicateV2RequestInitSignature, sigLen)
ln += protoencoding.SizeBool(FieldReplicateV2RequestInitSignObject, signObject)
return ln
}

// WriteReplicateV2Init writes ReplicateV2 request init oneof field with given
// fields into buf. Returns number of bytes written.
func WriteReplicateV2Init(buf []byte, objLen int, writeObjFn protoencoding.WriteMessageFunc, sigLen int, writeSigFn protoencoding.WriteMessageFunc, signObject bool) int {
off := protoencoding.WriteMessageField(buf, FieldReplicateV2RequestInitObject, objLen, writeObjFn)
off += protoencoding.WriteMessageField(buf[off:], FieldReplicateV2RequestInitSignature, sigLen, writeSigFn)
off += protoencoding.MarshalToBool(buf[off:], FieldReplicateV2RequestInitSignObject, signObject)
return off
}

// Field numbers of [ReplicateV2Request] message.
const (
_ = iota
FieldReplicateV2RequestInit
FieldReplicateV2RequestChunk
)

// CalculateReplicateV2InitRequestLength calculates length of initial
// ReplicateV2 request message with given fields.
func CalculateReplicateV2InitRequestLength(initLen int) int {
return protoencoding.SizeEmbeddedLENField(FieldReplicateV2RequestInit, initLen)
}

// CalculateReplicateV2ChunkRequestLength calculates length of chunk ReplicateV2
// request message with given fields.
func CalculateReplicateV2ChunkRequestLength(chunk []byte) int {
return protoencoding.SizeBytes(FieldReplicateV2RequestChunk, chunk)
}

// WriteReplicateV2InitRequest writes initial ReplicateV2 request with given
// fields into buf. Returns number of bytes written.
func WriteReplicateV2InitRequest(buf []byte, objLen int, writeObjFn protoencoding.WriteMessageFunc, nodeSigLen int, writeNodeSigFn protoencoding.WriteMessageFunc, signObject bool) int {
ln := CalculateReplicateV2InitLength(objLen, nodeSigLen, signObject)
if ln == 0 {
return 0
}
off := protoencoding.WriteTagAndLength(buf, FieldReplicateV2RequestInit, ln)
off += WriteReplicateV2Init(buf[off:], objLen, writeObjFn, nodeSigLen, writeNodeSigFn, signObject)
return off
}

// WriteReplicateV2ChunkRequest writes chunk ReplicateV2 request with given
// length and fields into buf. Returns number of bytes written.
func WriteReplicateV2ChunkRequest(buf []byte, chunk []byte) int {
return protoencoding.MarshalToBytes(buf, FieldReplicateV2RequestChunk, chunk)
}

// Field numbers of [ReplicateV2Response] message.
const (
_ = iota
FieldReplicateV2ResponseStatus
FieldReplicateV2ResponseObjectSignature
)
57 changes: 57 additions & 0 deletions proto/object/encoding_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package object_test

import (
"bytes"
"testing"

"github.com/nspcc-dev/neofs-sdk-go/internal/testutil"
protoencoding "github.com/nspcc-dev/neofs-sdk-go/proto/encoding"
prototest "github.com/nspcc-dev/neofs-sdk-go/proto/internal/test"
"github.com/nspcc-dev/neofs-sdk-go/proto/object"
"github.com/nspcc-dev/neofs-sdk-go/proto/refs"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)

// returns random object.Range with all non-zero fields.
Expand Down Expand Up @@ -469,3 +472,57 @@ func TestSearchV2Response_Body_MarshalStable(t *testing.T) {
},
})
}

func TestWriteReplicateV2InitRequest(t *testing.T) {
obj := &object.Object{
ObjectId: prototest.RandObjectID(),
Signature: prototest.RandSignature(),
Header: randHeader(),
}
objHdrLen := obj.MarshaledSize()
sig := prototest.RandSignature()
sigLen := sig.MarshaledSize()
const signObject = true

initLen := object.CalculateReplicateV2InitLength(objHdrLen, sigLen, signObject)

ln := object.CalculateReplicateV2InitRequestLength(initLen)

buf := make([]byte, ln)

writeObjFn := protoencoding.WriteStablyMarshalledMessageFunc(obj)
writeSigFn := protoencoding.WriteStablyMarshalledMessageFunc(sig)

n := object.WriteReplicateV2InitRequest(buf, objHdrLen, writeObjFn, sigLen, writeSigFn, signObject)

require.EqualValues(t, ln, n)

var req object.ReplicateV2Request
require.NoError(t, proto.Unmarshal(buf, &req))

init := req.GetInit()
require.NotNil(t, init)

require.True(t, proto.Equal(obj, init.Object))
require.True(t, proto.Equal(sig, init.Signature))
require.EqualValues(t, signObject, init.SignObject)
}

func TestWriteReplicateV2ChunkRequest(t *testing.T) {
chunk := testutil.RandByteSlice(1024)

ln := object.CalculateReplicateV2ChunkRequestLength(chunk)

buf := make([]byte, ln)

n := object.WriteReplicateV2ChunkRequest(buf, chunk)

require.EqualValues(t, ln, n)

var req object.ReplicateV2Request
require.NoError(t, proto.Unmarshal(buf, &req))

gotChunk := req.GetPayloadChunk()
require.NotNil(t, gotChunk)
require.True(t, bytes.Equal(chunk, gotChunk))
}
Loading
Loading