From 1cab39337e40117378141f582aefaa7634338609 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 3 May 2023 13:58:42 +0300 Subject: [PATCH] [#27] object: Resolve funlen linter warnings Signed-off-by: Evgenii Stratonikov --- object/convert.go | 195 +++++++++++++++++++++++++--------------------- 1 file changed, 105 insertions(+), 90 deletions(-) diff --git a/object/convert.go b/object/convert.go index 95fde3cd..7099b4c4 100644 --- a/object/convert.go +++ b/object/convert.go @@ -292,102 +292,26 @@ func (h *Header) FromGRPCMessage(m grpc.Message) error { var err error - version := v.GetVersion() - if version == nil { - h.version = nil - } else { - if h.version == nil { - h.version = new(refs.Version) - } - - err = h.version.FromGRPCMessage(version) - if err != nil { - return err - } + if err := h.fillVersion(v); err != nil { + return err } - - payloadHash := v.GetPayloadHash() - if payloadHash == nil { - h.payloadHash = nil - } else { - if h.payloadHash == nil { - h.payloadHash = new(refs.Checksum) - } - - err = h.payloadHash.FromGRPCMessage(payloadHash) - if err != nil { - return err - } + if err := h.fillPayloadHash(v); err != nil { + return err } - - ownerID := v.GetOwnerId() - if ownerID == nil { - h.ownerID = nil - } else { - if h.ownerID == nil { - h.ownerID = new(refs.OwnerID) - } - - err = h.ownerID.FromGRPCMessage(ownerID) - if err != nil { - return err - } + if err := h.fillOwnerID(v); err != nil { + return err } - - homoHash := v.GetHomomorphicHash() - if homoHash == nil { - h.homoHash = nil - } else { - if h.homoHash == nil { - h.homoHash = new(refs.Checksum) - } - - err = h.homoHash.FromGRPCMessage(homoHash) - if err != nil { - return err - } + if err := h.fillHomomorphicHash(v); err != nil { + return err } - - cid := v.GetContainerId() - if cid == nil { - h.cid = nil - } else { - if h.cid == nil { - h.cid = new(refs.ContainerID) - } - - err = h.cid.FromGRPCMessage(cid) - if err != nil { - return err - } + if err := h.fillContainerID(v); err != nil { + return err } - - sessionToken := v.GetSessionToken() - if sessionToken == nil { - h.sessionToken = nil - } else { - if h.sessionToken == nil { - h.sessionToken = new(session.Token) - } - - err = h.sessionToken.FromGRPCMessage(sessionToken) - if err != nil { - return err - } + if err := h.fillSessionToken(v); err != nil { + return err } - - split := v.GetSplit() - if split == nil { - h.split = nil - } else { - if h.split == nil { - h.split = new(SplitHeader) - } - - err = h.split.FromGRPCMessage(split) - if err != nil { - return err - } + if err := h.fillSplitHeader(v); err != nil { + return err } h.attr, err = AttributesFromGRPC(v.GetAttributes()) @@ -402,6 +326,97 @@ func (h *Header) FromGRPCMessage(m grpc.Message) error { return nil } +func (h *Header) fillVersion(v *object.Header) error { + version := v.GetVersion() + if version == nil { + h.version = nil + return nil + } + + if h.version == nil { + h.version = new(refs.Version) + } + return h.version.FromGRPCMessage(version) +} + +func (h *Header) fillPayloadHash(v *object.Header) error { + payloadHash := v.GetPayloadHash() + if payloadHash == nil { + h.payloadHash = nil + return nil + } + + if h.payloadHash == nil { + h.payloadHash = new(refs.Checksum) + } + return h.payloadHash.FromGRPCMessage(payloadHash) +} + +func (h *Header) fillOwnerID(v *object.Header) error { + ownerID := v.GetOwnerId() + if ownerID == nil { + h.ownerID = nil + return nil + } + + if h.ownerID == nil { + h.ownerID = new(refs.OwnerID) + } + return h.ownerID.FromGRPCMessage(ownerID) +} + +func (h *Header) fillHomomorphicHash(v *object.Header) error { + homoHash := v.GetHomomorphicHash() + if homoHash == nil { + h.homoHash = nil + return nil + } + + if h.homoHash == nil { + h.homoHash = new(refs.Checksum) + } + return h.homoHash.FromGRPCMessage(homoHash) +} + +func (h *Header) fillContainerID(v *object.Header) error { + cid := v.GetContainerId() + if cid == nil { + h.cid = nil + return nil + } + + if h.cid == nil { + h.cid = new(refs.ContainerID) + } + return h.cid.FromGRPCMessage(cid) +} + +func (h *Header) fillSessionToken(v *object.Header) error { + sessionToken := v.GetSessionToken() + if sessionToken == nil { + h.sessionToken = nil + return nil + } + + if h.sessionToken == nil { + h.sessionToken = new(session.Token) + } + return h.sessionToken.FromGRPCMessage(sessionToken) +} + +func (h *Header) fillSplitHeader(v *object.Header) error { + split := v.GetSplit() + if split == nil { + h.split = nil + return nil + } + + if h.split == nil { + h.split = new(SplitHeader) + } + return h.split.FromGRPCMessage(split) +} + func (h *HeaderWithSignature) ToGRPCMessage() grpc.Message { var m *object.HeaderWithSignature