forked from TrueCloudLab/frostfs-sdk-go
[#19] transformer: Simplify AccessIdentifiers
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
f43f18ecda
commit
1c94309d7a
4 changed files with 11 additions and 71 deletions
|
@ -109,8 +109,9 @@ func (f *formatter) Close() (*AccessIdentifiers, error) {
|
||||||
|
|
||||||
id, _ := f.obj.ID()
|
id, _ := f.obj.ID()
|
||||||
|
|
||||||
return new(AccessIdentifiers).
|
return &AccessIdentifiers{
|
||||||
WithSelfID(id).
|
ParentID: parID,
|
||||||
WithParentID(parID).
|
SelfID: id,
|
||||||
WithParent(parHdr), nil
|
ParentHeader: parHdr,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,11 +200,11 @@ func (s *payloadSizeLimiter) release(finalize bool) (*AccessIdentifiers, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// save identifier of the released object
|
// save identifier of the released object
|
||||||
s.previous = append(s.previous, ids.SelfID())
|
s.previous = append(s.previous, ids.SelfID)
|
||||||
|
|
||||||
if withParent {
|
if withParent {
|
||||||
// generate and release linking object
|
// generate and release linking object
|
||||||
s.initializeLinking(ids.Parent())
|
s.initializeLinking(ids.ParentHeader)
|
||||||
s.initializeCurrent()
|
s.initializeCurrent()
|
||||||
|
|
||||||
if _, err := s.release(false); err != nil {
|
if _, err := s.release(false); err != nil {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestTransformer(t *testing.T) {
|
||||||
case 3:
|
case 3:
|
||||||
parID, ok := tt.objects[i].ParentID()
|
parID, ok := tt.objects[i].ParentID()
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, ids.ParentID(), &parID)
|
require.Equal(t, ids.ParentID, &parID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
require.Equal(t, expectedPayload, actualPayload)
|
require.Equal(t, expectedPayload, actualPayload)
|
||||||
|
|
|
@ -11,11 +11,9 @@ import (
|
||||||
// that are returned after writing the object.
|
// that are returned after writing the object.
|
||||||
// Consists of the ID of the stored object and the ID of the parent object.
|
// Consists of the ID of the stored object and the ID of the parent object.
|
||||||
type AccessIdentifiers struct {
|
type AccessIdentifiers struct {
|
||||||
par *oid.ID
|
ParentID *oid.ID
|
||||||
|
SelfID oid.ID
|
||||||
self oid.ID
|
ParentHeader *object.Object
|
||||||
|
|
||||||
parHdr *object.Object
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectTarget is an interface of the object writer.
|
// ObjectTarget is an interface of the object writer.
|
||||||
|
@ -50,62 +48,3 @@ type ObjectTarget interface {
|
||||||
|
|
||||||
// TargetInitializer represents ObjectTarget constructor.
|
// TargetInitializer represents ObjectTarget constructor.
|
||||||
type TargetInitializer func() ObjectTarget
|
type TargetInitializer func() ObjectTarget
|
||||||
|
|
||||||
// SelfID returns identifier of the written object.
|
|
||||||
func (a AccessIdentifiers) SelfID() oid.ID {
|
|
||||||
return a.self
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithSelfID returns AccessIdentifiers with passed self identifier.
|
|
||||||
func (a *AccessIdentifiers) WithSelfID(v oid.ID) *AccessIdentifiers {
|
|
||||||
res := a
|
|
||||||
if res == nil {
|
|
||||||
res = new(AccessIdentifiers)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.self = v
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParentID return identifier of the parent of the written object.
|
|
||||||
func (a *AccessIdentifiers) ParentID() *oid.ID {
|
|
||||||
if a != nil {
|
|
||||||
return a.par
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithParentID returns AccessIdentifiers with passed parent identifier.
|
|
||||||
func (a *AccessIdentifiers) WithParentID(v *oid.ID) *AccessIdentifiers {
|
|
||||||
res := a
|
|
||||||
if res == nil {
|
|
||||||
res = new(AccessIdentifiers)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.par = v
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent return identifier of the parent of the written object.
|
|
||||||
func (a *AccessIdentifiers) Parent() *object.Object {
|
|
||||||
if a != nil {
|
|
||||||
return a.parHdr
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithParent returns AccessIdentifiers with passed parent identifier.
|
|
||||||
func (a *AccessIdentifiers) WithParent(v *object.Object) *AccessIdentifiers {
|
|
||||||
res := a
|
|
||||||
if res == nil {
|
|
||||||
res = new(AccessIdentifiers)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.parHdr = v
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue