Skip to content

Commit

Permalink
Different field types
Browse files Browse the repository at this point in the history
  • Loading branch information
dfithian committed Dec 17, 2024
1 parent 05f31c3 commit bad4f85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions prost-build/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl<C: ConfigCallbacks> CodeGenerator<'_, C> {
}

self.buf.push_str("\")]\n");
self.append_field_attributes(self.package.clone(), fq_message_name, descriptor, field.descriptor.name().to_string(), FieldDescriptor::Field(field.descriptor.clone()));
self.append_field_attributes(self.package.clone(), fq_message_name, descriptor, field.descriptor.name().to_string(), FieldDescriptor::Field(type_tag.to_string(), field.descriptor.clone()));
self.push_indent();
self.buf.push_str("pub ");
self.buf.push_str(&field.rust_name());
Expand Down Expand Up @@ -588,7 +588,7 @@ impl<C: ConfigCallbacks> CodeGenerator<'_, C> {
value_tag,
field.descriptor.number()
));
self.append_field_attributes(self.package.clone(), fq_message_name, descriptor, field.descriptor.name().to_string(), FieldDescriptor::Field(field.descriptor.clone()));
self.append_field_attributes(self.package.clone(), fq_message_name, descriptor, field.descriptor.name().to_string(), FieldDescriptor::MapField(key_tag.to_string(), value_tag.to_string(), field.descriptor.clone()));
self.push_indent();
self.buf.push_str(&format!(
"pub {}: {}<{}, {}>,\n",
Expand Down Expand Up @@ -673,7 +673,7 @@ impl<C: ConfigCallbacks> CodeGenerator<'_, C> {
ty_tag,
field.descriptor.number()
));
self.append_field_attributes(self.package.to_string(), &oneof_name, descriptor.clone(), field.descriptor.name().to_string(), FieldDescriptor::Field(field.descriptor.clone()));
self.append_field_attributes(self.package.to_string(), &oneof_name, descriptor.clone(), field.descriptor.name().to_string(), FieldDescriptor::OneofVariant(field.descriptor.clone()));

self.push_indent();
let ty = self.resolve_type(&field.descriptor, fq_message_name);
Expand Down
9 changes: 8 additions & 1 deletion prost-build/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,15 @@ pub struct Attribute {

#[derive(Clone)]
pub enum FieldDescriptor {
Field(FieldDescriptorProto),
/// A message's field.
Field(String, FieldDescriptorProto),
/// A oneof's variant.
OneofVariant(FieldDescriptorProto),
/// A map's field.
MapField(String, String, FieldDescriptorProto),
/// A oneof field.
Oneof(OneofDescriptorProto),
/// An enum's variant.
EnumVariant,
}

Expand Down

0 comments on commit bad4f85

Please sign in to comment.