-
Notifications
You must be signed in to change notification settings - Fork 17
Issue 80 #81
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
Conversation
| } | ||
|
|
||
| class _CborBytesImpl with CborValueMixin implements CborBytes { | ||
| class CborBytesImpl with CborValueMixin implements CborBytes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_CborBytesImpl can stay private as long as we add to this file part "typed_data.dart" and part of "bytes.dart for typed_data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't get this to work,, maybe try again when the code has settles some more.
lib/src/value/typed_data.dart
Outdated
| import 'package:ieee754/ieee754.dart'; | ||
|
|
||
| /// Base class for all Typed Arrays | ||
| abstract class CborTypedArray extends CborBytesImpl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider:
- Potentially making this private.
- Making this
sealed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made sealed, again couldn't get visibility to work as private.
|
Review from Claude Code |
| /// sint64 big endian | ||
| class CborInt64BigEndianArray extends CborTypedArray { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ByteData's getUint64() and getInt64() (and the setters) do not work on web. They throw a runtime exception. It works well on wasm.
I actually had to deal with this issue just a few weeks ago for a package that I maintain. See diff here:
--
Since JS has no distinction between int and float, you can use setFloat64 and getFloat64 instead. However, anything above JS's Number.MAX_SAFE_INTEGER may be corrupted (changed). In other words, it's not a bulletproof solution.
So, the way I see, there's two options:
- Simple fix: Check for web js and use
Float64while accepting it breaks for (some) large numbers - Complex fix: use
BigIntwhich would probably cause a bigger change
Note: Web WASM supports int64 and uint64 types. However, I am not sure if ByteData's get/setUint64 and get/setInt64 throws on web js only, or also on web wasm. It would need checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be to do (for now) the simple fix and maybe leave an issue open and a comment to the issue as a known limitation.
If ByteData's int64's operations do not work on WASM, the same can be achieved with two reads/writes of int32 operations and some binary shift, which should be perfectly safe to use for both VM and WEB WASM, while WEB JS can use the float64 operation(s).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L.e. Those are the files (config + git workflow) to run tests for VM + WEB JS + WEB WASM in CI if you're interested.
https://github.com/vespr-wallet/cardano_dart_types/blob/main/dart_test.yaml
https://github.com/vespr-wallet/cardano_dart_types/blob/main/.github/workflows/mobile-tests.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks for the comprehensive review, especially the web/wasm stuff. I've come across this before where things work OK in web(JS) but not wasm and vice versa in some of my other packages. I think the Google guys still have some work to do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look at this seperately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ramifications of updating the package to web/wasm targets is a bit more than just for this RFC, other tests concerning large numbers, infinity etc. also fail when tested in a web environment which is to be expected of course.
I've raised #82 to address web/wasm usage as a seperate task.
AlexDochioiu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty solid job. Main issue I see is about web (especially js) support
Key changes: 1. Validation: Added checks in toObjectInternal to throw CborMalformedException if the byte length is not a multiple of the element size. 2. Endianness: Fixed Float16 Little Endian handling by reversing bytes before decoding. 3. Float128: Updated toObjectInternal to throw UnimplementedError instead of returning raw bytes. 4. Int8: Removed confusing comments. 5. Factories: Added fromList factory constructors to Typed Array classes to facilitate encoding (e.g., CborUint16BigEndianArray.fromList([1, 2])). 6. Tests: Expanded test/rfc8746_test.dart to cover missing types (Uint64, Int32, Float128), edge cases (misaligned length), and the new factories.
|
Gemini updates so far on the review. My comments added in line. I asked it not to look at the web/wasm stuff I'll look at this. |
|
I looked over the new commits. Looks good to me! |
|
Great, thanks |
… of RFC8746.
Summary of changes:
1. Added Tag 40: Added CborTag.multiDimensionalArray to lib/src/value/value.dart.
2. Created `CborMultiDimensionalArray`: Implemented the CborMultiDimensionalArray class in lib/src/value/multi_dimensional_array.dart, including encode, toObject,
and toJson methods.
3. Added Factory Constructors: Added fromTypedArray and fromValues factory constructors to CborMultiDimensionalArray for easier instantiation.
4. Updated Decoder: Updated lib/src/decoder/stage3.dart to correctly decode arrays with Tag 40 into CborMultiDimensionalArray objects.
5. Fixed `isHintSubtype`: Updated lib/src/utils/utils.dart to include multiDimensionalArray (and missing rationalNumber, decimalFraction) in isHintSubtype, enabling
proper tag detection.
6. Added Tests: Added comprehensive unit tests for encoding and decoding multi-dimensional arrays in test/rfc8746_test.dart.
Verified all tests passed with dart test.
No description provided.