Please provide a small, self-contained hello world sample jsfiddle with (<script src="https://cdn.rawgit.com/dcodeIO/protobuf.js/master/dist/protobuf.min.js" />) for beginners.
I was trying and failing to assemble one example:
"Hello World!", an integer 123 and a float -123.456This way one example will cover how to reference this lib on a simple HTML page (with no other external dependencies), usage of types and encode/decode APIs. If someone then wants to incorporate the code in their project using commonJS/es6/amd etc. they can easily convert it.
Thanks!
@kasper3 here are some examples here
Thanks! I was hoping to have a very basic browser-based example (no deps on running server or node.js etc.) which creates a message object, serialize it to binary protobuf, then deserialize that binary back to object to assert:
assert.equal(originalObject, deserialize(serialize(originalObject)))
I was looking to represent .proto in .json and use grpc in node and was really happy to find this repo. :thumbsup:
However, I am looking to figure out a basic example of grpc using protobufjs.
I did manage to convert .proto to .json using pbjs (see below).
Can any of the moderators provide the code for greeter_server.js and greeter_client.js using protobufjs please. 馃檹 馃檹
syntax = "proto3";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
{
"nested": {
"helloworld": {
"nested": {
"Greeter": {
"methods": {
"SayHello": {
"requestType": "HelloRequest",
"responseType": "HelloReply"
}
}
},
"HelloRequest": {
"fields": {
"name": {
"type": "string",
"id": 1
}
}
},
"HelloReply": {
"fields": {
"message": {
"type": "string",
"id": 1
}
}
}
}
}
}
}
Most helpful comment
Thanks! I was hoping to have a very basic browser-based example (no deps on running server or node.js etc.) which creates a message object, serialize it to binary protobuf, then deserialize that binary back to object to assert:
assert.equal(originalObject, deserialize(serialize(originalObject)))