2023-03-23 13:32:25 +00:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ObjectInfo represents information about FrostFS object that has been created
|
|
|
|
// via gRPC/HTTP/S3 API.
|
|
|
|
type ObjectInfo struct {
|
|
|
|
Id uint64 // Identifier in bolt DB
|
|
|
|
CreatedAt int64 // UTC seconds from epoch when the object was created
|
|
|
|
CID string // Container ID in gRPC/HTTP
|
|
|
|
OID string // Object ID in gRPC/HTTP
|
|
|
|
S3Bucket string // Bucket name in S3
|
|
|
|
S3Key string // Object key in S3
|
|
|
|
Status string // Status of the object
|
|
|
|
PayloadHash string // SHA256 hash of object payload that can be used for verification
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o ObjectInfo) EncodeBinary(w *io.BinWriter) {
|
2023-03-23 14:42:51 +00:00
|
|
|
o.encodeFilterableFields(w)
|
2023-03-23 13:32:25 +00:00
|
|
|
w.WriteU64LE(o.Id)
|
|
|
|
w.WriteString(o.CID)
|
|
|
|
w.WriteString(o.OID)
|
|
|
|
w.WriteString(o.S3Bucket)
|
|
|
|
w.WriteString(o.S3Key)
|
|
|
|
w.WriteString(o.PayloadHash)
|
|
|
|
}
|
|
|
|
|
2023-03-23 14:42:51 +00:00
|
|
|
func (o ObjectInfo) encodeFilterableFields(w *io.BinWriter) {
|
|
|
|
w.WriteU64LE(uint64(o.CreatedAt))
|
|
|
|
w.WriteString(o.Status)
|
|
|
|
}
|
|
|
|
|
2023-03-23 13:32:25 +00:00
|
|
|
func (o *ObjectInfo) DecodeBinary(r *io.BinReader) {
|
2023-03-23 14:42:51 +00:00
|
|
|
o.decodeFilterableFields(r)
|
2023-03-23 13:32:25 +00:00
|
|
|
o.Id = r.ReadU64LE()
|
|
|
|
o.CID = r.ReadString()
|
|
|
|
o.OID = r.ReadString()
|
|
|
|
o.S3Bucket = r.ReadString()
|
|
|
|
o.S3Key = r.ReadString()
|
|
|
|
o.PayloadHash = r.ReadString()
|
|
|
|
}
|
|
|
|
|
2023-03-23 14:42:51 +00:00
|
|
|
func (o *ObjectInfo) decodeFilterableFields(r *io.BinReader) {
|
|
|
|
o.CreatedAt = int64(r.ReadU64LE())
|
|
|
|
o.Status = r.ReadString()
|
|
|
|
}
|
|
|
|
|
2023-03-23 13:32:25 +00:00
|
|
|
func (o ObjectInfo) Marshal() ([]byte, error) {
|
|
|
|
w := io.NewBufBinWriter()
|
|
|
|
o.EncodeBinary(w.BinWriter)
|
|
|
|
err := w.Err // Bytes() sets Err to ErrDrained
|
|
|
|
return w.Bytes(), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *ObjectInfo) Unmarshal(data []byte) error {
|
|
|
|
r := io.NewBinReaderFromBuf(data)
|
|
|
|
o.DecodeBinary(r)
|
|
|
|
return r.Err
|
|
|
|
}
|