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

Fix Vec<Uuid> error when using CST codec (the SSE codec does not have this bug) #1762

Merged
merged 17 commits into from
Feb 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,7 @@ impl<'a> WireDartCodecDcoGeneratorDecoderTrait for DelegateWireDartCodecDcoGener
IrTypeDelegate::Uuid => {
"return UuidValue.fromByteList(dco_decode_list_prim_u_8_strict(raw));".to_owned()
}
// IrTypeDelegate::Uuids =>
// "const kUuidSizeInBytes = 16;
// final bytes = dco_decode_list_prim_u_8(raw);
// return List.generate(
// bytes.lengthInBytes ~/ kUuidSizeInBytes,
// (i) => UuidValue.fromByteList(Uint8List.view(bytes.buffer, i * kUuidSizeInBytes, kUuidSizeInBytes)),
// growable: false,
// );
// ".to_owned(),
// IrTypeDelegate::Uuids => ...,
IrTypeDelegate::AnyhowException => "return AnyhowException(raw as String);".to_owned(),
IrTypeDelegate::Map(_) => format!(
"return Map.fromEntries(dco_decode_{}(raw).map((e) => MapEntry(e.$1, e.$2)));",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
use crate::codegen::generator::wire::dart::spec_generator::codec::dco::base::*;
use crate::codegen::generator::wire::dart::spec_generator::codec::dco::decoder::ty::WireDartCodecDcoGeneratorDecoderTrait;
use crate::codegen::ir::ty::delegate::IrTypeDelegate;
use crate::codegen::ir::ty::IrType;
use crate::library::codegen::ir::ty::IrTypeTrait;

impl<'a> WireDartCodecDcoGeneratorDecoderTrait for GeneralListWireDartCodecDcoGenerator<'a> {
fn generate_impl_decode_body(&self) -> String {
if let IrType::Delegate(IrTypeDelegate::Uuid) = &*self.ir.inner {
return "const kUuidSizeInBytes = 16;
final bytes = dco_decode_list_prim_u_8_strict(raw);
return List.generate(
bytes.lengthInBytes ~/ kUuidSizeInBytes,
(i) => UuidValue.fromByteList(Uint8List.view(bytes.buffer, i * kUuidSizeInBytes, kUuidSizeInBytes)),
growable: false,
);".to_owned();
}

format!(
"return (raw as List<dynamic>).map(dco_decode_{}).toList();",
self.ir.inner.safe_ident()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ impl<'a> WireRustCodecCstGeneratorDecoderTrait for GeneralListWireRustCodecCstGe
fn general_list_maybe_extra_pointer_indirection(ir: &IrTypeGeneralList) -> &'static str {
if matches!(
*ir.inner,
Optional(_) | Delegate(IrTypeDelegate::String) | IrType::PrimitiveList(_)
Optional(_)
| Delegate(IrTypeDelegate::String)
| Delegate(IrTypeDelegate::Uuid)
| IrType::PrimitiveList(_)
) {
"*mut "
} else {
Expand Down
36 changes: 36 additions & 0 deletions frb_example/pure_dart/frb_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,11 @@ typedef struct wire_cst_feature_uuid_twin_rust_async {
struct wire_cst_list_prim_u_8_strict *one;
} wire_cst_feature_uuid_twin_rust_async;

typedef struct wire_cst_list_Uuid {
struct wire_cst_list_prim_u_8_strict **ptr;
int32_t len;
} wire_cst_list_Uuid;

typedef struct wire_cst_feature_uuid_twin_sync {
struct wire_cst_list_prim_u_8_strict *one;
} wire_cst_feature_uuid_twin_sync;
Expand Down Expand Up @@ -11598,6 +11603,9 @@ void frbgen_frb_example_pure_dart_wire_handle_nested_uuids_twin_rust_async(int64
void frbgen_frb_example_pure_dart_wire_handle_uuid_twin_rust_async(int64_t port_,
struct wire_cst_list_prim_u_8_strict *id);

void frbgen_frb_example_pure_dart_wire_handle_uuids_twin_rust_async(int64_t port_,
struct wire_cst_list_Uuid *ids);

void frbgen_frb_example_pure_dart_wire_handle_nested_uuids_twin_rust_async_sse(int64_t port_,
uint8_t *ptr_,
int32_t rust_vec_len_,
Expand All @@ -11608,6 +11616,11 @@ void frbgen_frb_example_pure_dart_wire_handle_uuid_twin_rust_async_sse(int64_t p
int32_t rust_vec_len_,
int32_t data_len_);

void frbgen_frb_example_pure_dart_wire_handle_uuids_twin_rust_async_sse(int64_t port_,
uint8_t *ptr_,
int32_t rust_vec_len_,
int32_t data_len_);

void frbgen_frb_example_pure_dart_wire_handle_nested_uuids_twin_sse(int64_t port_,
uint8_t *ptr_,
int32_t rust_vec_len_,
Expand All @@ -11618,10 +11631,17 @@ void frbgen_frb_example_pure_dart_wire_handle_uuid_twin_sse(int64_t port_,
int32_t rust_vec_len_,
int32_t data_len_);

void frbgen_frb_example_pure_dart_wire_handle_uuids_twin_sse(int64_t port_,
uint8_t *ptr_,
int32_t rust_vec_len_,
int32_t data_len_);

WireSyncRust2DartDco frbgen_frb_example_pure_dart_wire_handle_nested_uuids_twin_sync(struct wire_cst_feature_uuid_twin_sync *ids);

WireSyncRust2DartDco frbgen_frb_example_pure_dart_wire_handle_uuid_twin_sync(struct wire_cst_list_prim_u_8_strict *id);

WireSyncRust2DartDco frbgen_frb_example_pure_dart_wire_handle_uuids_twin_sync(struct wire_cst_list_Uuid *ids);

WireSyncRust2DartSse frbgen_frb_example_pure_dart_wire_handle_nested_uuids_twin_sync_sse(uint8_t *ptr_,
int32_t rust_vec_len_,
int32_t data_len_);
Expand All @@ -11630,6 +11650,10 @@ WireSyncRust2DartSse frbgen_frb_example_pure_dart_wire_handle_uuid_twin_sync_sse
int32_t rust_vec_len_,
int32_t data_len_);

WireSyncRust2DartSse frbgen_frb_example_pure_dart_wire_handle_uuids_twin_sync_sse(uint8_t *ptr_,
int32_t rust_vec_len_,
int32_t data_len_);

void frbgen_frb_example_pure_dart_wire_test_more_than_just_one_raw_string_struct_twin_normal(int64_t port_);

void frbgen_frb_example_pure_dart_wire_test_raw_string_item_struct_twin_normal(int64_t port_);
Expand Down Expand Up @@ -11876,6 +11900,9 @@ void frbgen_frb_example_pure_dart_wire_handle_nested_uuids_twin_normal(int64_t p
void frbgen_frb_example_pure_dart_wire_handle_uuid_twin_normal(int64_t port_,
struct wire_cst_list_prim_u_8_strict *id);

void frbgen_frb_example_pure_dart_wire_handle_uuids_twin_normal(int64_t port_,
struct wire_cst_list_Uuid *ids);

void frbgen_frb_example_pure_dart_rust_arc_increment_strong_count_RustOpaque_BoxdynDartDebugTwinMoi(const void *ptr);

void frbgen_frb_example_pure_dart_rust_arc_decrement_strong_count_RustOpaque_BoxdynDartDebugTwinMoi(const void *ptr);
Expand Down Expand Up @@ -13068,6 +13095,8 @@ struct wire_cst_list_RustOpaque_HideDataTwinSyncMoi *frbgen_frb_example_pure_dar

struct wire_cst_list_String *frbgen_frb_example_pure_dart_cst_new_list_String(int32_t len);

struct wire_cst_list_Uuid *frbgen_frb_example_pure_dart_cst_new_list_Uuid(int32_t len);

struct wire_cst_list_application_env_var *frbgen_frb_example_pure_dart_cst_new_list_application_env_var(int32_t len);

struct wire_cst_list_application_settings *frbgen_frb_example_pure_dart_cst_new_list_application_settings(int32_t len);
Expand Down Expand Up @@ -13558,6 +13587,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_list_RustOpaque_HideDataTwinSync);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_list_RustOpaque_HideDataTwinSyncMoi);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_list_String);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_list_Uuid);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_list_application_env_var);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_list_application_settings);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_cst_new_list_attribute_twin_normal);
Expand Down Expand Up @@ -15423,6 +15453,12 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuid_twin_sse);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuid_twin_sync);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuid_twin_sync_sse);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuids_twin_normal);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuids_twin_rust_async);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuids_twin_rust_async_sse);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuids_twin_sse);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuids_twin_sync);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_uuids_twin_sync_sse);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_vec_of_opts_twin_normal);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_vec_of_opts_twin_rust_async);
dummy_var ^= ((int64_t) (void*) frbgen_frb_example_pure_dart_wire_handle_vec_of_opts_twin_rust_async_sse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Future<UuidValue> handleUuidTwinRustAsync(
{required UuidValue id, dynamic hint}) =>
RustLib.instance.api.handleUuidTwinRustAsync(id: id, hint: hint);

Future<List<UuidValue>> handleUuidsTwinRustAsync(
{required List<UuidValue> ids, dynamic hint}) =>
RustLib.instance.api.handleUuidsTwinRustAsync(ids: ids, hint: hint);

Future<FeatureUuidTwinRustAsync> handleNestedUuidsTwinRustAsync(
{required FeatureUuidTwinRustAsync ids, dynamic hint}) =>
RustLib.instance.api.handleNestedUuidsTwinRustAsync(ids: ids, hint: hint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Future<UuidValue> handleUuidTwinRustAsyncSse(
{required UuidValue id, dynamic hint}) =>
RustLib.instance.api.handleUuidTwinRustAsyncSse(id: id, hint: hint);

Future<List<UuidValue>> handleUuidsTwinRustAsyncSse(
{required List<UuidValue> ids, dynamic hint}) =>
RustLib.instance.api.handleUuidsTwinRustAsyncSse(ids: ids, hint: hint);

Future<FeatureUuidTwinRustAsyncSse> handleNestedUuidsTwinRustAsyncSse(
{required FeatureUuidTwinRustAsyncSse ids, dynamic hint}) =>
RustLib.instance.api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import 'package:uuid/uuid.dart';
Future<UuidValue> handleUuidTwinSse({required UuidValue id, dynamic hint}) =>
RustLib.instance.api.handleUuidTwinSse(id: id, hint: hint);

Future<List<UuidValue>> handleUuidsTwinSse(
{required List<UuidValue> ids, dynamic hint}) =>
RustLib.instance.api.handleUuidsTwinSse(ids: ids, hint: hint);

Future<FeatureUuidTwinSse> handleNestedUuidsTwinSse(
{required FeatureUuidTwinSse ids, dynamic hint}) =>
RustLib.instance.api.handleNestedUuidsTwinSse(ids: ids, hint: hint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import 'package:uuid/uuid.dart';
UuidValue handleUuidTwinSync({required UuidValue id, dynamic hint}) =>
RustLib.instance.api.handleUuidTwinSync(id: id, hint: hint);

List<UuidValue> handleUuidsTwinSync(
{required List<UuidValue> ids, dynamic hint}) =>
RustLib.instance.api.handleUuidsTwinSync(ids: ids, hint: hint);

FeatureUuidTwinSync handleNestedUuidsTwinSync(
{required FeatureUuidTwinSync ids, dynamic hint}) =>
RustLib.instance.api.handleNestedUuidsTwinSync(ids: ids, hint: hint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import 'package:uuid/uuid.dart';
UuidValue handleUuidTwinSyncSse({required UuidValue id, dynamic hint}) =>
RustLib.instance.api.handleUuidTwinSyncSse(id: id, hint: hint);

List<UuidValue> handleUuidsTwinSyncSse(
{required List<UuidValue> ids, dynamic hint}) =>
RustLib.instance.api.handleUuidsTwinSyncSse(ids: ids, hint: hint);

FeatureUuidTwinSyncSse handleNestedUuidsTwinSyncSse(
{required FeatureUuidTwinSyncSse ids, dynamic hint}) =>
RustLib.instance.api.handleNestedUuidsTwinSyncSse(ids: ids, hint: hint);
Expand Down
4 changes: 4 additions & 0 deletions frb_example/pure_dart/lib/src/rust/api/uuid_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import 'package:uuid/uuid.dart';
Future<UuidValue> handleUuidTwinNormal({required UuidValue id, dynamic hint}) =>
RustLib.instance.api.handleUuidTwinNormal(id: id, hint: hint);

Future<List<UuidValue>> handleUuidsTwinNormal(
{required List<UuidValue> ids, dynamic hint}) =>
RustLib.instance.api.handleUuidsTwinNormal(ids: ids, hint: hint);

Future<FeatureUuidTwinNormal> handleNestedUuidsTwinNormal(
{required FeatureUuidTwinNormal ids, dynamic hint}) =>
RustLib.instance.api.handleNestedUuidsTwinNormal(ids: ids, hint: hint);
Expand Down
Loading
Loading