mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
update
This commit is contained in:
parent
eb8ed94125
commit
e826e6cee9
@ -25,12 +25,8 @@ pub(crate) fn generate_vector_serializer(
|
||||
arg_name: &str,
|
||||
) -> proc_macro2::TokenStream {
|
||||
let values_serializer = match value_ty {
|
||||
ParsedType::Boolean(_) => {
|
||||
quote! {
|
||||
unimplemented!("Vector of booleans is unsupported")
|
||||
}
|
||||
}
|
||||
ParsedType::I8(_)
|
||||
ParsedType::Boolean(_)
|
||||
| ParsedType::I8(_)
|
||||
| ParsedType::U8(_)
|
||||
| ParsedType::I16(_)
|
||||
| ParsedType::U16(_)
|
||||
@ -120,31 +116,16 @@ pub(crate) fn generate_vector_deserializer(
|
||||
let values_deserializer = match value_ty {
|
||||
ParsedType::Boolean(_) => {
|
||||
quote! {
|
||||
unimplemented!("Vector of booleans is unsupported")
|
||||
}
|
||||
}
|
||||
ParsedType::F32(_) => {
|
||||
quote! {
|
||||
Vec::from_raw_parts(offset as _, size as _, size as _)
|
||||
}
|
||||
}
|
||||
ParsedType::F64(_) => {
|
||||
quote! {
|
||||
let mut arg: Vec<u64> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
for value in arg {
|
||||
result.push(f64::from_bits(value as _));
|
||||
}
|
||||
|
||||
result
|
||||
let arg: Vec<u8> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
arg.into_iter().map(|v| v == 1).collect::<Vec<bool>>()
|
||||
}
|
||||
}
|
||||
ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) => {
|
||||
quote! {
|
||||
let mut arg: Vec<u64> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut arg = arg.into_iter();
|
||||
let mut result = Vec::with_capacity(arg.len() / 2);
|
||||
|
||||
while let Some(offset) = arg.next() {
|
||||
let size = arg.next().unwrap();
|
||||
let value = String::from_raw_parts(offset as _, size as _, size as _);
|
||||
@ -164,7 +145,7 @@ pub(crate) fn generate_vector_deserializer(
|
||||
quote! {
|
||||
#inner_vector_deserializer
|
||||
|
||||
let mut arg: Vec<u64> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
let mut arg = arg.into_iter();
|
||||
@ -182,7 +163,7 @@ pub(crate) fn generate_vector_deserializer(
|
||||
let record_name_ident = crate::new_ident!(record_name);
|
||||
|
||||
quote! {
|
||||
let mut arg: Vec<u64> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut arg: Vec<u32> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
for offset in arg {
|
||||
@ -195,21 +176,13 @@ pub(crate) fn generate_vector_deserializer(
|
||||
}
|
||||
_ => {
|
||||
quote! {
|
||||
let mut arg: Vec<u64> = Vec::from_raw_parts(offset as _, size as _, size as _);
|
||||
let mut result = Vec::with_capacity(arg.len());
|
||||
|
||||
for value in arg {
|
||||
result.push(value as _);
|
||||
}
|
||||
|
||||
result
|
||||
Vec::from_raw_parts(offset as _, size as _, size as _)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
unsafe fn #arg(offset: u32, size: u32) -> Vec<#value_ty> {
|
||||
let size = size / 8;
|
||||
#values_deserializer
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ fn generate_deserializer_fn(record: &AstRecordItem) -> proc_macro2::TokenStream
|
||||
|
||||
quote::quote! {
|
||||
pub unsafe fn __fce_generated_deserialize(record_ptr: *const u8) -> Self {
|
||||
let raw_record: Vec<u64> = Vec::from_raw_parts(record_ptr as _, #record_size, #record_size);
|
||||
let raw_record: Vec<u8> = Vec::from_raw_parts(record_ptr as _, #record_size, #record_size);
|
||||
|
||||
#fields_der
|
||||
|
||||
|
@ -42,8 +42,9 @@ impl RecordSerGlueCodeGenerator for AstRecordItem {
|
||||
let field_serialization = match &field.ty {
|
||||
ParsedType::Utf8Str(_) | ParsedType::Utf8String(_) => {
|
||||
quote! {
|
||||
raw_record.push(&#field_ident.as_ptr().to_le_bytes());
|
||||
raw_record.push(&#field_ident.len().to_le_bytes());
|
||||
let field_ident_ptr = #field_ident.as_ptr() as usize;
|
||||
raw_record.extend(&field_ident_ptr.to_le_bytes());
|
||||
raw_record.extend(&#field_ident.len().to_le_bytes());
|
||||
}
|
||||
}
|
||||
ParsedType::Vector(ty, passing_style) => {
|
||||
@ -65,17 +66,18 @@ impl RecordSerGlueCodeGenerator for AstRecordItem {
|
||||
#vector_serializer
|
||||
let #serialized_field_ident = unsafe { #generated_serializer_ident(&#field_ident) };
|
||||
|
||||
raw_record.push(&#serialized_field_ident.0.to_le_bytes());
|
||||
raw_record.push(&#serialized_field_ident.1.to_le_bytes());
|
||||
raw_record.extend(&#serialized_field_ident.0.to_le_bytes());
|
||||
raw_record.extend(&#serialized_field_ident.1.to_le_bytes());
|
||||
}
|
||||
}
|
||||
ParsedType::Record(..) => {
|
||||
quote! {
|
||||
raw_record.push(&#field_ident.__fce_generated_serialize().to_le_bytes());
|
||||
let serialized_struct_ptr = #field_ident.__fce_generated_serialize() as usize;
|
||||
raw_record.extend(&serialized_struct_ptr.to_le_bytes());
|
||||
}
|
||||
}
|
||||
_ => quote! {
|
||||
raw_record.push(&#field_ident.to_le_bytes());
|
||||
raw_record.extend(&#field_ident.to_le_bytes());
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user