gRPC Any type - Uncaught TypeError: deserialize is not a function

Viewed 404

I'm having an issue in gRPC that's been driving me crazy. I have a .NET gRPC service that my ReactJS client is connecting to - this works fine. I'm subscribing to my stream, and I get data over the stream as expected. I'm having an issue deserializing "google.protobuf.Any" types that exist in my messages. The one I'm receiving looks like this:

message PointNotification {
    KindsOfPointNotification Kind = 1;
    google.protobuf.Any NotificationData = 2;
}

Inside of the ReactJS client I am doing the following:

useEffect(() => {
    console.log("Subscribing to point stream");
    var pointStream = client.subscribeToNotificationStream(new Empty(), {});
    pointStream.on("data", (response) => {
        switch (response.getKind())
        {
            case KindsOfPointNotification.KINDS_OF_POINT_NOTIFICATION_POINT_ADDED_OR_UPDATED:
                const any = response.getNotificationdata();
                console.log(any);
                const bar = any.unpack(NotificationPointAddedOrUpdated.deserializeBinary, any.getTypeName());
                console.log(bar);
                break;
            case KindsOfPointNotification.KINDS_OF_POINT_NOTIFICATION_POINT_REMOVED:
                console.log("Point removed");
                break;
        }
    });

The "any" variable looks right in the browser logs. The payload, and the typeName are correct. However when I go to unpack "any" I get the following error (screenshot):

TypeError in browser

Uncaught TypeError: deserialize is not a function

This is despite the fact that the generated _pb file has the following method:

/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.Point.NotificationPointAddedOrUpdated}
*/
proto.Point.NotificationPointAddedOrUpdated.deserializeBinary = function(bytes) {
   var reader = new jspb.BinaryReader(bytes);
   var msg = new proto.Point.NotificationPointAddedOrUpdated;
   return proto.Point.NotificationPointAddedOrUpdated.deserializeBinaryFromReader(msg, 
   reader);
};

According to The documentation this is correct way to do it. What am I missing? Why am I getting a deserialize error?

Edit: I have one other thing to add. If I change the following line:

const bar = any.unpack(NotificationPointAddedOrUpdated.deserializeBinary, any.getTypeName());

To:

const bar = any.unpack(NotificationPointAddedOrUpdated.deserializeBinary(), any.getTypeName());

The error I get in the browser changes to:

Uncaught TypeError: _proto_pointdata_pb_js__WEBPACK_IMPORTED_MODULE_3___default(...).deserializeBinary is not a function
1 Answers
Related