[#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) {
|
||||
case nil:
|
||||
return nil, errNilObjectPart
|
||||
case *v2object.GetHeaderPartShort:
|
||||
case *v2object.ShortHeader:
|
||||
if !p.short {
|
||||
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.SetPayloadLength(h.GetPayloadLength())
|
||||
|
@ -665,14 +665,14 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o
|
|||
hdr.SetOwnerID(h.GetOwnerID())
|
||||
hdr.SetObjectType(h.GetObjectType())
|
||||
hdr.SetCreationEpoch(h.GetCreationEpoch())
|
||||
case *v2object.GetHeaderPartFull:
|
||||
case *v2object.HeaderWithSignature:
|
||||
if p.short {
|
||||
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 {
|
||||
return nil, errNilObjectPart
|
||||
}
|
||||
|
|
|
@ -1023,62 +1023,6 @@ func HeadRequestFromGRPCMessage(m *object.HeadRequest) *HeadRequest {
|
|||
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 {
|
||||
if r == nil {
|
||||
return nil
|
||||
|
@ -1088,13 +1032,13 @@ func HeadResponseBodyToGRPCMessage(r *HeadResponseBody) *object.HeadResponse_Bod
|
|||
|
||||
switch v := r.GetHeaderPart(); t := v.(type) {
|
||||
case nil:
|
||||
case *GetHeaderPartFull:
|
||||
case *HeaderWithSignature:
|
||||
m.SetHeader(
|
||||
GetHeaderPartFullToGRPCMessage(t),
|
||||
HeaderWithSignatureToGRPCMessage(t),
|
||||
)
|
||||
case *GetHeaderPartShort:
|
||||
case *ShortHeader:
|
||||
m.SetShortHeader(
|
||||
GetHeaderPartShortToGRPCMessage(t),
|
||||
ShortHeaderToGRPCMessage(t),
|
||||
)
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown header part %T", t))
|
||||
|
@ -1114,11 +1058,11 @@ func HeadResponseBodyFromGRPCMessage(m *object.HeadResponse_Body) *HeadResponseB
|
|||
case nil:
|
||||
case *object.HeadResponse_Body_Header:
|
||||
r.SetHeaderPart(
|
||||
GetHeaderPartFullFromGRPCMessage(v),
|
||||
HeaderWithSignatureFromGRPCMessage(v.Header),
|
||||
)
|
||||
case *object.HeadResponse_Body_ShortHeader:
|
||||
r.SetHeaderPart(
|
||||
GetHeaderPartShortFromGRPCMessage(v),
|
||||
ShortHeaderFromGRPCMessage(v.ShortHeader),
|
||||
)
|
||||
default:
|
||||
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.
|
||||
func (m *HeaderWithSignature) SetHeader(v *Header) {
|
||||
if m != nil {
|
||||
|
@ -370,16 +338,20 @@ func (m *HeaderWithSignature) SetSignature(v *refs.Signature) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.Head = v
|
||||
m.Head = &HeadResponse_Body_Header{
|
||||
Header: v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
switch v := r.hdrPart.(type) {
|
||||
case *GetHeaderPartFull:
|
||||
case *HeaderWithSignature:
|
||||
if v != nil {
|
||||
_, err := proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v.hdr)
|
||||
_, err := proto.NestedStructureMarshal(headRespBodyHeaderField, buf, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
case *GetHeaderPartShort:
|
||||
case *ShortHeader:
|
||||
if v != nil {
|
||||
_, err := proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v.hdr)
|
||||
_, err := proto.NestedStructureMarshal(headRespBodyShortHeaderField, buf, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1045,13 +1045,13 @@ func (r *HeadResponseBody) StableSize() (size int) {
|
|||
|
||||
if r.hdrPart != nil {
|
||||
switch v := r.hdrPart.(type) {
|
||||
case *GetHeaderPartFull:
|
||||
case *HeaderWithSignature:
|
||||
if v != nil {
|
||||
size += proto.NestedStructureSize(headRespBodyHeaderField, v.hdr)
|
||||
size += proto.NestedStructureSize(headRespBodyHeaderField, v)
|
||||
}
|
||||
case *GetHeaderPartShort:
|
||||
case *ShortHeader:
|
||||
if v != nil {
|
||||
size += proto.NestedStructureSize(headRespBodyShortHeaderField, v.hdr)
|
||||
size += proto.NestedStructureSize(headRespBodyShortHeaderField, v)
|
||||
}
|
||||
default:
|
||||
panic("unknown one of object put request body type")
|
||||
|
|
|
@ -611,13 +611,9 @@ func generateHeadResponseBody(flag bool) *object.HeadResponseBody {
|
|||
var part object.GetHeaderPart
|
||||
|
||||
if flag {
|
||||
short := new(object.GetHeaderPartShort)
|
||||
short.SetShortHeader(generateShortHeader("short id"))
|
||||
part = short
|
||||
part = generateShortHeader("short id")
|
||||
} else {
|
||||
full := new(object.GetHeaderPartFull)
|
||||
full.SetHeaderWithSignature(generateHeaderWithSignature())
|
||||
part = full
|
||||
part = generateHeaderWithSignature()
|
||||
}
|
||||
|
||||
req.SetHeaderPart(part)
|
||||
|
|
|
@ -161,11 +161,8 @@ func testHeadResponse() *object.HeadResponse {
|
|||
shortHdr := new(object.ShortHeader)
|
||||
shortHdr.SetCreationEpoch(100)
|
||||
|
||||
hdrPart := new(object.GetHeaderPartShort)
|
||||
hdrPart.SetShortHeader(shortHdr)
|
||||
|
||||
body := new(object.HeadResponseBody)
|
||||
body.SetHeaderPart(hdrPart)
|
||||
body.SetHeaderPart(shortHdr)
|
||||
|
||||
meta := new(session.ResponseMetaHeader)
|
||||
meta.SetTTL(1)
|
||||
|
|
|
@ -151,14 +151,6 @@ type GetHeaderPart interface {
|
|||
getHeaderPart()
|
||||
}
|
||||
|
||||
type GetHeaderPartFull struct {
|
||||
hdr *HeaderWithSignature
|
||||
}
|
||||
|
||||
type GetHeaderPartShort struct {
|
||||
hdr *ShortHeader
|
||||
}
|
||||
|
||||
type HeadResponseBody struct {
|
||||
hdrPart GetHeaderPart
|
||||
}
|
||||
|
@ -292,6 +284,8 @@ func (h *ShortHeader) SetPayloadLength(v uint64) {
|
|||
}
|
||||
}
|
||||
|
||||
func (h *ShortHeader) getHeaderPart() {}
|
||||
|
||||
func (a *Attribute) GetKey() string {
|
||||
if a != nil {
|
||||
return a.key
|
||||
|
@ -586,6 +580,8 @@ func (h *HeaderWithSignature) SetSignature(v *refs.Signature) {
|
|||
}
|
||||
}
|
||||
|
||||
func (h *HeaderWithSignature) getHeaderPart() {}
|
||||
|
||||
func (o *Object) GetObjectID() *refs.ObjectID {
|
||||
if o != nil {
|
||||
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 {
|
||||
if r != nil {
|
||||
return r.hdrPart
|
||||
|
|
Loading…
Reference in a new issue