From 47e8527ffbd8b9cc3312f236c4fd25587a4e3378 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 16 Feb 2022 17:49:29 +0300 Subject: [PATCH] [#143] object: Add notification setters and getters Signed-off-by: Pavel Karpy --- object/raw.go | 5 +++++ object/rw.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/object/raw.go b/object/raw.go index 0d9e7ce..409176c 100644 --- a/object/raw.go +++ b/object/raw.go @@ -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) +} diff --git a/object/rw.go b/object/rw.go index 39e2457..1c24fe0 100644 --- a/object/rw.go +++ b/object/rw.go @@ -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 {