Skip to content

Commit

Permalink
address PR reviews 2
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown unknown committed Nov 29, 2023
1 parent a0e9770 commit 80211c4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions codec/unknownproto/unknown_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func RejectUnknownFields(bz []byte, msg proto.Message, allowUnknownNonCriticals
Type: reflect.ValueOf(msg).Type().String(),
TagNum: tagNum,
GotWireType: wireType,
WantWireType: fieldTypeToProtowireType(fieldDescProto.GetType()),
WantWireType: toProtowireType(fieldDescProto.GetType()),
}
}
default:
Expand Down Expand Up @@ -442,8 +442,8 @@ func (d DefaultAnyResolver) Resolve(typeURL string) (proto.Message, error) {
return reflect.New(mt.Elem()).Interface().(proto.Message), nil
}

// fieldTypeToProtowireType converts a descriptorpb.FieldDescriptorProto_Type to a protowire.Type.
func fieldTypeToProtowireType(fieldType descriptorpb.FieldDescriptorProto_Type) protowire.Type {
// toProtowireType converts a descriptorpb.FieldDescriptorProto_Type to a protowire.Type.
func toProtowireType(fieldType descriptorpb.FieldDescriptorProto_Type) protowire.Type {
switch fieldType {
// varint encoded
case descriptorpb.FieldDescriptorProto_TYPE_INT64,
Expand All @@ -455,24 +455,27 @@ func fieldTypeToProtowireType(fieldType descriptorpb.FieldDescriptorProto_Type)
descriptorpb.FieldDescriptorProto_TYPE_SINT32,
descriptorpb.FieldDescriptorProto_TYPE_SINT64:
return protowire.VarintType

// fixed64 encoded
case descriptorpb.FieldDescriptorProto_TYPE_DOUBLE,
descriptorpb.FieldDescriptorProto_TYPE_FIXED64,
descriptorpb.FieldDescriptorProto_TYPE_SFIXED64:
return protowire.Fixed64Type

// fixed32 encoded
case descriptorpb.FieldDescriptorProto_TYPE_FLOAT,
descriptorpb.FieldDescriptorProto_TYPE_FIXED32,
descriptorpb.FieldDescriptorProto_TYPE_SFIXED32:
return protowire.Fixed32Type

// bytes encoded
case descriptorpb.FieldDescriptorProto_TYPE_STRING,
descriptorpb.FieldDescriptorProto_TYPE_BYTES,
descriptorpb.FieldDescriptorProto_TYPE_MESSAGE,
descriptorpb.FieldDescriptorProto_TYPE_GROUP:
return protowire.BytesType
default:
panic(fmt.Sprintf("unknown field type %s", fieldType.String()))
panic(fmt.Sprintf("unknown field type %s", fieldType))
}
}

Expand Down

0 comments on commit 80211c4

Please sign in to comment.