gRPC and Protocol Buffers
In gRPC, a client application can directly call a method on a server application on a different machine as if it were a local object, making it easier to create distributed applications and services. As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. On the server side (Token.io Cloud), the server implements this interface and runs a gRPC server to handle client calls. On the client side, the client has a stub that provides the same methods as the server.
Here's the best way to think about it (click to enlarge):
gRPC clients and servers can run and talk to each from different environments. For instance, a gRPC server in Java can support clients in Javescript, C# or Java.
Using protocol buffers (or protobuffs, for short), serialized information is structured by defining protocol buffer message types in .proto files. Each protocol buffer message is a small logical record of information, containing a series of name-value pairs. A fairly simple example of a .proto file that defines a message containing information about a Token.io business member might look like this:
message
Signature
{
string member_id
= 1;
string key_id
= 2;
string signature
= 3;
}
The protocol buffer compiler then generates data access classes. These provide simple accessors for each field — like member_id() and set_member_id() — as well as methods to serialize/parse the whole structure to/from raw bytes. Hence, building a Signature in JavaScript is as easy as:
Signature
{
memberId
= 'member_id string',
keyId
= 'key_id string',
signature
= 'signature string'
}
In JavaScript, the object corresponding to a protocol buffer message has fields with camel-case names. Protocol buffer field member_id in Signature therefore becomes the JavaScript field memberId, key_id becomes keyId, and so forth.Thus, a protocol buffer string becomes a JavaScript string; a protocol buffer number becomes a JavaScript number. A protocol buffer enum value becomes a JavaScript string. For example, if a .proto enum has a value of ENDORSED = 1, then in JavaScript, this value is 'ENDORSED'. A repeated protocol buffer field becomes a JavaScript array. Protocol buffer bytes become a JavaScript string representing the Base64 encoding of those bytes.
For more on protocol buffers and gRPC from developers.google.com, click the respective link.