google / google/emboss

Provide a way to read the offset and size of a field.

Open
#99 0 comments 1 reaction 0 assignees View on GitHub
enhancement language feature
Dominant language
Python
Stars
92
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Given a structure like:

```
struct Foo:
0 [+4] UInt a
some_complex_offset [+some_complex_size] Structure b
```

it would be useful to be able to get the values of `some_complex_offset` and `some_complex_size`, both in Emboss definitions and in C++.

The tricky part of this is that the offset and size of a field are properties of the structure that contains the field, not properties of the field itself, so a function like `$offset_of(b)` would need some new machinery to ensure that the argument was a physical field and that it was called in a context where it makes sense.

One thought I had was to make implicit virtual fields `$offset_of_b` and `$size_of_b`, similar to the existing implicit virtual field `$size_in_bytes`. (These might be spelled `$offset_of b` or `$offset_of(b)` in an `.emb`. The C++ names would need to be regular C++ identifiers, or there would need to be contortions in the C++ code generator to make something like `view.OffsetOf().b()` work.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.