[bpf2go] Generate union fields as fixed bytes array #1586
chenBenjamin97
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When
bpf2go
generates a union field into a Go field, it seeme like it takes the first field from the C union, then adds anonymous field with the rest of the union's size.Example given:
The following C union:
is converted into the following Go field:
This Go implementation might be problematic for union fields that are being used as a container for various possible structs.
For example, a generic struct that is being sent to the user-space through a ring buffer. Such a struct would probably hold an ID, indicating the user-space the context of the message, then the user-space code would parse the union field into the relevant Go struct (again, based on the context).
Current implementation requires two runtime operations in order to achieve this goal: first, convert the whole
RawEvent
field into a bytes array, then parse this array to the relevant Go struct.If we'll just set the
RawEvent
Go field a fixed bytes array, we can avoid the first operation in runtime.I guess we can add the suggested behavior as a flag to the
bpf2go
tool in order to maintain its backward compatibility.What do you think about that?
If agreed, I'll be glad to implement it.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions