(
fd: &ProtoReprInfo,
compiler: &mut SerializationCompiler,
msg_info: &MessageInfo,
)
| 660 | } |
| 661 | |
| 662 | fn add_impl( |
| 663 | fd: &ProtoReprInfo, |
| 664 | compiler: &mut SerializationCompiler, |
| 665 | msg_info: &MessageInfo, |
| 666 | ) -> Result<()> { |
| 667 | let type_annotations = msg_info.get_type_params(false, &fd)?; |
| 668 | let where_clause = msg_info.get_where_clause(false, &fd)?; |
| 669 | let impl_context = ImplContext::new( |
| 670 | StructName::new(&msg_info.get_name(), type_annotations.clone()), |
| 671 | None, |
| 672 | where_clause, |
| 673 | ); |
| 674 | |
| 675 | compiler.add_context(Context::Impl(impl_context))?; |
| 676 | // add constants at the top of the impl |
| 677 | compiler.add_const_def( |
| 678 | "BITMAP_SIZE", |
| 679 | "usize", |
| 680 | &format!("{}", msg_info.get_bitmap_size()), |
| 681 | )?; |
| 682 | |
| 683 | for field in msg_info.get_fields().iter() { |
| 684 | compiler.add_newline()?; |
| 685 | let field_info = FieldInfo(field.clone()); |
| 686 | for (var, typ, def) in msg_info.get_constants(&field_info, false, false)?.iter() { |
| 687 | compiler.add_const_def(var, typ, def)?; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | compiler.add_newline()?; |
| 692 | let new_func_context = FunctionContext::new("new", true, vec![], "Self"); |
| 693 | compiler.add_context(Context::Function(new_func_context))?; |
| 694 | let struct_def_context = StructDefContext::new(&msg_info.get_name()); |
| 695 | compiler.add_context(Context::StructDef(struct_def_context))?; |
| 696 | compiler.add_struct_def_field("bitmap", "[0u8; Self::BITMAP_SIZE]")?; |
| 697 | for field in msg_info.get_fields().iter() { |
| 698 | let field_info = FieldInfo(field.clone()); |
| 699 | if field_info.is_list() { |
| 700 | if field_info.is_int_list() { |
| 701 | compiler.add_struct_def_field(&field_info.get_name(), "List::default()")?; |
| 702 | } else { |
| 703 | compiler.add_struct_def_field(&field_info.get_name(), "VariableList::default()")?; |
| 704 | } |
| 705 | } else { |
| 706 | compiler |
| 707 | .add_struct_def_field(&field_info.get_name(), &fd.get_default_type(field_info)?)?; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | compiler.pop_context()?; // end of struct definition |
| 712 | compiler.pop_context()?; // end of new function |
| 713 | |
| 714 | for field in msg_info.get_fields().iter() { |
| 715 | let field_info = FieldInfo(field.clone()); |
| 716 | add_field_methods(fd, compiler, &field_info)?; |
| 717 | } |
| 718 | |
| 719 | compiler.pop_context()?; |
no test coverage detected