You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add unset field semantics for structs ("strict structs") (#607)
* Add unset field semantics (disc #536)
Signed-off-by: Simon Beyzerov <[email protected]>
* Fix up PR
Signed-off-by: Adam Glustein <[email protected]>
* Further clean up of PR; add docs, improve error messages, fix inheritance bug
Signed-off-by: Adam Glustein <[email protected]>
* Change lint to use 3.11
Signed-off-by: Adam Glustein <[email protected]>
* Fix 3.10+ Union annotations
Signed-off-by: Adam Glustein <[email protected]>
* Fix typo in docs
Signed-off-by: Adam Glustein <[email protected]>
* Store optionality on the field object, and embed whether or not the field is set to None in the struct's bitmask
Signed-off-by: Adam Glustein <[email protected]>
* More PR comments
Signed-off-by: Adam Glustein <[email protected]>
* Fix str/repr for strict structs
Signed-off-by: Adam Glustein <[email protected]>
* WIP PR comments
Signed-off-by: Adam Glustein <[email protected]>
* PR comments
Signed-off-by: Adam Glustein <[email protected]>
* Store set and none masks in the same vector, provide accessors
Signed-off-by: Adam Glustein <[email protected]>
* Tests: add collectts test case, merge wiring_access tests, add fromts test
Signed-off-by: Adam Glustein <[email protected]>
* Update pydantic schema
Signed-off-by: Adam Glustein <[email protected]>
* Add tests for pydantic validation
Signed-off-by: Adam Glustein <[email protected]>
---------
Signed-off-by: Simon Beyzerov <[email protected]>
Signed-off-by: Adam Glustein <[email protected]>
Co-authored-by: Simon Beyzerov <[email protected]>
1. Let M1 be the bitmask with 1s that align with the set bit of optional fields and
528
+
2. Let M2 be the bitmask with 1s that align with the none bit of optional fields.
529
+
-- Both M1 and M2 are computed trivially when we create the meta.
530
+
3. Let M1* = M1 & mask. M1* now is the bitmask of all set optional fields.
531
+
4. Similarly, let M2* = M2 & mask, such that M2* is the bitmask of all none optional fields.
532
+
5. Let M3 = mask | (M1* << 1) | (M2* >> 1). Since the shifted set/none bitsets will fill in that optional fields other bit,
533
+
the struct can validate iff M3 is all 1s.
534
+
535
+
Notes:
536
+
1) We do this on a byte by byte basis currently. If we add 32/64 bit padding to the struct mask, we could do this as one single step for most structs.
537
+
2) There is an edge condition if a) the set bit of an optional field is the last bit of a byte or b) the none bit of an optional field is the first bit of a byte.
538
+
So, when we create the meta, we ensure this never happens by being smart about the ordering of fields in the mask.
539
+
*/
460
540
461
541
constuint8_t * m = reinterpret_cast<constuint8_t *>( s ) + m_maskLoc;
462
-
constuint8_t * e = m + m_maskSize - bool( numRemainingBits );
463
-
for( ; m < e; ++m )
542
+
constuint8_t * e = m + m_maskSize - bool( m_lastByteMask );
0 commit comments