Skip to content

Conversation

@ERoydev
Copy link
Collaborator

@ERoydev ERoydev commented Sep 4, 2025

What

Optional field handler implemted in templates

reader.readU8() == 1 ? reader.readString() : null;
writer.writeU8(optional_str != null ? 1 : 0);
  • if optional_str (or other fields) is null it writes 1 meaning value is present, then writes the string, else it writes 0
  • For read try to read the first byte if its 1 it reads and return the value otherwise returns null

Borsh logic for Enums

Variant represents an Optioan in the Enum and this Option can have a Tuple, Struct or be Empty as a value, i treat everything inside like a structFieldType and i extract those fields in a collection.

Loop through variants of the Enum and for each variant:

  • I count the fields that this variants has `(StringType, NumberType, ... ) and i take the all the fields that this variants has.
  • I use to generate serialization/deserialization methods for every field + checking if Optional using the recursiveBorsh macros.

Added couple of methods in the Shared nunjucks template

  • fixed offset of bytes for some of the methods
  • I found that in dart i cannot have u8 or u64 types for numbers so we just use int and bigint

Implemented fragment for Dart Typed Arrays conversion

  • Maps Rust number formats (u8, i16, etc.) to Dart typed arrays (Uint8List, Int16List, …).
  • Handles string arrays → List.
  • Handles struct arrays → List.
  • Handles number arrays with proper dart:typed_data imports. to have like (Uint32List, Int16List, ...)
  • Provides a fallback to generic Dart lists when no mapping is found.

@ERoydev ERoydev requested a review from failfmi September 4, 2025 09:18
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.

3 participants