protobufjs / protobuf.js

Protocol Buffers for JavaScript & TypeScript.
Other
9.96k stars 1.42k forks source link

support of protoset binary format? #1117

Open c0b opened 6 years ago

c0b commented 6 years ago

from grpc/grpc-node#556 wonder is the protoset binary format already supported? or can be added?

I have searched the keyword of grpc + nodejs + protoset on google and within this repo, nothing found so far

protobuf.load("awesome.protoset", function(err, root) {
  ...
}

I see the compiled protoset binary format is a good solution to bundle many related *.proto files into a single one file, it's pretty well supported by protoc compiler, and in Go language pkg github.com/golang/protobuf, and tools like grpcurl https://github.com/fullstorydev/grpcurl#protoset-files https://github.com/golang/protobuf/tree/master/protoc-gen-go/descriptor

$ protoc --help
Usage: protoc [OPTION] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:
  -IPATH, --proto_path=PATH   Specify the directory in which to search for
                              imports.  May be specified multiple times;
                              directories will be searched in order.  If not
                              given, the current working directory is used.

  -oFILE,                     Writes a FileDescriptorSet (a protocol buffer,
    --descriptor_set_out=FILE defined in descriptor.proto) containing all of
                              the input files to FILE.
c0b commented 6 years ago

hello?

dcodeIO commented 6 years ago

Looked over protoset pretty quick, appears to be binary encoded file descriptor sets. There is no first-class support, but there's an extension that might be useful: https://github.com/dcodeIO/protobuf.js/tree/master/ext/descriptor

c0b commented 5 years ago

from https://github.com/grpc/grpc-node/issues/550#issuecomment-443163398 I want to report a problem not sure which side can resolve it better?

because most grpc uses this require('@grpc/proto-loader') package's load or loadSync and that's the only exported methods, and it seems the authors of @grpc/proto-loader are reluctant to export more, the load or loadSync method's problem is they do load plain text *.proto files only,

to make it work with the require("protobufjs/ext/descriptor") I have to export the createPackageDefinition method from this module, but they're not willing to do so, so my temporary solution is to keep a copy its compiled code, and change createPackageDefinition method to be exported, I name it as loader.js and uses in my project require("./loader.js").createPackageDefinition(root, ...)

source code is mainly in this ts file

https://github.com/grpc/grpc-node/blob/master/packages/proto-loader/src/index.ts

example code from https://github.com/grpc/grpc/blob/master/examples/node/dynamic_codegen/greeter_client.js

var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
    PROTO_PATH,
    { keepCase: true, longs: String, enums: String, defaults: true, oneofs: true, });
var hello_proto = grpc.loadPackageDefinition(packageDefinition).helloworld;

keep a private copy is not a good solution, hope either side can have a better one

tatemz commented 4 years ago

+1 if file descriptor sets are a supported feature of protoc, then we will need the ability to create PackageDefinition objects using them.

keep a private copy is not a good solution, hope either side can have a better one

tatemz commented 4 years ago

@dcodeIO or @nicolasnoble Do you have time to look at the linked graphql-mesh issue (1086) and offer advice? I would love the comments by @c0b to be addressed as I am in the same predicament. It seems the path forward on this is to fork this project.