Skip to content

Conversation

@saibatizoku
Copy link
Contributor

@saibatizoku saibatizoku commented Jan 12, 2025

Description

Add conversion from UUID types into CBOR values.

Please confirm the following checks

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream module

@saibatizoku saibatizoku added the enhancement New feature or request label Jan 12, 2025
@saibatizoku saibatizoku self-assigned this Jan 12, 2025
@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 294/294}$ | ${\color{red}Fail: 0/294}$ |

Copy link
Collaborator

@stevenj stevenj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not loving the existing and new coset types in the UUID types.
The reason being is that coset uses the ciborium library under the hood. This means we end up with two different ways of encoding the exactly same binary stream. Its a maintenance issue.

We settled a while ago on using minicbor for our go-to cbor encode/decode library.
I don't think we should be bringing in cborium or any other cbor encoder into our common libraries.

Its also unnecessary. minicbor can serialize/deserialize from bytes (Vec).
If we are forced to use ciborium then it should be 100% constrained to the crate that brings that requirement in (another topic).
We should be able to use the minicbor encode/decode functions for these types when converting too-from cbor, and just convert the upper type. All this requires is the ability to convert between a (in this case) coset value and vec which it should be under the hood anyway.

I want us to remove coset from the dependencies of this crate, use minicbor only for encoding/decoding to-from vec and the uuid types, so that there is a single source of truth for cbor encoding for these types. If the library we are using does not support minicbor then we should either:

  1. Use a library that does.
  2. (if 1 above can not work) Wrap the minicbor encode/decode in the crate which needs the non minicbor encoder and not in the types themselves.

@saibatizoku saibatizoku force-pushed the fix/serialize-uuid-types branch from 829e1f6 to 60933ea Compare January 14, 2025 21:29
@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 256/256}$ | ${\color{red}Fail: 0/256}$ |

@saibatizoku saibatizoku changed the title fix(rust/catalyst-types): Convert UUID types to cbor::Value fix(rust/catalyst-types): Convert UUID types to cbor Jan 15, 2025
@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 256/256}$ | ${\color{red}Fail: 0/256}$ |

}

/// Encode `UUID` into `CBOR`
pub(crate) fn encode_cbor_uuid<W: minicbor::encode::Write>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For generality, encoding with a Tag should be optional.
Suggest adding a context tag: bool.

  • true = encode with a tag
  • false = encode without a tag.

/// Decode from `CBOR` into `UUID`
pub(crate) fn decode_cbor_uuid(
d: &mut Decoder<'_>, (): &mut (),
) -> Result<uuid::Uuid, minicbor::decode::Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For generality, there are three possible options one would want on a decode:

  1. MUST have a TAG
  2. MUST not have a TAG
  3. Optionally has a TAG.

Suggest adding a tagged: Option<bool> as the context.

  • None = Optionally has a Tag
  • Some(true) = Must have a Tag
  • Some(false) = Must NOT have a Tag

@saibatizoku saibatizoku force-pushed the fix/serialize-uuid-types branch from 83fd117 to f47590e Compare January 15, 2025 19:55
@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 256/256}$ | ${\color{red}Fail: 0/256}$ |

@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 260/260}$ | ${\color{red}Fail: 0/260}$ |

@saibatizoku saibatizoku force-pushed the fix/serialize-uuid-types branch 2 times, most recently from 0dd8c98 to 5a376af Compare January 16, 2025 05:40
@saibatizoku saibatizoku force-pushed the fix/serialize-uuid-types branch from 5a376af to c6b0446 Compare January 16, 2025 05:46
@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 260/260}$ | ${\color{red}Fail: 0/260}$ |

@saibatizoku saibatizoku force-pushed the fix/serialize-uuid-types branch from d7ca046 to 1a430ec Compare January 16, 2025 05:58
@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 260/260}$ | ${\color{red}Fail: 0/260}$ |

@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 256/256}$ | ${\color{red}Fail: 0/256}$ |

@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 260/260}$ | ${\color{red}Fail: 0/260}$ |

@saibatizoku saibatizoku added the review me PR is ready for review label Jan 16, 2025
@saibatizoku saibatizoku marked this pull request as ready for review January 16, 2025 20:40
@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 262/262}$ | ${\color{red}Fail: 0/262}$ |

Mr-Leshiy
Mr-Leshiy previously approved these changes Jan 16, 2025
Copy link
Contributor

@Mr-Leshiy Mr-Leshiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite one comment LGTM

@github-actions
Copy link
Contributor

Test Report | ${\color{lightgreen}Pass: 262/262}$ | ${\color{red}Fail: 0/262}$ |

Copy link
Collaborator

@stevenj stevenj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stevenj stevenj self-requested a review January 17, 2025 04:58
Copy link
Collaborator

@stevenj stevenj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stevenj stevenj merged commit 0d155bf into main Jan 17, 2025
22 checks passed
@stevenj stevenj deleted the fix/serialize-uuid-types branch January 17, 2025 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request review me PR is ready for review

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants