Comments (6)
Yes, extend is not fully supported. One goal was to keep the library small, but I'd also be happy to see a PR for this 👍
from protobuf.js.
I am trying to add support for extend here: https://github.com/danielflower/ProtoBuf.js/commits/master
Given the following:
message Foo {
optional string blah = 1;
extensions 1000 to max;
}
extend Foo {
optional int32 bar = 1001;
}
message Person {
extend Foo {
optional Person person = 1002;
}
required string name = 1;
required int32 id = 2;
optional string email = 3;
}
...you can work with Foo as if the extend blocks were directly on Foo (this is a little different from, Java, say, where you had to call special setExtension()/getExtension() methods.
var Foo = builder.build("Foo");
var foo = new Foo({
"blah": "blahValue",
"bar": 12,
person: {
"name": "Nancy",
"id": 123
}
});
I will do more testing before making a pull request.
from protobuf.js.
Hi Daniel,
Are you ready to pull request your patch? I also want to use "extend" in my protobuf. Your change is good to me. Thanks.
from protobuf.js.
The library already supports extend in most common use cases. What's described here are rather a couple of edge cases.
from protobuf.js.
The edge cases you mentioned is like the above one (internal definitions), right? ex.
message Foo {
optional string blah = 1;
extensions 1000 to max;
}
message PersonA {
extend Foo {
optional PersonA person = 1001;
}
required string name = 1;
}
message PersonB {
extend Foo {
optional PersonB person = 1002;
}
required int32 = 1;
}
If I want to parse this message buffer, it may has problems now, right?
// data is the input ArrayBuffer which was already encoded by the remote side.
var bytebuf = dcodeIO.ByteBuffer.wrap(data);
var foo = builder.build("Foo");
var packet = foo.decode(bytebuf); // Could this work if I added extend PersionA or PersionB already?
from protobuf.js.
Internal definitions are not used by / available with ProtoBuf.js, but this should work as of today:
message Foo {
optional string blah = 1;
extensions 1000 to max;
}
message PersonA {
extend Foo {
optional PersonA persona = 1001;
}
required string name = 1;
}
message PersonB {
extend Foo {
optional PersonB personb = 1002;
}
required int32 bleh = 1;
}
And is equivalent to:
message Foo {
optional string blah = 1;
extensions 1000 to max;
}
message PersonA {
required string name = 1;
}
message PersonB {
required int32 bleh = 1;
}
extend Foo {
optional PersonA persona = 1001;
optional PersonB personb = 1002;
}
from protobuf.js.
Related Issues (20)
- How to decode grpc-web-text
- Enum value ignored HOT 1
- Fails to parse "{" in options
- int64 precesion problem
- Enum reserved keyword removed when compiling proto from json
- Add Auth to Xhr fetch
- The problem with load
- Update from version 6.x.x to version 7.x.x
- not support eval and new Function()/Function() HOT 2
- how do you type decode(...)
- how do I type a namespace?
- how to fix property does not exist on type "Message<MessageType>"
- Cannot read properties of undefined (reading 'add') HOT 3
- protobuff.encode() does not work as expected
- Backport prototype setProperty checks to 6.11.3 HOT 5
- protobufjs-cli still pull older version of escodegen HOT 3
- [Feature Request] Explore all files in a folder/subfolder
- CVE-2022-25878 - Fix for version 5.0.3 HOT 3
- Decoding fails sometimes, logs attached HOT 1
- CVE-2023-36665 - Fix not reflected in dist version HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf.js.