[#209] v2/object: Add splitID to unified structure

* Add getters/setters
* Support stable marshaling
* Support converters

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-11-24 20:14:03 +03:00 committed by Alex Vanin
parent d441193952
commit b9778464b9
4 changed files with 29 additions and 0 deletions

View file

@ -135,6 +135,8 @@ func SplitHeaderToGRPCMessage(h *SplitHeader) *object.Header_Split {
m.SetChildren(childMsg) m.SetChildren(childMsg)
m.SetSplitId(h.GetSplitID())
return m return m
} }
@ -170,6 +172,8 @@ func SplitHeaderFromGRPCMessage(m *object.Header_Split) *SplitHeader {
h.SetChildren(children) h.SetChildren(children)
h.SetSplitID(m.GetSplitId())
return h return h
} }

View file

@ -21,6 +21,7 @@ const (
splitHdrParentSignatureField = 3 splitHdrParentSignatureField = 3
splitHdrParentHeaderField = 4 splitHdrParentHeaderField = 4
splitHdrChildrenField = 5 splitHdrChildrenField = 5
splitHdrSplitIDField = 6
hdrVersionField = 1 hdrVersionField = 1
hdrContainerIDField = 2 hdrContainerIDField = 2
@ -275,6 +276,11 @@ func (h *SplitHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
} }
_, err = proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID)
if err != nil {
return nil, err
}
return buf, nil return buf, nil
} }
@ -292,6 +298,8 @@ func (h *SplitHeader) StableSize() (size int) {
size += proto.NestedStructureSize(splitHdrChildrenField, h.children[i]) size += proto.NestedStructureSize(splitHdrChildrenField, h.children[i])
} }
size += proto.BytesSize(splitHdrSplitIDField, h.splitID)
return size return size
} }

View file

@ -461,6 +461,7 @@ func generateSplit(sig string) *object.SplitHeader {
split.SetParent(generateObjectID("Parent")) split.SetParent(generateObjectID("Parent"))
split.SetParentSignature(generateSignature("Key", sig)) split.SetParentSignature(generateSignature("Key", sig))
split.SetPrevious(generateObjectID("Previous")) split.SetPrevious(generateObjectID("Previous"))
split.SetSplitID([]byte("UUIDv4"))
return split return split
} }

View file

@ -33,6 +33,8 @@ type SplitHeader struct {
parHdr *Header parHdr *Header
children []*refs.ObjectID children []*refs.ObjectID
splitID []byte
} }
type Header struct { type Header struct {
@ -380,6 +382,20 @@ func (h *SplitHeader) SetChildren(v []*refs.ObjectID) {
} }
} }
func (h *SplitHeader) GetSplitID() []byte {
if h != nil {
return h.splitID
}
return nil
}
func (h *SplitHeader) SetSplitID(v []byte) {
if h != nil {
h.splitID = v
}
}
func (h *Header) GetVersion() *refs.Version { func (h *Header) GetVersion() *refs.Version {
if h != nil { if h != nil {
return h.version return h.version