[#225] Do not use wrappers on oneof object.HeadResponse types
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
6db6b569e0
commit
28aad71860
7 changed files with 35 additions and 162 deletions
|
@ -650,14 +650,14 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o
|
||||||
switch v := resp.GetBody().GetHeaderPart().(type) {
|
switch v := resp.GetBody().GetHeaderPart().(type) {
|
||||||
case nil:
|
case nil:
|
||||||
return nil, errNilObjectPart
|
return nil, errNilObjectPart
|
||||||
case *v2object.GetHeaderPartShort:
|
case *v2object.ShortHeader:
|
||||||
if !p.short {
|
if !p.short {
|
||||||
return nil, errors.Errorf("wrong header part type: expected %T, received %T",
|
return nil, errors.Errorf("wrong header part type: expected %T, received %T",
|
||||||
(*v2object.GetHeaderPartFull)(nil), (*v2object.GetHeaderPartShort)(nil),
|
(*v2object.ShortHeader)(nil), (*v2object.HeaderWithSignature)(nil),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
h := v.GetShortHeader()
|
h := v
|
||||||
|
|
||||||
hdr = new(v2object.Header)
|
hdr = new(v2object.Header)
|
||||||
hdr.SetPayloadLength(h.GetPayloadLength())
|
hdr.SetPayloadLength(h.GetPayloadLength())
|
||||||
|
@ -665,14 +665,14 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o
|
||||||
hdr.SetOwnerID(h.GetOwnerID())
|
hdr.SetOwnerID(h.GetOwnerID())
|
||||||
hdr.SetObjectType(h.GetObjectType())
|
hdr.SetObjectType(h.GetObjectType())
|
||||||
hdr.SetCreationEpoch(h.GetCreationEpoch())
|
hdr.SetCreationEpoch(h.GetCreationEpoch())
|
||||||
case *v2object.GetHeaderPartFull:
|
case *v2object.HeaderWithSignature:
|
||||||
if p.short {
|
if p.short {
|
||||||
return nil, errors.Errorf("wrong header part type: expected %T, received %T",
|
return nil, errors.Errorf("wrong header part type: expected %T, received %T",
|
||||||
(*v2object.GetHeaderPartShort)(nil), (*v2object.GetHeaderPartFull)(nil),
|
(*v2object.HeaderWithSignature)(nil), (*v2object.ShortHeader)(nil),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
hdrWithSig := v.GetHeaderWithSignature()
|
hdrWithSig := v
|
||||||
if hdrWithSig == nil {
|
if hdrWithSig == nil {
|
||||||
return nil, errNilObjectPart
|
return nil, errNilObjectPart
|
||||||
}
|
}
|
||||||
|
|
|
@ -1023,62 +1023,6 @@ func HeadRequestFromGRPCMessage(m *object.HeadRequest) *HeadRequest {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHeaderPartFullToGRPCMessage(r *GetHeaderPartFull) *object.HeadResponse_Body_Header {
|
|
||||||
if r == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
m := new(object.HeadResponse_Body_Header)
|
|
||||||
|
|
||||||
m.SetHeaderWithSignature(
|
|
||||||
HeaderWithSignatureToGRPCMessage(r.GetHeaderWithSignature()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetHeaderPartFullFromGRPCMessage(m *object.HeadResponse_Body_Header) *GetHeaderPartFull {
|
|
||||||
if m == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r := new(GetHeaderPartFull)
|
|
||||||
|
|
||||||
r.SetHeaderWithSignature(
|
|
||||||
HeaderWithSignatureFromGRPCMessage(m.GetHeaderWithSignature()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetHeaderPartShortToGRPCMessage(r *GetHeaderPartShort) *object.HeadResponse_Body_ShortHeader {
|
|
||||||
if r == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
m := new(object.HeadResponse_Body_ShortHeader)
|
|
||||||
|
|
||||||
m.SetShortHeader(
|
|
||||||
ShortHeaderToGRPCMessage(r.GetShortHeader()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetHeaderPartShortFromGRPCMessage(m *object.HeadResponse_Body_ShortHeader) *GetHeaderPartShort {
|
|
||||||
if m == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
r := new(GetHeaderPartShort)
|
|
||||||
|
|
||||||
r.SetShortHeader(
|
|
||||||
ShortHeaderFromGRPCMessage(m.GetShortHeader()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func HeadResponseBodyToGRPCMessage(r *HeadResponseBody) *object.HeadResponse_Body {
|
func HeadResponseBodyToGRPCMessage(r *HeadResponseBody) *object.HeadResponse_Body {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -1088,13 +1032,13 @@ func HeadResponseBodyToGRPCMessage(r *HeadResponseBody) *object.HeadResponse_Bod
|
||||||
|
|
||||||
switch v := r.GetHeaderPart(); t := v.(type) {
|
switch v := r.GetHeaderPart(); t := v.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
case *GetHeaderPartFull:
|
case *HeaderWithSignature:
|
||||||
m.SetHeader(
|
m.SetHeader(
|
||||||
GetHeaderPartFullToGRPCMessage(t),
|
HeaderWithSignatureToGRPCMessage(t),
|
||||||
)
|
)
|
||||||
case *GetHeaderPartShort:
|
case *ShortHeader:
|
||||||
m.SetShortHeader(
|
m.SetShortHeader(
|
||||||
GetHeaderPartShortToGRPCMessage(t),
|
ShortHeaderToGRPCMessage(t),
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unknown header part %T", t))
|
panic(fmt.Sprintf("unknown header part %T", t))
|
||||||
|
@ -1114,11 +1058,11 @@ func HeadResponseBodyFromGRPCMessage(m *object.HeadResponse_Body) *HeadResponseB
|
||||||
case nil:
|
case nil:
|
||||||
case *object.HeadResponse_Body_Header:
|
case *object.HeadResponse_Body_Header:
|
||||||
r.SetHeaderPart(
|
r.SetHeaderPart(
|
||||||
GetHeaderPartFullFromGRPCMessage(v),
|
HeaderWithSignatureFromGRPCMessage(v.Header),
|
||||||
)
|
)
|
||||||
case *object.HeadResponse_Body_ShortHeader:
|
case *object.HeadResponse_Body_ShortHeader:
|
||||||
r.SetHeaderPart(
|
r.SetHeaderPart(
|
||||||
GetHeaderPartShortFromGRPCMessage(v),
|
ShortHeaderFromGRPCMessage(v.ShortHeader),
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unknown header part %T", v))
|
panic(fmt.Sprintf("unknown header part %T", v))
|
||||||
|
|
|
@ -323,38 +323,6 @@ func (m *HeadRequest) SetVerifyHeader(v *session.RequestVerificationHeader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetShortHeader returns short header of the object.
|
|
||||||
func (m *HeadResponse_Body_ShortHeader) GetShortHeader() *ShortHeader {
|
|
||||||
if m != nil {
|
|
||||||
return m.ShortHeader
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetShortHeader sets short header of the object.
|
|
||||||
func (m *HeadResponse_Body_ShortHeader) SetShortHeader(v *ShortHeader) {
|
|
||||||
if m != nil {
|
|
||||||
m.ShortHeader = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetHeaderWithSignature returns object header.
|
|
||||||
func (m *HeadResponse_Body_Header) GetHeaderWithSignature() *HeaderWithSignature {
|
|
||||||
if m != nil {
|
|
||||||
return m.Header
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetHeaderWithSignature sets object header.
|
|
||||||
func (m *HeadResponse_Body_Header) SetHeaderWithSignature(v *HeaderWithSignature) {
|
|
||||||
if m != nil {
|
|
||||||
m.Header = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetHeader sets object header.
|
// SetHeader sets object header.
|
||||||
func (m *HeaderWithSignature) SetHeader(v *Header) {
|
func (m *HeaderWithSignature) SetHeader(v *Header) {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
|
@ -370,16 +338,20 @@ func (m *HeaderWithSignature) SetSignature(v *refs.Signature) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHeader sets full header of the object.
|
// SetHeader sets full header of the object.
|
||||||
func (m *HeadResponse_Body) SetHeader(v *HeadResponse_Body_Header) {
|
func (m *HeadResponse_Body) SetHeader(v *HeaderWithSignature) {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
m.Head = v
|
m.Head = &HeadResponse_Body_Header{
|
||||||
|
Header: v,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetShortHeader sets short header of the object.
|
// SetShortHeader sets short header of the object.
|
||||||
func (m *HeadResponse_Body) SetShortHeader(v *HeadResponse_Body_ShortHeader) {
|
func (m *HeadResponse_Body) SetShortHeader(v *ShortHeader) {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
m.Head = v
|
m.Head = &HeadResponse_Body_ShortHeader{
|
||||||
|
ShortHeader: v,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1016,16 +1016,16 @@ func (r *HeadResponseBody) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
|
|
||||||
if r.hdrPart != nil {
|
if r.hdrPart != nil {
|
||||||
switch v := r.hdrPart.(type) {
|
switch v := r.hdrPart.(type) {
|
||||||
case *GetHeaderPartFull:
|
case *HeaderWithSignature:
|
||||||
if v != nil {
|
if v != nil {
|
||||||
_, err := proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v.hdr)
|
_, err := proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *GetHeaderPartShort:
|
case *ShortHeader:
|
||||||
if v != nil {
|
if v != nil {
|
||||||
_, err := proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v.hdr)
|
_, err := proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1045,13 +1045,13 @@ func (r *HeadResponseBody) StableSize() (size int) {
|
||||||
|
|
||||||
if r.hdrPart != nil {
|
if r.hdrPart != nil {
|
||||||
switch v := r.hdrPart.(type) {
|
switch v := r.hdrPart.(type) {
|
||||||
case *GetHeaderPartFull:
|
case *HeaderWithSignature:
|
||||||
if v != nil {
|
if v != nil {
|
||||||
size += proto.NestedStructureSize(headRespBodyHeaderField, v.hdr)
|
size += proto.NestedStructureSize(headRespBodyHeaderField, v)
|
||||||
}
|
}
|
||||||
case *GetHeaderPartShort:
|
case *ShortHeader:
|
||||||
if v != nil {
|
if v != nil {
|
||||||
size += proto.NestedStructureSize(headRespBodyShortHeaderField, v.hdr)
|
size += proto.NestedStructureSize(headRespBodyShortHeaderField, v)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic("unknown one of object put request body type")
|
panic("unknown one of object put request body type")
|
||||||
|
|
|
@ -611,13 +611,9 @@ func generateHeadResponseBody(flag bool) *object.HeadResponseBody {
|
||||||
var part object.GetHeaderPart
|
var part object.GetHeaderPart
|
||||||
|
|
||||||
if flag {
|
if flag {
|
||||||
short := new(object.GetHeaderPartShort)
|
part = generateShortHeader("short id")
|
||||||
short.SetShortHeader(generateShortHeader("short id"))
|
|
||||||
part = short
|
|
||||||
} else {
|
} else {
|
||||||
full := new(object.GetHeaderPartFull)
|
part = generateHeaderWithSignature()
|
||||||
full.SetHeaderWithSignature(generateHeaderWithSignature())
|
|
||||||
part = full
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.SetHeaderPart(part)
|
req.SetHeaderPart(part)
|
||||||
|
|
|
@ -161,11 +161,8 @@ func testHeadResponse() *object.HeadResponse {
|
||||||
shortHdr := new(object.ShortHeader)
|
shortHdr := new(object.ShortHeader)
|
||||||
shortHdr.SetCreationEpoch(100)
|
shortHdr.SetCreationEpoch(100)
|
||||||
|
|
||||||
hdrPart := new(object.GetHeaderPartShort)
|
|
||||||
hdrPart.SetShortHeader(shortHdr)
|
|
||||||
|
|
||||||
body := new(object.HeadResponseBody)
|
body := new(object.HeadResponseBody)
|
||||||
body.SetHeaderPart(hdrPart)
|
body.SetHeaderPart(shortHdr)
|
||||||
|
|
||||||
meta := new(session.ResponseMetaHeader)
|
meta := new(session.ResponseMetaHeader)
|
||||||
meta.SetTTL(1)
|
meta.SetTTL(1)
|
||||||
|
|
|
@ -151,14 +151,6 @@ type GetHeaderPart interface {
|
||||||
getHeaderPart()
|
getHeaderPart()
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetHeaderPartFull struct {
|
|
||||||
hdr *HeaderWithSignature
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetHeaderPartShort struct {
|
|
||||||
hdr *ShortHeader
|
|
||||||
}
|
|
||||||
|
|
||||||
type HeadResponseBody struct {
|
type HeadResponseBody struct {
|
||||||
hdrPart GetHeaderPart
|
hdrPart GetHeaderPart
|
||||||
}
|
}
|
||||||
|
@ -292,6 +284,8 @@ func (h *ShortHeader) SetPayloadLength(v uint64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *ShortHeader) getHeaderPart() {}
|
||||||
|
|
||||||
func (a *Attribute) GetKey() string {
|
func (a *Attribute) GetKey() string {
|
||||||
if a != nil {
|
if a != nil {
|
||||||
return a.key
|
return a.key
|
||||||
|
@ -586,6 +580,8 @@ func (h *HeaderWithSignature) SetSignature(v *refs.Signature) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HeaderWithSignature) getHeaderPart() {}
|
||||||
|
|
||||||
func (o *Object) GetObjectID() *refs.ObjectID {
|
func (o *Object) GetObjectID() *refs.ObjectID {
|
||||||
if o != nil {
|
if o != nil {
|
||||||
return o.objectID
|
return o.objectID
|
||||||
|
@ -1240,38 +1236,6 @@ func (r *HeadRequest) SetVerificationHeader(v *session.RequestVerificationHeader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *GetHeaderPartFull) GetHeaderWithSignature() *HeaderWithSignature {
|
|
||||||
if h != nil {
|
|
||||||
return h.hdr
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *GetHeaderPartFull) SetHeaderWithSignature(v *HeaderWithSignature) {
|
|
||||||
if h != nil {
|
|
||||||
h.hdr = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*GetHeaderPartFull) getHeaderPart() {}
|
|
||||||
|
|
||||||
func (h *GetHeaderPartShort) GetShortHeader() *ShortHeader {
|
|
||||||
if h != nil {
|
|
||||||
return h.hdr
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *GetHeaderPartShort) SetShortHeader(v *ShortHeader) {
|
|
||||||
if h != nil {
|
|
||||||
h.hdr = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*GetHeaderPartShort) getHeaderPart() {}
|
|
||||||
|
|
||||||
func (r *HeadResponseBody) GetHeaderPart() GetHeaderPart {
|
func (r *HeadResponseBody) GetHeaderPart() GetHeaderPart {
|
||||||
if r != nil {
|
if r != nil {
|
||||||
return r.hdrPart
|
return r.hdrPart
|
||||||
|
|
Loading…
Reference in a new issue