frostfs-node/pkg/services/control/convert.go

40 lines
747 B
Go
Raw Permalink Normal View History

package control
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
type requestWrapper struct {
message.Message
m grpc.Message
}
func (w *requestWrapper) ToGRPCMessage() grpc.Message {
return w.m
}
type responseWrapper[T grpc.Message] struct {
message *T
}
func newResponseWrapper[T grpc.Message]() *responseWrapper[T] {
return &responseWrapper[T]{
message: new(T),
}
}
func (w *responseWrapper[T]) ToGRPCMessage() grpc.Message {
return w.message
}
func (w *responseWrapper[T]) FromGRPCMessage(m grpc.Message) error {
response, ok := m.(*T)
if !ok {
return message.NewUnexpectedMessageType(m, w.message)
}
w.message = response
return nil
}