Go <-> NodeJS: Serialization question for non primitive types
- Dominant language
- TypeScript
- Stars
- 4.8k
- Forks
- 716
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 10
Description
### Problem description
This is more a question than a problem
We have a GRPC service written in Go, and a client written in Javascript (using Nodejs runtime).
Besides some primitives, we are using some google protobuf structures as follows:
```
message PredicateMatch {
message Entry {
google.protobuf.Timestamp timestamp = 1;
oneof value {
float scalar = 2;
string compound = 3;
}
}
...
```
When generating the types and using the proto loader in nodejs to get the responses
```ts
export interface _api_PredicateMatch_Entry {
'timestamp'?: (_google_protobuf_Timestamp | null); // this is an object with { seconds: string, nanos: number }
'scalar'?: (number | string);
'compound'?: (string);
'value'?: "scalar" | "compound";
}
```
The challenge is that we need to manually convert the Timestamp to an "almost equivalent" with a function like this:
```ts
export function convertProtoTimestampToUnixMs({ seconds, nanos }: { seconds: string; nanos: number }) {
return (parseInt(seconds) + nanos / 1e9) * 1000;
}
```
Is there a better way to do this? Is there a way to have some "hooks" or interceptors at the deserialization layer to make this abstraction execute in a better layer?
Contributor guide
Assessment
This issue has not been assessed yet.