-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
[Protobuf] Optional properties not removed #848
Comments
It is possible to remove the optional property, and it is not hard for me. However, in that case, it makes the decoded object to be dynamic object, so that it cannot take advantage of hidden class optimization. Considering the purpose of protocol buffer for performance boosting, I think such dynamic object construction is not suitable for protocol buffer functions. How do you think about it?
|
@samchon The problem with this issue is that it unnecessarily increases the buffer size. And I think protobuf function should aim for networking performance over runtime performance. This issue obviously won't break the code but it's better to produce the smallest possible buffer for maximizing transferring speeds, while still guaranteeing type-safety. Normally, using JSON will require compressions as an extra step for minimizing data size. This is the data lifecycle when using JSON format. Receiving data -> Input buffer -> decompression -> JSON decode -> Input validation -> processing data -> Output validation -> JSON encode -> compression -> Output buffer -> Transferring data This is the developer's expected lifecycle. Receiving data -> Input buffer -> protobuf decode -> processing data -> protobuf encode -> Output buffer -> Transferring data So even a novice developer can see that there will be a massive performance boost when applying the second approach. Most developers know that it's very bad to use JSON instead of protobuf in terms of performance. But most protobuf libraries require defining an extra static schema for each message, which is extremely incovenient. Back to this issue, I think you should check for the existence of the // input
{a: undefined, b: 1}
// expected output
{a: undefined, b: 1}
//input
{b: 1}
// expected output
{b: 1} So the the code should be like this. if (!Object.getOwnPropertyDescriptor(input, "a")) {
delete output.a;
} |
If I adapt the second way of above picture, the dynamic property assignment, your goal would be accomplished. By the way, before determining whether accept your suggestion or not, I can't understand your word "increase the buffer size". In the Protocol Buffer spec, if do not insert anything to the buffer about a specific property, it means |
I've just double-check and I personally think that removing |
I will provide an option that turning on and off the delete statement at Saturday. |
This feature would be supported after TypeScript v5.3 release with ts-patch supporting |
If you want to use it earlier, then install like below: npm install typia@next |
Close #848 - `exactOptionalPropertyTypes` option for `typia.protobuf.decode<T>()` function.
Bug Report
It looks like typia is unexpectedly include optional property with value
undefined
after decoding with protobuf. Technically, it's considered a valid behavior by typescript but I think as a protobuf parser thentypia
should remove those properties instead.📝 Summary
Write a short summary of the bug in here.
Write detailed description in here.
⏯ Playground Link
https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDOAzKERwERIqp4DcAUGcAHYwCmUGqAxrXAAqpSogDOcA3mThxUALjg8YUagHNywgEbiqAVxAL65AL5lCrAPJgYwCFVQAbDl15wAvO07GLAHivceAPnJkmpyXFoqXwATWmC3G3tCNAA6MGwYCAUVDBjAkNpnQ2NTCwjPAAp+LQBKcl8qfzBOdzsEZFj4iETk1NCMrKMTM0sa3g8C9IhQ8L6eMp8-CHNaGPMIGQLq63GSIA
💻 Code occuring the bug
The text was updated successfully, but these errors were encountered: