1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::generator::dart::ty::*;
use crate::ir::*;
use crate::target::Acc;
use crate::type_dart_generator_struct;
type_dart_generator_struct!(TypeSyncReturnGenerator, IrTypeSyncReturn);
impl TypeDartGeneratorTrait for TypeSyncReturnGenerator<'_> {
fn api2wire_body(&self) -> Acc<Option<String>> {
unimplemented!("SyncReturn generator for Dart: api2wire_body is not supported")
}
fn wire2api_body(&self) -> String {
match self.ir {
IrTypeSyncReturn::Primitive(ref primitive) => match primitive {
IrTypePrimitive::Bool => "return uint8ListToBool(raw);".into(),
primitive => {
let primitive_name = match primitive {
IrTypePrimitive::U8 => "Uint8",
IrTypePrimitive::U16 => "Uint16",
IrTypePrimitive::U32 => "Uint32",
IrTypePrimitive::U64 => "Uint64",
IrTypePrimitive::I8 => "Int8",
IrTypePrimitive::I16 => "Int16",
IrTypePrimitive::I32 => "Int32",
IrTypePrimitive::I64 => "Int64",
IrTypePrimitive::F32 => "Float32",
IrTypePrimitive::F64 => "Float64",
_ => panic!(
"SyncReturn generator for Dart: type {} is not supported",
primitive.rust_api_type()
),
};
format!(
r#"
final dataView = ByteData.view(raw.buffer);
return dataView.get{primitive_name}(0);
"#,
primitive_name = primitive_name
)
}
},
IrTypeSyncReturn::String => "return utf8.decode(raw);".into(),
IrTypeSyncReturn::VecU8 => "return raw;".into(),
}
}
}