-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow direct struct field matching from binary token
The binary token resolution leaves some efficiency on the table as it first translates the token to a string and then matches the string against struct fields. The PR asks the question, what if we reduce the operation to just matching on the 16bit value? Remove the translation step and simplify matching. This is what I envision and technically now works in this PR: ```rust struct MyStruct { #[jomini(token = 0x2d82)] field1: String, } ``` Large caveats: - Direct matching is only done when the string resolution fails - And must use `FailedResolveStrategy::Visit` The first caveat is the largest problem as we don't want to remove tokens from the token list because token resolution needs to work on values (they aren't always keys). I think the best course of action will be to classify each struct as if fields can be directly resolved or if it needs translation based on the presence of the `#[jomini(token)]` attribute. For direct structs, swap the request to `deserialize_identifier` to `deserialize_u16` to give a hint that tokens should not be resolved. Some unanswered questions: - Do the efficiency gains justify the complication? - I know PDS doesn't want the token list revealed, I wonder if this is obfuscated enough to be ok.
- Loading branch information
1 parent
249046a
commit 21a6f73
Showing
7 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[allow(dead_code)] | ||
use jomini_derive::JominiDeserialize; | ||
|
||
#[derive(JominiDeserialize)] | ||
pub struct Model { | ||
#[jomini(token = 0x10)] | ||
human: bool, | ||
#[jomini(token = 0x11)] | ||
checksum: String, | ||
fourth: u16, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: proc-macro derive panicked | ||
--> tests/compile-fail/tokens.rs:4:10 | ||
| | ||
4 | #[derive(JominiDeserialize)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: message: Model does not have #[jomini(token = x)] defined for all fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters