[#143] object: Add notification setters and getters

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-02-16 17:49:29 +03:00 committed by LeL
parent ddd6c08b6a
commit 47e8527ffb
2 changed files with 56 additions and 0 deletions

View file

@ -161,3 +161,8 @@ func (o *RawObject) ResetRelations() {
func (o *RawObject) InitRelations() {
o.initRelations()
}
// SetNotification writes NotificationInfo to the object structure.
func (o *RawObject) SetNotification(ni NotificationInfo) {
o.setNotification(ni)
}

View file

@ -249,6 +249,57 @@ func (o *rwObject) setChildren(v ...*oid.ID) {
})
}
// NotificationInfo groups information about object notification
// that can be written to object.
//
// Topic is an optional field.
type NotificationInfo struct {
ni object.NotificationInfo
}
// Epoch returns object notification tick
// epoch.
func (n NotificationInfo) Epoch() uint64 {
return n.ni.Epoch()
}
// SetEpoch sets object notification tick
// epoch.
func (n *NotificationInfo) SetEpoch(epoch uint64) {
n.ni.SetEpoch(epoch)
}
// Topic return optional object notification
// topic.
func (n NotificationInfo) Topic() string {
return n.ni.Topic()
}
// SetTopic sets optional object notification
// topic.
func (n *NotificationInfo) SetTopic(topic string) {
n.ni.SetTopic(topic)
}
// NotificationInfo returns notification info
// read from the object structure.
// Returns any error that appeared during notification
// information parsing.
func (o *rwObject) NotificationInfo() (*NotificationInfo, error) {
ni, err := object.GetNotificationInfo((*object.Object)(o))
if err != nil {
return nil, err
}
return &NotificationInfo{
ni: *ni,
}, nil
}
func (o *rwObject) setNotification(ni NotificationInfo) {
object.WriteNotificationInfo((*object.Object)(o), ni.ni)
}
// SplitID return split identity of split object. If object is not split
// returns nil.
func (o *rwObject) SplitID() *SplitID {