-
Notifications
You must be signed in to change notification settings - Fork 913
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
Serialize and deserialize protocol buffers #2667
Comments
@kyleconroy This is a great idea, I'm using vtprotobuf a lot currently and it works great. Having some kind of auto-transpiler that automatically converts the reflection-based protobuf-go to use vtprotobuf would be great. Quick question: as of March 2023, it seems like most of the reflection features are supported - is there anything missing for the existing reflection version to work currently? |
And even more reflect is working, including the last bug on you roadmap. |
@kyleconroy @dgryski looking at the roadmap is it time for the confetti emoji? |
So it seems that the default protobuf compiler is not supported still even with the improvements to reflection. I have yet to test
|
FWIW I have successfully used https://github.com/planetscale/vtprotobuf to marshal/unmarshal protobuf in tinygo -target=wasi (this can be closed then?) |
How are you able to use vtprotobuf with tinygo? Isn't the generated code from vtprotobuf depends on the result of protobuf-go? I am still getting the same error with my |
The reflection methods are stubbed out, so it still compiles and the vtprotobuf version doesn't invoke the reflection methods, so it works fine for me.
Post the error and make sure you're on the latest tinygo version |
I am on the latest tinygo v0.31.1, and I am also using it with wasmtime. The error I got is exactly the same with the one you posted before without using vtprotobuf. Did you change any of the code generated by |
no modifications needed. Can you post a reproduction? |
I am so sorry to bother u, it was me making a dumb mistake causing the error, I fixed the error and it works totally fine. Thank you so much. |
vtprotobuf generates static code for Marshal and Unmarshal. We just need a version of protoc-gen-go that does not import reflect nor any of the "heavy" protobuf packages that add a lot of complexity to the resulting binary. I have forked to protoc-gen-go-lite here and have already dropped everything but the protoc plugin, and am working on adjusting the compiler to generate bare structs without referencing reflect: aperturerobotics/protobuf-go-lite#1 Please join the effort there as this is intended to make it easier to build lightweight tinygo protobuf projects. |
vtprotobuf generates static code for Marshal and Unmarshal. We just need a version of protoc-gen-go that does not import reflect nor any of the "heavy" protobuf packages that add a lot of complexity to the resulting binary. tinygo-org/tinygo#2667 Drop all unused code and fix linter warnings. Signed-off-by: Christian Stewart <christian@aperture.us>
vtprotobuf generates static code for Marshal and Unmarshal. We just need a version of protoc-gen-go that does not import reflect nor any of the "heavy" protobuf packages that add a lot of complexity to the resulting binary. tinygo-org/tinygo#2667 Drop all unused code and fix linter warnings. Signed-off-by: Christian Stewart <christian@aperture.us>
vtprotobuf generates static code for Marshal and Unmarshal. We just need a version of protoc-gen-go that does not import reflect nor any of the "heavy" protobuf packages that add a lot of complexity to the resulting binary. tinygo-org/tinygo#2667 Drop all unused code and fix linter warnings. Drop protoimpl.EnforceVersion lines Add link to vtprotobuf-lite Drop weak fields, extensions, json marshal, errors pkg. Signed-off-by: Christian Stewart <christian@aperture.us>
vtprotobuf generates static code for Marshal and Unmarshal. We just need a version of protoc-gen-go that does not import reflect nor any of the "heavy" protobuf packages that add a lot of complexity to the resulting binary. tinygo-org/tinygo#2667 Drop all unused code and fix linter warnings. Drop protoimpl.EnforceVersion lines Add link to vtprotobuf-lite Drop weak fields, extensions, json marshal, errors pkg. Drop testprotos. Signed-off-by: Christian Stewart <christian@aperture.us>
vtprotobuf generates static code for Marshal and Unmarshal. We just need a version of protoc-gen-go that does not import reflect nor any of the "heavy" protobuf packages that add a lot of complexity to the resulting binary. tinygo-org/tinygo#2667 Drop all unused code and fix linter warnings. Drop protoimpl.EnforceVersion lines Add link to vtprotobuf-lite Drop weak fields, extensions, json marshal, errors pkg. Drop testprotos. Signed-off-by: Christian Stewart <christian@aperture.us>
vtprotobuf generates static code for Marshal and Unmarshal. We just need a version of protoc-gen-go that does not import reflect nor any of the "heavy" protobuf packages that add a lot of complexity to the resulting binary. tinygo-org/tinygo#2667 Drop all unused code and fix linter warnings. Drop protoimpl.EnforceVersion lines Add link to vtprotobuf-lite Drop weak fields, extensions, json marshal, errors pkg. Drop testprotos. Hand-write String() for timestamp and duration. Signed-off-by: Christian Stewart <christian@aperture.us>
I have completed protobuf-go-lite which is a reflection-free fork of protobuf-go merged with vtprotobuf and protoc-gen-go-json. Library: https://github.com/aperturerobotics/protobuf-go-lite RPCs are available as well with starpc: https://github.com/aperturerobotics/starpc protobuf-go-lite now supports reflection-free protobuf and protojson encoding! |
This is a version of protobuf-go that does not use reflection. Reflection adds weight to the compiled binary and is not supported fully by tinygo. We can eliminate the requirement on reflect with vtprotobuf, which generates static code for Marshal and Unmarshal. tinygo-org/tinygo#2667 This commit merges vtprotobuf and protobuf-go-lite into a single repo. This allows tightly integrating the protobuf-go compiler and the vtprotobuf compiler, generating a single .pb.go file instead of multiple files. This also allows radical simplifications of the protobuf compiler plugin and the generated vtprotobuf code, eliminating the need for extra wrapper code. Major changes from upstream: - Drop all unused code and fix linter warnings. - Drop pooling - Add link to protobuf-go-lite - Drop grpc - Drop exts - Drop references to ProtoPkg - Dropped pool from vtprotobuf - Dropped MessageSet (deprecated) - Dropped any (requires reflect) - Dropped fieldmask (requires reflect) - Dropped the -wrap option for vtprotobuf - Allow import paths without slashes in protogen - Derive Go package name from the proto3 package name - Derive Go import path from the proto3 adjacency to Go packages - Generate a String() for enums which does not use reflect Signed-off-by: Christian Stewart <christian@aperture.us>
This is a reflection-less version of protobuf-go with vtprotobuf. Now starpc works without the reflect package, which is much better for supporting platforms like WebAssembly and tinygo, where every import matters in terms of managing binary size, and the reflection support may be limited. Reflection adds weight to the compiled binary and is not supported fully by tinygo. We can eliminate the requirement on reflect with vtprotobuf, which generates static code for Marshal and Unmarshal. See: tinygo-org/tinygo#2667 See: aperturerobotics/protobuf-go-lite@e0016a1 Signed-off-by: Christian Stewart <christian@aperture.us>
This commit implements protojson support by merging in a fork of: https://github.com/TheThingsIndustries/protoc-gen-go-json protoc-gen-go-json has been heavily modified to integrate cleanly with vtprotobuf and the rest of protobuf-go-lite. Currently proto2 and proto3opt are not supported w/ the json feature. This implements reflection-free protojson support for tinygo: tinygo-org/tinygo#2667 (comment) Signed-off-by: Christian Stewart <christian@aperture.us>
As outlined in #447, TinyGo should support common serialization formats. While most people may think of JSON, I personally want TinyGo to support protocol buffers. This issue is meant to track my progress on adding Protocol Buffer support to TinyGo.
Design
The default Protocol Buffer package (https://pkg.go.dev/google.golang.org/protobuf) makes heavy use of reflection. TinyGo only supports a small amount of the
reflect
package. Heavy use of reflection leads to slow code, so the folks at PlanetScale wrote vtprotobuf, which generates explicit serialization / deserialization code. This code works today with TinyGo. However, it requires the existing, slow code to compile.So the plan is simple: Support compiling the code generated by protoc-gen-go and running and of the code contained in
init()
functions. Use the code generated by vtprotobuf to serialize and deserialize the data.Roadmap
env::sync/atomic.StoreUint32
has not been defined #2652The text was updated successfully, but these errors were encountered: