static void PrepareProtoType(Message m, Field f)
{
//Change property name to C# style, CamelCase.
f.Name = GetCSPropertyName (m, f.Name);
f.ProtoType = GetScalarProtoType (f.ProtoTypeName);
//Wire, and set type
switch (f.ProtoType) {
case ProtoTypes.Double:
case ProtoTypes.Fixed64:
case ProtoTypes.Sfixed64:
f.WireType = Wire.Fixed64;
break;
case ProtoTypes.Float:
case ProtoTypes.Fixed32:
case ProtoTypes.Sfixed32:
f.WireType = Wire.Fixed32;
break;
case ProtoTypes.Int32:
case ProtoTypes.Int64:
case ProtoTypes.Uint32:
case ProtoTypes.Uint64:
case ProtoTypes.Sint32:
case ProtoTypes.Sint64:
case ProtoTypes.Bool:
f.WireType = Wire.Varint;
break;
case ProtoTypes.String:
case ProtoTypes.Bytes:
f.WireType = Wire.LengthDelimited;
break;
default:
MessageEnumBase pt = GetProtoType (m, f.ProtoTypeName);
if (pt == null) {
//Assumed to be a message defined elsewhere
f.ProtoType = ProtoTypes.Message;
f.WireType = Wire.LengthDelimited;
f.ProtoTypeMessage = new MessageName (m, f.ProtoTypeName);
}
if (pt is MessageEnum) {
f.ProtoType = ProtoTypes.Enum;
f.WireType = Wire.Varint;
f.ProtoTypeEnum = (MessageEnum)pt;
}
if (pt is Message) {
f.ProtoType = ProtoTypes.Message;
f.WireType = Wire.LengthDelimited;
f.ProtoTypeMessage = (Message)pt;
}
string[] parts = f.ProtoTypeName.Split ('.');
string cc = GetCamelCase (parts [parts.Length - 1]);
if (pt is Message) {
f.CSClass = cc;
#if GENERATE_INTERFACE
f.CSType += "I" + cc;
#else
f.CSType += cc;
#endif
break;
} else
f.CSType = cc;
break;
}
if (f.OptionPacked) {
if (f.WireType == Wire.LengthDelimited)
throw new InvalidDataException ("Packed field not allowed for length delimited types");
f.WireType = Wire.LengthDelimited;
}
if (f.OptionCodeType != null) {
f.CSClass = f.OptionCodeType;
f.CSType = f.OptionCodeType;
}
if (f.CSType == null) {
f.CSType = GetCSType (f.ProtoType);
f.CSClass = f.CSType;
}
}