frostfs-node/pkg/services/control/convert.go
Evgenii Stratonikov f73ac6e02d [#290] control: Use generics for response wrappers
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-04-28 10:57:24 +03:00

39 lines
747 B
Go

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
}