-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Let's talk about static code generation #512
Comments
This is how generated code looks like currently: https://github.com/dcodeIO/protobuf.js/blob/master/tests/data/package.js Of course it is missing reflection entirely and there is no asJSON or services, yet. On the other hand, it only requires a super minimal runtime. |
I think for me being able to write custom targets for the CLI would be nice, instead of having to pick from premade targets something like Currently there is no way to "plug in" to the CLI and do custom things. |
Specifying a path to an alternative I've also updated the static target to support AMD, CommonJS and the global scope, depending on what is available. Additionally, the |
Now also generates services (example). |
Can we generate a TypeScript definition with the static bundle? |
Most likely, just as we do with the library itself, we could run tsd-jsdoc on the static output. |
hello, I come from china, My english not good,I have a question for you, Please help me, Thank you // login.proto
package login;
syntax = "proto3";
message CheckVersionRequest
{
int32 game_id = 1;
} require.config({
paths: {
long:'src/protobuf3/node_modules/protobufjs/node_modules/long/dist/long',
protobuf:'src/protobuf3/node_modules/protobufjs/dist/protobuf',
messageManager3:'src/protobuf3/messageManager3'
}
});
require(['protobuf'],
function(protobuf){
protobuf.load("/src/protobuf3/login.proto",
function(err, root)
{
if (err) throw err;
var CheckVersionRequest = root.lookup("login.CheckVersionRequest");
var message = CheckVersionRequest.create({game_id:4});
var buffer = CheckVersionRequest.encode(message).finish();
cc.log("--------------checkVersionReques=", CheckVersionRequest);
cc.log("--------------message=", message);
cc.log("--------------buffer=", buffer, "byteLength=", buffer.byteLength);
}
)
}
); why buffer is empty? |
It's now possible to generate TypeScript definitions from static modules. |
The static runtime is now also available for browser usage. It works with statically generated modules only - at 5.4kb gzipped. |
@chuanglovelily Sorry, I looked over it briefly, but I cannot identify the issue. Consider creating a dedicated issue if it still isn't working with current master (this issue thread appears to be the wrong place to me). |
Most of the things I wanted to do are in now, so I am closing this for now. |
There have been quite a lot of requests for static code generation in the past. Personally, I'd not absolutely require it with v6's built-in codegen, but there certainly are valid use cases where having actual code to reference makes sense (i.e. when using TypeScript).
I know that a few people already started working on something for v5, so I added a static stub to v6's pbjs that can be used as a reference: https://github.com/dcodeIO/protobuf.js/blob/master/cli/targets/static.js
I also made sure that built-in code generation can be reused to write encode/decode functions on top of static code. See Type#decode / Type#encode for an example on how to bind a scope and make it output a function.
If you have any suggestions or want to tackle it, let me know!
The text was updated successfully, but these errors were encountered: