We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
protobuf.js version: <7.4.0>
How can I put any message in the "child" field just similar to google.protobuf.any ?
import { Message, Type, Field, OneOf, } from 'protobufjs/light'; // respectively "./node_modules/protobufjs/light.js" export class ChildString extends Message<ChildString> { @Field.d(1, 'string') public someString: string = ''; } export class ChildNumber extends Message<ChildNumber> { @Field.d(1, 'int32') public someNumber?: number; } export class ParentMessage extends Message<ParentMessage> { @Field.d(1, 'string') public name?: string; @Field.d(2, Message) // Any of ChildString or ChildNumber etc... public child?: Message; } const childMessage = new ChildString(); childMessage.someString = 'Hello World'; const parentMessage = new ParentMessage(); parentMessage.name = 'John'; parentMessage.child = childMessage; let buffer = ParentMessage.encode(parentMessage).finish(); let decodedMessage = ParentMessage.decode(buffer); console.info('output:', decodedMessage); const childMessage2 = new ChildNumber(); childMessage2.someNumber = 123; parentMessage.child = childMessage2; buffer = ParentMessage.encode(parentMessage).finish(); decodedMessage = ParentMessage.decode(buffer); console.info('output:', decodedMessage); >
Result
output: ParentMessage { name: 'John', child: Message {} } output: ParentMessage { name: 'John', child: Message {} }
Both output of "child" field is empty.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
protobuf.js version: <7.4.0>
How can I put any message in the "child" field just similar to google.protobuf.any ?
Result
Both output of "child" field is empty.
The text was updated successfully, but these errors were encountered: