frostfs-api-go/pkg/object/id.go
Leonard Lyubich 524280a5e8 [#140] sdk: Refactor reference types
Refactor v2-compatible reference types to be wrappers over corresponding
types from v2.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-09-18 10:45:11 +03:00

32 lines
697 B
Go

package object
import (
"crypto/sha256"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
)
// ID represents v2-compatible object identifier.
type ID refs.ObjectID
// NewIDFromV2 wraps v2 ObjectID message to ID.
func NewIDFromV2(idV2 *refs.ObjectID) *ID {
return (*ID)(idV2)
}
// NewID creates and initializes blank ID.
//
// Works similar as NewIDFromV2(new(ObjectID)).
func NewID() *ID {
return NewIDFromV2(new(refs.ObjectID))
}
// SetSHA256 sets object identifier value to SHA256 checksum.
func (id *ID) SetSHA256(v [sha256.Size]byte) {
(*refs.ObjectID)(id).SetValue(v[:])
}
// ToV2 converts ID to v2 ObjectID message.
func (id *ID) ToV2() *refs.ObjectID {
return (*refs.ObjectID)(id)
}