frostfs-sdk-go/object/ecinfo.go
Pavel Pogodaev 2156a6bf73
Some checks failed
DCO / DCO (pull_request) Successful in 35s
Tests and linters / Tests (pull_request) Failing after 1m11s
Tests and linters / Lint (pull_request) Successful in 2m5s
[#276] Merge repo with frostfs-api-go
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
2024-10-11 23:19:04 +03:00

69 lines
1.6 KiB
Go

package object
import (
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
)
type ECChunk object.ECChunk
func (c *ECChunk) SetID(id oid.ID) {
objV2 := new(refs.ObjectID)
id.WriteToV2(objV2)
c.ID = *objV2
}
// ToV2 converts ECChunk to v2 ECChunk message.
//
// Nil ECChunk converts to nil.
func (c *ECChunk) ToV2() *object.ECChunk {
return (*object.ECChunk)(c)
}
func NewECChunkFromV2(v2 *object.ECChunk) *ECChunk {
return (*ECChunk)(v2)
}
type ECInfo object.ECInfo
// NewECInfoFromV2 wraps v2 ECInfo message to ECInfo.
//
// Nil object.ECInfo converts to nil.
func NewECInfoFromV2(v2 *object.ECInfo) *ECInfo {
return (*ECInfo)(v2)
}
// NewECInfo creates and initializes blank ECInfo.
func NewECInfo() *ECInfo {
return NewECInfoFromV2(new(object.ECInfo))
}
// ToV2 converts ECInfo to v2 ECInfo message.
//
// Nil ECInfo converts to nil.
func (s *ECInfo) ToV2() *object.ECInfo {
return (*object.ECInfo)(s)
}
func (s *ECInfo) Marshal() ([]byte, error) {
return (*object.ECInfo)(s).StableMarshal(nil), nil
}
func (s *ECInfo) Unmarshal(data []byte) error {
return (*object.ECInfo)(s).Unmarshal(data)
}
// MarshalJSON implements json.Marshaler.
func (s *ECInfo) MarshalJSON() ([]byte, error) {
return (*object.ECInfo)(s).MarshalJSON()
}
// UnmarshalJSON implements json.Unmarshaler.
func (s *ECInfo) UnmarshalJSON(data []byte) error {
return (*object.ECInfo)(s).UnmarshalJSON(data)
}
func (s *ECInfo) AddChunk(chunk ECChunk) {
s.Chunks = append(s.Chunks, *chunk.ToV2())
}