Skip to content
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

Flatc annotation provides struct name and not field name #7714

Closed
bWFpbA opened this issue Dec 14, 2022 · 2 comments
Closed

Flatc annotation provides struct name and not field name #7714

bWFpbA opened this issue Dec 14, 2022 · 2 comments
Assignees

Comments

@bWFpbA
Copy link

bWFpbA commented Dec 14, 2022

When using the flatc --annotate option on a FlatBuffer schema and binary that contain a struct that is used for multiple fields, those fields will be annotated with the struct name and not the field name. This makes it difficult to understand which field the data is for.

For example, say I have the following struct:

struct ParamSet {
	hp:ubyte; // 0
	atk:ubyte; // 1
	def:ubyte; // 2
	spatk:ubyte; // 3
	spdef:ubyte; // 4
	agi:ubyte; // 5
}

And usage like so:

table Personal {
	pains:ParamSet; // 19
	basic:ParamSet; // 20
}

It will be annotated like so:

  +0x80 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.hp` (UByte)
  +0x81 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.atk` (UByte)
  +0x82 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.def` (UByte)
  +0x83 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.spatk` (UByte)
  +0x84 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.spdef` (UByte)
  +0x85 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.agi` (UByte)
  +0x86 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.hp` (UByte)
  +0x87 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.atk` (UByte)
  +0x88 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.def` (UByte)
  +0x89 | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.spatk` (UByte)
  +0x8A | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.spdef` (UByte)
  +0x8B | 00                      | uint8_t    | 0x00 (0)                   | struct field `ParamSet.agi` (UByte)

Looking at the annotated vtable suggests that the first six fields are for pains, and the last six fields are for basic. However, this is not obvious in the annotated table.

Instead, I would have expected it to be annotated like so:

  +0x80 | 00                      | uint8_t    | 0x00 (0)                   | struct field `pains.hp` (UByte)
  +0x81 | 00                      | uint8_t    | 0x00 (0)                   | struct field `pains.atk` (UByte)
  +0x82 | 00                      | uint8_t    | 0x00 (0)                   | struct field `pains.def` (UByte)
  +0x83 | 00                      | uint8_t    | 0x00 (0)                   | struct field `pains.spatk` (UByte)
  +0x84 | 00                      | uint8_t    | 0x00 (0)                   | struct field `pains.spdef` (UByte)
  +0x85 | 00                      | uint8_t    | 0x00 (0)                   | struct field `pains.agi` (UByte)
  +0x86 | 00                      | uint8_t    | 0x00 (0)                   | struct field `basic.hp` (UByte)
  +0x87 | 00                      | uint8_t    | 0x00 (0)                   | struct field `basic.atk` (UByte)
  +0x88 | 00                      | uint8_t    | 0x00 (0)                   | struct field `basic.def` (UByte)
  +0x89 | 00                      | uint8_t    | 0x00 (0)                   | struct field `basic.spatk` (UByte)
  +0x8A | 00                      | uint8_t    | 0x00 (0)                   | struct field `basic.spdef` (UByte)
  +0x8B | 00                      | uint8_t    | 0x00 (0)                   | struct field `basic.agi` (UByte)

You can find the FlatBuffer schema and binary I am using here.

@dbaileychess dbaileychess self-assigned this Dec 14, 2022
@dbaileychess
Copy link
Collaborator

Thanks for the report. This seems straightforward to fix.

@dbaileychess
Copy link
Collaborator

@bWFpbA Can you look at the attached PR (#7735) to see if that is what you expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants