Skip to content

Conversation

thejtshow
Copy link
Contributor

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
@thejtshow
Copy link
Contributor 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?

@thejtshow
Copy link
Contributor 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.

@thejtshow
Copy link
Contributor 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)

@thejtshow thejtshow force-pushed the feature/non_scalar_default_bfbs_support branch from 148d925 to d92b677 Compare August 21, 2025 01:08
@thejtshow
Copy link
Contributor 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

@thejtshow thejtshow changed the title Add non scalar support to BFBS files Add non scalar default support to BFBS files Aug 27, 2025
@thejtshow thejtshow force-pushed the feature/non_scalar_default_bfbs_support branch from ca5d722 to 22fa6e2 Compare August 29, 2025 12:49
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.

2 participants