diff --git a/object/convert.go b/object/convert.go index f19cc09..5b4acda 100644 --- a/object/convert.go +++ b/object/convert.go @@ -269,6 +269,8 @@ func (h *ECHeader) ToGRPCMessage() grpc.Message { m = new(object.Header_EC) m.Parent = h.Parent.ToGRPCMessage().(*refsGRPC.ObjectID) + m.ParentSplitId = h.ParentSplitID + m.ParentSplitIndex = h.ParentSplitIndex m.Index = h.Index m.Total = h.Total m.Header = h.Header @@ -300,6 +302,8 @@ func (h *ECHeader) FromGRPCMessage(m grpc.Message) error { } } + h.ParentSplitID = v.GetParentSplitId() + h.ParentSplitIndex = v.GetParentSplitIndex() h.Index = v.GetIndex() h.Total = v.GetTotal() h.Header = v.GetHeader() diff --git a/object/grpc/service.pb.go b/object/grpc/service.pb.go index 2bfb50b..75d359e 100644 Binary files a/object/grpc/service.pb.go and b/object/grpc/service.pb.go differ diff --git a/object/grpc/types.pb.go b/object/grpc/types.pb.go index 8f4f383..254e76d 100644 Binary files a/object/grpc/types.pb.go and b/object/grpc/types.pb.go differ diff --git a/object/marshal.go b/object/marshal.go index a8d399c..fa2de95 100644 --- a/object/marshal.go +++ b/object/marshal.go @@ -31,6 +31,8 @@ const ( ecHdrTotalField = 3 ecHdrHeaderLengthField = 4 ecHdrHeaderField = 5 + ecHdrParentSplitID = 6 + ecHdrParentSplitIndex = 7 hdrVersionField = 1 hdrContainerIDField = 2 @@ -260,7 +262,9 @@ func (h *ECHeader) StableMarshal(buf []byte) []byte { offset += proto.UInt32Marshal(ecHdrIndexField, buf[offset:], h.Index) offset += proto.UInt32Marshal(ecHdrTotalField, buf[offset:], h.Total) offset += proto.UInt32Marshal(ecHdrHeaderLengthField, buf[offset:], h.HeaderLength) - proto.BytesMarshal(ecHdrHeaderField, buf[offset:], h.Header) + offset += proto.BytesMarshal(ecHdrHeaderField, buf[offset:], h.Header) + offset += proto.BytesMarshal(ecHdrParentSplitID, buf[offset:], h.ParentSplitID) + proto.UInt32Marshal(ecHdrParentSplitIndex, buf[offset:], h.ParentSplitIndex) return buf } @@ -274,6 +278,8 @@ func (h *ECHeader) StableSize() (size int) { size += proto.UInt32Size(ecHdrTotalField, h.Total) size += proto.UInt32Size(ecHdrHeaderLengthField, h.HeaderLength) size += proto.BytesSize(ecHdrHeaderField, h.Header) + size += proto.BytesSize(ecHdrParentSplitID, h.ParentSplitID) + size += proto.UInt32Size(ecHdrParentSplitIndex, h.ParentSplitIndex) return size } diff --git a/object/message_test.go b/object/message_test.go index e675f49..749c373 100644 --- a/object/message_test.go +++ b/object/message_test.go @@ -13,7 +13,9 @@ func TestMessageConvert(t *testing.T) { func(empty bool) message.Message { return objecttest.GenerateShortHeader(empty) }, func(empty bool) message.Message { return objecttest.GenerateAttribute(empty) }, func(empty bool) message.Message { return objecttest.GenerateSplitHeader(empty) }, - func(empty bool) message.Message { return objecttest.GenerateHeader(empty) }, + func(empty bool) message.Message { return objecttest.GenerateHeaderWithSplitHeader(empty) }, + func(empty bool) message.Message { return objecttest.GenerateHeaderWithECHeader(empty) }, + func(empty bool) message.Message { return objecttest.GenerateECHeader(empty) }, func(empty bool) message.Message { return objecttest.GenerateObject(empty) }, func(empty bool) message.Message { return objecttest.GenerateSplitInfo(empty) }, func(empty bool) message.Message { return objecttest.GenerateECInfo(empty) }, diff --git a/object/test/generate.go b/object/test/generate.go index b107023..bb774cc 100644 --- a/object/test/generate.go +++ b/object/test/generate.go @@ -68,17 +68,41 @@ func generateSplitHeader(empty, withPar bool) *object.SplitHeader { m.SetParentSignature(refstest.GenerateSignature(empty)) if withPar { - m.SetParentHeader(generateHeader(empty, false)) + m.SetParentHeader(GenerateHeaderWithSplitHeader(empty)) } return m } -func GenerateHeader(empty bool) *object.Header { - return generateHeader(empty, true) +func GenerateHeaderWithSplitHeader(empty bool) *object.Header { + m := generateHeader(empty) + m.SetSplit(generateSplitHeader(empty, false)) + return m } -func generateHeader(empty, withSplit bool) *object.Header { +func GenerateHeaderWithECHeader(empty bool) *object.Header { + m := generateHeader(empty) + m.SetEC(GenerateECHeader(empty)) + return m +} + +func GenerateECHeader(empty bool) *object.ECHeader { + ech := new(object.ECHeader) + + if !empty { + ech.Parent = refstest.GenerateObjectID(empty) + ech.ParentSplitID = []byte{1, 2, 3} + ech.ParentSplitIndex = 1 + ech.Index = 0 + ech.Total = 2 + ech.Header = []byte("chunk of ec-encoded parent header") + ech.HeaderLength = uint32(2 * len(ech.Header)) + } + + return ech +} + +func generateHeader(empty bool) *object.Header { m := new(object.Header) if !empty { @@ -95,10 +119,6 @@ func generateHeader(empty, withSplit bool) *object.Header { m.SetHomomorphicHash(refstest.GenerateChecksum(empty)) m.SetSessionToken(sessiontest.GenerateSessionToken(empty)) - if withSplit { - m.SetSplit(generateSplitHeader(empty, false)) - } - return m } @@ -106,7 +126,7 @@ func GenerateHeaderWithSignature(empty bool) *object.HeaderWithSignature { m := new(object.HeaderWithSignature) m.SetSignature(refstest.GenerateSignature(empty)) - m.SetHeader(GenerateHeader(empty)) + m.SetHeader(GenerateHeaderWithSplitHeader(empty)) return m } @@ -120,7 +140,7 @@ func GenerateObject(empty bool) *object.Object { } m.SetSignature(refstest.GenerateSignature(empty)) - m.SetHeader(GenerateHeader(empty)) + m.SetHeader(GenerateHeaderWithSplitHeader(empty)) return m } @@ -194,7 +214,7 @@ func GenerateGetObjectPartInit(empty bool) *object.GetObjectPartInit { } m.SetSignature(refstest.GenerateSignature(empty)) - m.SetHeader(GenerateHeader(empty)) + m.SetHeader(GenerateHeaderWithSplitHeader(empty)) return m } @@ -248,7 +268,7 @@ func GeneratePutObjectPartInit(empty bool) *object.PutObjectPartInit { } m.SetSignature(refstest.GenerateSignature(empty)) - m.SetHeader(GenerateHeader(empty)) + m.SetHeader(GenerateHeaderWithSplitHeader(empty)) return m } diff --git a/object/types.go b/object/types.go index 4588f13..78c8d43 100644 --- a/object/types.go +++ b/object/types.go @@ -40,12 +40,14 @@ type SplitHeader struct { } type ECHeader struct { - Parent *refs.ObjectID - Index uint32 - Total uint32 - Header []byte - HeaderLength uint32 - Signature []byte + Parent *refs.ObjectID + ParentSplitID []byte + ParentSplitIndex uint32 + Index uint32 + Total uint32 + Header []byte + HeaderLength uint32 + Signature []byte } type Header struct {