Skip to content

Conversation

@jtdavis777
Copy link
Collaborator

This PR adds in an extra field to the reflection.fbs that holds string representations of non scalar defaults -- vectors and strings, specifically.

This isn't the 'best' way to accomplish this, but I think its the most pragmatic given how prolific the Value struct is in the code base.

Accepting suggestions for better names!

@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Aug 14, 2025
@jtdavis777
Copy link
Collaborator Author

@dbaileychess and @aardappel interested to hear your collective take on this one! I realized this was missing while working on the wireshark generator.

@aardappel
Copy link
Collaborator

This PR has formatting and other changes that appear not directly related that make it hard to review.

Why is the new bool in Value needed? Doesn't the Type already tell you if it is scalar or not?

@jtdavis777
Copy link
Collaborator Author

This is getting at the inelegance of the design -- much of the code relies on the constant string being default constructed as "0". Pair that with std::string not being able to differentiate between empty and unset and you end up either needing to do a large refactor, or pull some shenanigans like this.

I tried to just default construct constant and set it to 0 if a scalar type, but then I couldn't tell the difference between "user set default to "" and no default. Which is probably okay? But with all of the modifications needed to go that route it seemed wrong. I can try that again if the bfbs doesn't need to tell the difference between set to empty and unset, maybe I tried too many things at once.

@jtdavis777
Copy link
Collaborator Author

in reading up on the non scalar defaults more (#6053), it does seem that the bfbs would need to differentiate between being provided a default ( = "") and not being provided one (nullptr) -- std::string doesn't have a mechanism to differentiate this, so I'm left with

  1. adding a boolean (implemented here)
  2. wrapping the constant member in some sort of std::optional-esque thing (which I did try, it got messy real fast)
  3. injecting and removing an extra set of "" when a non scalar default is provided (so that .empty()) would mean nothing provided and """" would be equivalent to "" which would be set in the bfbs

1 or 3 would work for me, and I can work to remove the auto formatting to make the pr easier to review (vscode format go brrrrrr)

@jtdavis777 jtdavis777 force-pushed the feature/non_scalar_default_bfbs_support branch from 148d925 to d92b677 Compare August 21, 2025 01:08
@jtdavis777
Copy link
Collaborator Author

there were only two lines of formatting changes -- the other change is flatc now generates scoped enums instead of unscoped.

@aardappel
Copy link
Collaborator

@dbaileychess your review here would be helpful

@jtdavis777 jtdavis777 changed the title Add non scalar support to BFBS files Add non scalar default support to BFBS files Aug 27, 2025
@jtdavis777 jtdavis777 force-pushed the feature/non_scalar_default_bfbs_support branch from ca5d722 to 22fa6e2 Compare August 29, 2025 12:49
@jtdavis777 jtdavis777 force-pushed the feature/non_scalar_default_bfbs_support branch from 22fa6e2 to 64f8e55 Compare November 5, 2025 14:13
@jtdavis777 jtdavis777 force-pushed the feature/non_scalar_default_bfbs_support branch from 64f8e55 to bf03023 Compare December 6, 2025 01:50
@jtdavis777 jtdavis777 added the ready-for-merge This PR has been approved by a maintainer and is ready for merge by a code owner label Dec 20, 2025
@jtdavis777
Copy link
Collaborator Author

not 100% ready for merge but want to get it into the review pipeline

padding:uint16 = 0;
/// If the field uses 64-bit offsets.
offset64:bool = false;
default_non_scalar:string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a better long term solution is to have a default_value field that is of type Union (long, string, short, etc..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you want me to deprecate the old constant field to do so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also have to be a union of struct of primitive, since unions of primitives aren't a thing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not great to remove the existing fields.. so we may as well continue with the current pattern?

Just not great to merge strings and vectors into 1 field. Better probably to have default:string (which at least in FlatBuffers can be detected as not-set vs empty) and default_vector:bool` ?

In terms of the variable constant in the parser.. I actually like your idea of making it contain the string including extra "": this would make a lot of sense as way to represent different types of values inside a string.

The long term solution would be to replace constant with a variant<int64_t,double,string,bool> or similar? But that will likely cause a LOT of code churn.

@jtdavis777 jtdavis777 removed the ready-for-merge This PR has been approved by a maintainer and is ready for merge by a code owner label Dec 22, 2025
@jtdavis777
Copy link
Collaborator Author

I will see about refactoring this to use option 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema java python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants