[#19] transformer: Simplify AccessIdentifiers

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-02-17 13:00:27 +03:00 committed by Gitea
parent f43f18ecda
commit 1c94309d7a
4 changed files with 11 additions and 71 deletions

View file

@ -109,8 +109,9 @@ func (f *formatter) Close() (*AccessIdentifiers, error) {
id, _ := f.obj.ID()
return new(AccessIdentifiers).
WithSelfID(id).
WithParentID(parID).
WithParent(parHdr), nil
return &AccessIdentifiers{
ParentID: parID,
SelfID: id,
ParentHeader: parHdr,
}, nil
}

View file

@ -200,11 +200,11 @@ func (s *payloadSizeLimiter) release(finalize bool) (*AccessIdentifiers, error)
}
// save identifier of the released object
s.previous = append(s.previous, ids.SelfID())
s.previous = append(s.previous, ids.SelfID)
if withParent {
// generate and release linking object
s.initializeLinking(ids.Parent())
s.initializeLinking(ids.ParentHeader)
s.initializeCurrent()
if _, err := s.release(false); err != nil {

View file

@ -56,7 +56,7 @@ func TestTransformer(t *testing.T) {
case 3:
parID, ok := tt.objects[i].ParentID()
require.True(t, ok)
require.Equal(t, ids.ParentID(), &parID)
require.Equal(t, ids.ParentID, &parID)
}
}
require.Equal(t, expectedPayload, actualPayload)

View file

@ -11,11 +11,9 @@ import (
// that are returned after writing the object.
// Consists of the ID of the stored object and the ID of the parent object.
type AccessIdentifiers struct {
par *oid.ID
self oid.ID
parHdr *object.Object
ParentID *oid.ID
SelfID oid.ID
ParentHeader *object.Object
}
// ObjectTarget is an interface of the object writer.
@ -50,62 +48,3 @@ type ObjectTarget interface {
// TargetInitializer represents ObjectTarget constructor.
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
}