-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[TS] optional escalar not set in the binary when it holds value 0 #8245
Comments
It sounds like some wrong |
No, the code correctly checks for |
My suggestion here would be that for an optional field, the default value would be |
Indeed this is how it's done in C++. There, if the field is optional it is unconditionally written in the buffer, if set. |
I see that we can simply set force defaults in the builder. I'll test this later. |
If I make the
then this is the diff in the generated TypeScript code: diff -bur /tmp/fbs/consumer/consumer-layers.ts node/src/fbs/consumer/consumer-layers.ts
--- /tmp/fbs/consumer/consumer-layers.ts 2024-02-29 13:06:59
+++ node/src/fbs/consumer/consumer-layers.ts 2024-02-29 13:07:12
@@ -27,9 +27,9 @@
return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
}
-temporalLayer():number|null {
+temporalLayer():number {
const offset = this.bb!.__offset(this.bb_pos, 6);
- return offset ? this.bb!.readUint8(this.bb_pos + offset) : null;
+ return offset ? this.bb!.readUint8(this.bb_pos + offset) : 0;
}
static startConsumerLayers(builder:flatbuffers.Builder) {
@@ -49,10 +49,9 @@
return offset;
}
-static createConsumerLayers(builder:flatbuffers.Builder, spatialLayer:number, temporalLayer:number|null):flatbuffers.Offset {
+static createConsumerLayers(builder:flatbuffers.Builder, spatialLayer:number, temporalLayer:number):flatbuffers.Offset {
ConsumerLayers.startConsumerLayers(builder);
ConsumerLayers.addSpatialLayer(builder, spatialLayer);
- if (temporalLayer !== null)
ConsumerLayers.addTemporalLayer(builder, temporalLayer);
return ConsumerLayers.endConsumerLayers(builder);
}
@@ -74,7 +73,7 @@
export class ConsumerLayersT implements flatbuffers.IGeneratedObject {
constructor(
public spatialLayer: number = 0,
- public temporalLayer: number|null = null
+ public temporalLayer: number = 0
){} |
So AFAIS here the problem in addFieldInt8(voffset: number, value: number, defaultValue: number): void {
if (this.force_defaults || value != defaultValue) {
this.addInt8(value);
this.slot(voffset);
}
} When a The question here is, why is this
Yes, forcing the defaults would "fix" the problem but the issue does exist. |
Well, it's called with static addTemporalLayer(builder:flatbuffers.Builder, temporalLayer:number) {
builder.addFieldInt8(1, temporalLayer, 0);
} Notice that 3rd argument ( So setting |
This is defintely not an option as the C++ side is crashing with a SIGBUS, indicating there are issues when reading the buffer. This happens if doing a The solution here would be as suggested:
|
So this problem seem to be solved already since Sept 2023 #7864 But the last flatbuffer version (which we are using) was released in May 2023. When is the next version being released? |
10 months without releasing a new version (having obvious bug fixes merged in master branch in the meantime) worries me a lot. |
- Due to an issue in Flatbuffers (google/flatbuffers#8245) when we call `consumer.setPreferredLayers()` with `temporalLayer: 0`, we are NOT passing `temporalLayer` to the worker so it selects the highest available temporal layer instead. - This PR tests that use case in both Node and Rust, and tests should fail until the Flatbuffers issue is resolved. - BTW the Flatbuffers issue was already fixed long ago (google/flatbuffers#8245) but well, maintainers have not released a new version since May 2023 because whatever inexplicable reason.
Ok, ticket created asking for a new release: #8246 |
- Due to an issue in Flatbuffers (google/flatbuffers#8245) when we call `consumer.setPreferredLayers()` with `temporalLayer: 0`, we are NOT passing `temporalLayer` to the worker so it selects the highest available temporal layer instead. - This PR tests that use case in both Node and Rust, and tests should fail until the Flatbuffers issue is resolved. - BTW the Flatbuffers issue was already fixed long ago (google/flatbuffers#8245) but well, maintainers have not released a new version since May 2023 because whatever inexplicable reason.
I've tested the new release 24.3.6 and confirm that this issue is fixed (no surprise of course), so I think we can close this issue. |
flatbuffers: 23.5.26
Having the current schema:
Creating a buffer with
temporal_layer = 0
results in a buffer without the temporal layer field.I the field was not optional then skipping the field in the binary would make sense, but being it optional, how st the app supposed to distinguish between the field containing a 0 and it not being present?
The text was updated successfully, but these errors were encountered: