Skip to content

Commit

Permalink
object: Update documentation
Browse files Browse the repository at this point in the history
closes #226

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Jul 20, 2023
1 parent 2dcae11 commit c0517de
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 98 deletions.
26 changes: 17 additions & 9 deletions object/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
// Attribute represents v2-compatible object attribute.
type Attribute object.Attribute

// NewAttributeFromV2 wraps v2 Attribute message to Attribute.
// NewAttributeFromV2 wraps v2 [object.Attribute] message to [Attribute].
//
// Nil object.Attribute converts to nil.
// Nil [object.Attribute] converts to nil.
func NewAttributeFromV2(aV2 *object.Attribute) *Attribute {
return (*Attribute)(aV2)
}

// NewAttribute creates and initializes blank Attribute.
// NewAttribute creates and initializes blank [Attribute].
//
// Works similar as NewAttributeFromV2(new(Attribute)).
//
Expand Down Expand Up @@ -45,29 +45,37 @@ func (a *Attribute) SetValue(v string) {
(*object.Attribute)(a).SetValue(v)
}

// ToV2 converts Attribute to v2 Attribute message.
// ToV2 converts [Attribute] to v2 [object.Attribute] message.
//
// Nil Attribute converts to nil.
// Nil [Attribute] converts to nil.
func (a *Attribute) ToV2() *object.Attribute {
return (*object.Attribute)(a)
}

// Marshal marshals Attribute into a protobuf binary form.
// Marshal marshals [Attribute] into a protobuf binary form.
//
// See also [Attribute.Unmarshal].
func (a *Attribute) Marshal() ([]byte, error) {
return (*object.Attribute)(a).StableMarshal(nil), nil
}

// Unmarshal unmarshals protobuf binary representation of Attribute.
// Unmarshal unmarshals protobuf binary representation of [Attribute].
//
// See also [Attribute.Marshal].
func (a *Attribute) Unmarshal(data []byte) error {
return (*object.Attribute)(a).Unmarshal(data)
}

// MarshalJSON encodes Attribute to protobuf JSON format.
// MarshalJSON encodes [Attribute] to protobuf JSON format.
//
// See also [Attribute.UnmarshalJSON].
func (a *Attribute) MarshalJSON() ([]byte, error) {
return (*object.Attribute)(a).MarshalJSON()
}

// UnmarshalJSON decodes Attribute from protobuf JSON format.
// UnmarshalJSON decodes [Attribute] from protobuf JSON format.
//
// See also [Attribute.MarshalJSON].
func (a *Attribute) UnmarshalJSON(data []byte) error {
return (*object.Attribute)(a).UnmarshalJSON(data)
}
4 changes: 4 additions & 0 deletions object/error.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package object

// SplitInfoError is a special error that means that the original object is a large one (split into a number of smaller objects).
type SplitInfoError struct {
si *SplitInfo
}

const splitInfoErrorMsg = "object not found, split info has been provided"

// Error implements the error interface.
func (s *SplitInfoError) Error() string {
return splitInfoErrorMsg
}

// SplitInfo returns [SplitInfo] data.
func (s *SplitInfoError) SplitInfo() *SplitInfo {
return s.si
}

// NewSplitInfoError is a constructor for [SplitInfoError].
func NewSplitInfoError(v *SplitInfo) *SplitInfoError {
return &SplitInfoError{si: v}
}
2 changes: 1 addition & 1 deletion object/id/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (x *Address) DecodeString(s string) error {
return nil
}

// String implements fmt.Stringer.
// String implements [fmt.Stringer].
//
// String is designed to be human-readable, and its format MAY differ between
// SDK versions. String MAY return same result as EncodeToString. String MUST NOT
Expand Down
2 changes: 1 addition & 1 deletion object/id/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (id *ID) DecodeString(s string) error {
return id.Decode(data)
}

// String implements fmt.Stringer.
// String implements [fmt.Stringer].
//
// String is designed to be human-readable, and its format MAY differ between
// SDK versions. String MAY return same result as EncodeToString. String MUST NOT
Expand Down
22 changes: 14 additions & 8 deletions object/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import (
// Lock represents record with locked objects. It is compatible with
// NeoFS API V2 protocol.
//
// Lock instance can be written to the Object, see WriteLock/ReadLock.
// Lock instance can be written to the [Object], see WriteLock/ReadLock.
type Lock v2object.Lock

// WriteLock writes Lock to the Object, and sets its type to TypeLock.
// WriteLock writes [Lock] to the [Object], and sets its type to [TypeLock].
//
// See also ReadLock.
func (o *Object) WriteLock(l Lock) {
o.SetType(TypeLock)
o.SetPayload(l.Marshal())
}

// ReadLock reads Lock from the Object. The lock must not be nil.
// ReadLock reads [Lock] from the [Object]. The lock must not be nil.
// Returns an error describing incorrect format. Makes sense only
// if object has TypeLock type.
// if object has [TypeLock] type.
//
// See also WriteLock.
// See also [Object.WriteLock].
func (o *Object) ReadLock(l *Lock) error {
return l.Unmarshal(o.Payload())
}
Expand All @@ -36,7 +36,7 @@ func (x Lock) NumberOfMembers() int {

// ReadMembers reads list of locked members.
//
// Buffer length must not be less than NumberOfMembers.
// Buffer length must not be less than [Lock.NumberOfMembers].
func (x Lock) ReadMembers(buf []oid.ID) {
var i int

Expand All @@ -47,6 +47,8 @@ func (x Lock) ReadMembers(buf []oid.ID) {
}

// WriteMembers writes list of locked members.
//
// See also [Lock.ReadMembers].
func (x *Lock) WriteMembers(ids []oid.ID) {
var members []refs.ObjectID

Expand All @@ -61,12 +63,16 @@ func (x *Lock) WriteMembers(ids []oid.ID) {
(*v2object.Lock)(x).SetMembers(members)
}

// Marshal encodes the Lock into a NeoFS protocol binary format.
// Marshal encodes the [Lock] into a NeoFS protocol binary format.
//
// See also [Lock.Unmarshal].
func (x Lock) Marshal() []byte {
return (*v2object.Lock)(&x).StableMarshal(nil)
}

// Unmarshal decodes the Lock from its NeoFS protocol binary representation.
// Unmarshal decodes the [Lock] from its NeoFS protocol binary representation.
//
// See also [Lock.Marshal].
func (x *Lock) Unmarshal(data []byte) error {
return (*v2object.Lock)(x).Unmarshal(data)
}
Loading

0 comments on commit c0517de

Please sign in to comment.