forked from TrueCloudLab/frostfs-api-go
[#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:
parent
d441193952
commit
b9778464b9
4 changed files with 29 additions and 0 deletions
|
@ -135,6 +135,8 @@ func SplitHeaderToGRPCMessage(h *SplitHeader) *object.Header_Split {
|
|||
|
||||
m.SetChildren(childMsg)
|
||||
|
||||
m.SetSplitId(h.GetSplitID())
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
|
@ -170,6 +172,8 @@ func SplitHeaderFromGRPCMessage(m *object.Header_Split) *SplitHeader {
|
|||
|
||||
h.SetChildren(children)
|
||||
|
||||
h.SetSplitID(m.GetSplitId())
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ const (
|
|||
splitHdrParentSignatureField = 3
|
||||
splitHdrParentHeaderField = 4
|
||||
splitHdrChildrenField = 5
|
||||
splitHdrSplitIDField = 6
|
||||
|
||||
hdrVersionField = 1
|
||||
hdrContainerIDField = 2
|
||||
|
@ -275,6 +276,11 @@ func (h *SplitHeader) StableMarshal(buf []byte) ([]byte, error) {
|
|||
offset += n
|
||||
}
|
||||
|
||||
_, err = proto.BytesMarshal(splitHdrSplitIDField, buf[offset:], h.splitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
|
@ -292,6 +298,8 @@ func (h *SplitHeader) StableSize() (size int) {
|
|||
size += proto.NestedStructureSize(splitHdrChildrenField, h.children[i])
|
||||
}
|
||||
|
||||
size += proto.BytesSize(splitHdrSplitIDField, h.splitID)
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
|
|
|
@ -461,6 +461,7 @@ func generateSplit(sig string) *object.SplitHeader {
|
|||
split.SetParent(generateObjectID("Parent"))
|
||||
split.SetParentSignature(generateSignature("Key", sig))
|
||||
split.SetPrevious(generateObjectID("Previous"))
|
||||
split.SetSplitID([]byte("UUIDv4"))
|
||||
|
||||
return split
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ type SplitHeader struct {
|
|||
parHdr *Header
|
||||
|
||||
children []*refs.ObjectID
|
||||
|
||||
splitID []byte
|
||||
}
|
||||
|
||||
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 {
|
||||
if h != nil {
|
||||
return h.version
|
||||
|
|
Loading…
Reference in a new issue