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

Support 'hex-string' de-serialization method on getBytes operators #2391

Open
guidiaz opened this issue Sep 4, 2023 · 4 comments · May be fixed by #2413
Open

Support 'hex-string' de-serialization method on getBytes operators #2391

guidiaz opened this issue Sep 4, 2023 · 4 comments · May be fixed by #2413
Labels
enhancement 📈 New feature or request

Comments

@guidiaz
Copy link
Contributor

guidiaz commented Sep 4, 2023

  • 'hex-string' method is mostly used in Web3/EVM contexts.
  • Optional second parameter would need to be added:
    • RadonMap.getBytes(key: string, method?: string)
    • RadonArray.getBytes(index: number, method?: string)
    • RadonString.asBytes(method?: string)
@guidiaz guidiaz added the enhancement 📈 New feature or request label Sep 4, 2023
@aesedepece
Copy link
Member

aesedepece commented Sep 4, 2023

I'd absolutely love to have this.

I've always envisioned it as:

  • RadonString.asBytes(encoding: RadonBytesEncoding) -> Result<RadonBytes>
  • RadonMap.getBytes(key: string, encoding: RadonBytesEncoding) -> Result<RadonBytes>
  • RadonArray.getBytes(index: number, encoding: RadonBytesEncoding) -> Result<RadonBytes>
#[derive(Deserialize, Debug, Default, Serialize)]
enum RadonBytesEncoding {
    #[default]
    Hex = 0,
    Base64 = 1,
}

@guidiaz
Copy link
Contributor Author

guidiaz commented Sep 7, 2023

As a natural approach to web3 interactions, these other operators would also be great to have:

  • RadonBytes.asInteger() (big-endian assumed)
  • RadonString.asInteger(encoding?: RadonBytesEncoding) -> Result<RadonInteger>
#[derive(Deserialize, Debug, Default, Serialize)]
enum RadonBytesEncoding {
    #[default]
    Hex = 0,
    Base64 = 1,
    Decimal = 2,
}

@aesedepece
Copy link
Member

As a natural approach to web3 interactions, these other operators would also be great to have:

* `RadonBytes.asInteger()` (big-endian assumed)

* `RadonString.asInteger(encoding?: RadonBytesEncoding) -> Result<RadonInteger>`

Sure, that's a great addition!

I agree on the point of assuming Big-Endian. Otherwise we'd need to have separate entries in RadonBytesEncoding for the BE and LE versions of each encoding.

We'd better simply have a RadonBytes.flip operator that does the BE<>LE conversion.

@guidiaz
Copy link
Contributor Author

guidiaz commented Dec 13, 2023

ArrayGetBytes and MapGetBytes would be unneccesary for two reasons:

  • We cannot expect for a RadonMap item to contain binary values after a parseJSONMap() or parseJSONArray() is processed.
  • In practice, they'd get solved by the succession of ArrayGetString/MapGetString and StringAsBytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 📈 New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants