2021-11-06 10:38:52 +00:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
2023-03-07 10:38:56 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
|
|
status "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
|
2021-11-06 10:38:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (x *Detail) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *status.Status_Detail
|
|
|
|
|
|
|
|
if x != nil {
|
|
|
|
m = new(status.Status_Detail)
|
|
|
|
|
|
|
|
m.SetId(x.id)
|
|
|
|
m.SetValue(x.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Detail) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*status.Status_Detail)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
x.id = v.GetId()
|
|
|
|
x.val = v.GetValue()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func CodeFromGRPC(v uint32) Code {
|
|
|
|
return Code(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CodeToGRPC(v Code) uint32 {
|
|
|
|
return uint32(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Status) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *status.Status
|
|
|
|
|
|
|
|
if x != nil {
|
|
|
|
m = new(status.Status)
|
|
|
|
|
|
|
|
m.SetCode(CodeToGRPC(x.code))
|
|
|
|
m.SetMessage(x.msg)
|
|
|
|
|
2024-08-27 12:12:31 +00:00
|
|
|
var ds []status.Status_Detail
|
2021-11-06 10:38:52 +00:00
|
|
|
|
|
|
|
if ln := len(x.details); ln > 0 {
|
2024-08-27 12:12:31 +00:00
|
|
|
ds = make([]status.Status_Detail, 0, ln)
|
2021-11-06 10:38:52 +00:00
|
|
|
|
2024-09-04 12:44:59 +00:00
|
|
|
for i := range ln {
|
2024-08-27 12:12:31 +00:00
|
|
|
ds = append(ds, *x.details[i].ToGRPCMessage().(*status.Status_Detail))
|
2021-11-06 10:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.SetDetails(ds)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Status) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*status.Status)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2022-03-02 08:43:54 +00:00
|
|
|
ds []Detail
|
2021-11-06 10:38:52 +00:00
|
|
|
dsV2 = v.GetDetails()
|
|
|
|
)
|
|
|
|
|
|
|
|
if dsV2 != nil {
|
|
|
|
ln := len(dsV2)
|
|
|
|
|
2022-03-02 08:43:54 +00:00
|
|
|
ds = make([]Detail, ln)
|
2021-11-06 10:38:52 +00:00
|
|
|
|
2024-09-04 12:44:59 +00:00
|
|
|
for i := range ln {
|
2024-08-27 12:12:31 +00:00
|
|
|
if err := ds[i].FromGRPCMessage(&dsV2[i]); err != nil {
|
|
|
|
return err
|
2021-11-06 10:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x.details = ds
|
|
|
|
x.msg = v.GetMessage()
|
|
|
|
x.code = CodeFromGRPC(v.GetCode())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|