Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow direct struct field matching from binary token #127

Merged
merged 1 commit into from
Nov 22, 2023
Merged

Conversation

nickbabcock
Copy link
Contributor

@nickbabcock nickbabcock commented Nov 11, 2023

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:

#[derive(JominiDeserialize, PartialEq, Debug)]
struct MyStruct {
    #[jomini(token = 0x2d82)]
    field1: String,
}

Large caveats:

  • All or no fields in a given struct should have the token attribute

classify each struct 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.

@nickbabcock nickbabcock marked this pull request as ready for review November 17, 2023 21:15
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.
@nickbabcock nickbabcock merged commit 5f22afa into master Nov 22, 2023
7 checks passed
@nickbabcock nickbabcock deleted the direct branch November 22, 2023 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant