-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server streaming not implemented #79
Comments
Is it possible that you are using an older version of @protobuf-ts/grpc-transport? I've had server streaming running for some time now. See here for example:
It's a node CLI client using grpc-transport and server streaming. |
Ah wow, I didn't realize I had an older version in my package.json, sorry for that. I see that you're not using the |
I don't know about The goal for protobuf-ts is to be able to generate:
In addition to that, because it is trivial to implement and because users know them:
For gRPC client and server on node, I recommend I can't recommend using gRPC for production yet. That'll have to wait for the 2.0 release. |
I will go ahead and use the |
Hi @timostamm, I know this is off-topic, but since you are being so responsive and helpful, I thought I would ask you another question. I have a server and client I am testing together now. I am getting an error:
I'm thinking this is due to the data I am sending vs the schema? Do you have any tips on how to debug this type of issue or how to get more information on where the error is occurring? |
Ah. Yes, |
Looks like the error originates somewhere in @grpc/grpc-js. I would just patch in a gCall.addListener('error', err => {
console.log(err) // or err.stack? Then you can follow real the stack trace. |
@timostamm one more thing. I'm using |
Usage is pretty similar to other languages
let foo: Foo = Foo.create();
let any: Any = Any.pack(foo, Foo);
if (Any.contains(any, Foo)) {
foo = Any.unpack(any, Foo);
} If you want to send a message that contains a field with an any: message MyRequest {
google.protobuf.Any xxx = 1;
}
message Foo {} let foo: Foo = {};
let r: MyRequest = {
xxx : Any.pack(foo, Foo)
}; Any is just binary data of a message + a "type url" that contains the type name. The following is equivalent to Any.pack(): let any: Any = {
value: Foo.toBinary(foo),
typeUrl: "type.googleapis.com/Foo"
}; |
Thanks so much! I was having a lot of trouble finding TS usage examples. This would be helpful info for the readme, seems like everything online is outdated. |
Hey @timostamm still having some trouble here. In your example, the For example, this does not work, obviously because you can't have a type as a value: type User = {
firstName: string;
lastName: string;
};
GrpcTypes.Any.pack(data, User); Is there any way to use Any to represent types that are not part of the protobuf schema? |
This is an example for a good use case for any: message Status {
// The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
int32 code = 1;
// A developer-facing error message, which should be in English. Any
// user-facing error message should be localized and sent in the
// [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
string message = 2;
// A list of messages that carry the error details. There is a common set of
// message types for APIs to use.
repeated google.protobuf.Any details = 3;
} https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto When you create a status message, you put one of the messages defined in error_details.proto in the "details" field. But if your API has some special requirements where the messages defined in error_details.proto is not sufficients, it is totally fine to put a different message in there. |
If you really want to pack a "User" into the any, you should have some kind of protobuf declaration for this type. Or you could just create the type at runtime: let userType = new MessageType<UnknownMessage>("User", [
{no: 1, name: "firstName", kind: "scalar", T: ScalarType.STRING},
{no: 2, name: "lastName", kind: "scalar", T: ScalarType.STRING}
]);
let user = {
firstName: "a",
lastName: "b"
};
let any = Any.pack(user, userType); Of course you have to be pretty careful with that. There are no typescript interfaces preventing you from passing an invalid object. |
Or you could assemble the binary data yourself: let bytes = new BinaryWriter()
.fork()
.tag(1, WireType.LengthDelimited)
.string("a")
.tag(2, WireType.LengthDelimited)
.string("b")
.join()
.finish();
let any: Any = {
value: bytes,
typeUrl: "type.googleapis.com/User"
}; Terrible idea for maintenance, but possible :) |
Maybe google.protobuf.Struct is a better match for your use case? Structs allow arbitrary data. Same types as JSON. message Foo {
google.protobuf.Struct user = 1;
} let foo: Foo = {
user: Struct.fromJson({
firstName: "a",
lastName: "b"
})
} |
Ah, I think a Struct is exactly what I need! Thank you so much for this! You have been amazingly helpful. Please let me know if you have a donation link, I'm happy to support. |
Is there a way to make a server streaming client that works in NodeJS? I was trying to use the
promise-client
.The text was updated successfully, but these errors were encountered: