VOL-2001 resolve sca errors
Change-Id: Iee4c814e721437c6f2f0d3387cac92be498ceb99
diff --git a/internal/pkg/afrouter/codec.go b/internal/pkg/afrouter/codec.go
index 278fc0a..b11d102 100644
--- a/internal/pkg/afrouter/codec.go
+++ b/internal/pkg/afrouter/codec.go
@@ -17,22 +17,34 @@
package afrouter
import (
- "fmt"
"github.com/golang/protobuf/proto"
"github.com/opencord/voltha-go/common/log"
- "google.golang.org/grpc"
+ "google.golang.org/grpc/encoding"
)
-func Codec() grpc.Codec {
+/*
+ * encoding.Codec renamed grpc.Codec's String() method to Name()
+ *
+ * grpc.ForceCodec() expects an encoding.Codec, alternative use of grpc.Codec is deprecated
+ * grpc.CustomCodec() expects a grpc.Codec, has no mechanism to use encoding.Codec
+ *
+ * Make an interface that supports them both.
+ */
+type hybridCodec interface {
+ encoding.Codec
+ String() string
+}
+
+func Codec() hybridCodec {
return CodecWithParent(&protoCodec{})
}
-func CodecWithParent(parent grpc.Codec) grpc.Codec {
+func CodecWithParent(parent encoding.Codec) hybridCodec {
return &transparentRoutingCodec{parent}
}
type transparentRoutingCodec struct {
- parentCodec grpc.Codec
+ parentCodec encoding.Codec
}
// responseFrame is a frame being "returned" to whomever established the connection
@@ -74,7 +86,15 @@
case *responseFrame:
t.payload = data
// This is where the affinity is established on a northbound response
- t.router.ReplyHandler(v)
+
+ /*
+ * NOTE: Ignoring this error is intentional. MethodRouter returns
+ * error when a reply is not processed for northbound affinity,
+ * but we still need to unmarshal it.
+ *
+ * TODO: Investigate error-return semantics of ReplyHandler.
+ */
+ _ = t.router.ReplyHandler(v)
return nil
case *requestFrame:
t.payload = data
@@ -93,8 +113,12 @@
}
}
+func (cdc *transparentRoutingCodec) Name() string {
+ return cdc.parentCodec.Name()
+}
+
func (cdc *transparentRoutingCodec) String() string {
- return fmt.Sprintf("%s", cdc.parentCodec.String())
+ return cdc.Name()
}
// protoCodec is a Codec implementation with protobuf. It is the default Codec for gRPC.
@@ -108,6 +132,6 @@
return proto.Unmarshal(data, v.(proto.Message))
}
-func (protoCodec) String() string {
+func (protoCodec) Name() string {
return "protoCodec"
}