-/// Because we don't expand macros, any code that we need to generated based on their contents has
-/// to be completely manual. In this case its all just serialization, so its not too hard.
-fn convert_macro<W: std::io::Write>(w: &mut W, macro_path: &syn::Path, stream: &TokenStream, types: &TypeResolver) {
- assert_eq!(macro_path.segments.len(), 1);
- match &format!("{}", macro_path.segments.iter().next().unwrap().ident) as &str {
- "impl_writeable" | "impl_writeable_len_match" => {
- let struct_for = if let TokenTree::Ident(i) = stream.clone().into_iter().next().unwrap() { i } else { unimplemented!(); };
- if let Some(s) = types.maybe_resolve_ident(&struct_for) {
- if !types.crate_types.opaques.get(&s).is_some() { return; }
- writeln!(w, "#[no_mangle]").unwrap();
- writeln!(w, "/// Serialize the {} into a byte array which can be read by {}_read", struct_for, struct_for).unwrap();
- writeln!(w, "pub extern \"C\" fn {}_write(obj: &{}) -> crate::c_types::derived::CVec_u8Z {{", struct_for, struct_for).unwrap();
- writeln!(w, "\tcrate::c_types::serialize_obj(unsafe {{ &(*(*obj).inner) }})").unwrap();
- writeln!(w, "}}").unwrap();
- writeln!(w, "#[no_mangle]").unwrap();
- writeln!(w, "pub(crate) extern \"C\" fn {}_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {{", struct_for).unwrap();
- writeln!(w, "\tcrate::c_types::serialize_obj(unsafe {{ &*(obj as *const native{}) }})", struct_for).unwrap();
- writeln!(w, "}}").unwrap();
- writeln!(w, "#[no_mangle]").unwrap();
- writeln!(w, "/// Read a {} from a byte array, created by {}_write", struct_for, struct_for).unwrap();
- writeln!(w, "pub extern \"C\" fn {}_read(ser: crate::c_types::u8slice) -> {} {{", struct_for, struct_for).unwrap();
- writeln!(w, "\tif let Ok(res) = crate::c_types::deserialize_obj(ser) {{").unwrap();
- writeln!(w, "\t\t{} {{ inner: Box::into_raw(Box::new(res)), is_owned: true }}", struct_for).unwrap();
- writeln!(w, "\t}} else {{").unwrap();
- writeln!(w, "\t\t{} {{ inner: std::ptr::null_mut(), is_owned: true }}", struct_for).unwrap();
- writeln!(w, "\t}}\n}}").unwrap();
- }
- },
- _ => {},
- }
-}
-