-
struct Symbol
{
const char *symbol;
int32_t symbol_id = -1;
uint8_t RESERVED_00[3];
char char_ref[8];
uint64_t tick_size :16;
uint64_t RESERVED_02:48;
uint32_t v1 :1;
uint32_t v2 :1;
uint32_t RESERVED_03:30;
};for this struct, how to use it in codon. Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
arshajii
Jul 30, 2025
Replies: 1 comment
-
|
The bitfields make this somewhat tricky but here is a Codon representation that should be compatible with that C struct: @tuple
class Symbol:
symbol: cobj
symbold_id: i32
RESERVED_00_0: u8
RESERVED_00_1: u8
RESERVED_00_2: u8
char_ref0: u8
char_ref1: u8
char_ref2: u8
char_ref3: u8
char_ref4: u8
char_ref5: u8
char_ref6: u8
char_ref7: u8
_padding: u8
_bitfields1: UInt[96]
_bitfields2: u32
@property
def tick_size(self):
return int(self._bitfields1) & 0xffff
@property
def v1(self):
return bool(self._bitfields1 & (UInt[96](1) << UInt[64]))
@property
def v2(self):
return bool(self._bitfields1 & (UInt[96](1) << UInt[65]))Note that the arrays are broken up into their components and the bitfields are represented as single members with getters. The You can see the layout of the structure in C and how the fields are accessed here: https://godbolt.org/z/EzGqn5an8 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
qinwf
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The bitfields make this somewhat tricky but here is a Codon representation that should be compatible with that C struct: