[#69] object: Initial EC implementation

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-03-19 09:55:23 +03:00
parent a85146250b
commit 1772b92182
30 changed files with 1240 additions and 613 deletions

View file

@ -26,6 +26,12 @@ const (
splitHdrChildrenField = 5
splitHdrSplitIDField = 6
ecHdrParentField = 1
ecHdrIndexField = 2
ecHdrTotalField = 3
ecHdrHeaderLengthField = 4
ecHdrHeaderField = 5
hdrVersionField = 1
hdrContainerIDField = 2
hdrOwnerIDField = 3
@ -37,6 +43,7 @@ const (
hdrSessionTokenField = 9
hdrAttributesField = 10
hdrSplitField = 11
hdrECField = 12
hdrWithSigHeaderField = 1
hdrWithSigSignatureField = 2
@ -229,6 +236,43 @@ func (h *SplitHeader) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.Header_Split))
}
func (h *ECHeader) StableMarshal(buf []byte) []byte {
if h == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, h.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(ecHdrParentField, buf[offset:], h.Parent)
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)
return buf
}
func (h *ECHeader) StableSize() (size int) {
if h == nil {
return 0
}
size += proto.NestedStructureSize(ecHdrParentField, h.Parent)
size += proto.UInt32Size(ecHdrIndexField, h.Index)
size += proto.UInt32Size(ecHdrTotalField, h.Total)
size += proto.UInt32Size(ecHdrHeaderLengthField, h.HeaderLength)
size += proto.BytesSize(ecHdrHeaderField, h.Header)
return size
}
func (h *ECHeader) Unmarshal(data []byte) error {
return message.Unmarshal(h, data, new(object.Header_EC))
}
func (h *Header) StableMarshal(buf []byte) []byte {
if h == nil {
return []byte{}
@ -255,6 +299,7 @@ func (h *Header) StableMarshal(buf []byte) []byte {
}
proto.NestedStructureMarshal(hdrSplitField, buf[offset:], h.split)
proto.NestedStructureMarshal(hdrECField, buf[offset:], h.ec)
return buf
}
@ -277,6 +322,7 @@ func (h *Header) StableSize() (size int) {
size += proto.NestedStructureSize(hdrAttributesField, &h.attr[i])
}
size += proto.NestedStructureSize(hdrSplitField, h.split)
size += proto.NestedStructureSize(hdrECField, h.ec)
return size
}