2021-03-15 11:04:13 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
2021-03-15 11:04:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type requestWrapper struct {
|
|
|
|
message.Message
|
|
|
|
m grpc.Message
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *requestWrapper) ToGRPCMessage() grpc.Message {
|
|
|
|
return w.m
|
|
|
|
}
|
|
|
|
|
2023-04-27 10:38:25 +00:00
|
|
|
type responseWrapper[T grpc.Message] struct {
|
|
|
|
message *T
|
2021-03-15 11:04:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 10:38:25 +00:00
|
|
|
func newResponseWrapper[T grpc.Message]() *responseWrapper[T] {
|
|
|
|
return &responseWrapper[T]{
|
|
|
|
message: new(T),
|
2021-03-15 11:04:13 +00:00
|
|
|
}
|
2023-04-07 11:21:05 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 10:38:25 +00:00
|
|
|
func (w *responseWrapper[T]) ToGRPCMessage() grpc.Message {
|
|
|
|
return w.message
|
2023-04-07 11:21:05 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 10:38:25 +00:00
|
|
|
func (w *responseWrapper[T]) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
response, ok := m.(*T)
|
2023-04-07 11:21:05 +00:00
|
|
|
if !ok {
|
2023-04-27 10:38:25 +00:00
|
|
|
return message.NewUnexpectedMessageType(m, w.message)
|
2023-04-07 11:21:05 +00:00
|
|
|
}
|
|
|
|
|
2023-04-27 10:38:25 +00:00
|
|
|
w.message = response
|
2023-04-07 11:21:05 +00:00
|
|
|
return nil
|
|
|
|
}
|