I need to create .proto file for following CRMData case class. I am having confusion with the following datatypes i.e Nested Maps and user defined class (ShipToGroup)
case class CRMData(
var customerShipToGroups : Map[String, Map[UUID, ShipToGroup]],
var shipToGroups : Map[UUID, ShipToGroup],
var shipToGroupLastUsed : UUID,
var defaultShipToGroup : UUID
)
case class ShipToGroup(
var customerUUID : String,
var shipToGroupUUID : UUID,
var name : String,
var address : String,
var companyName : String,
var phoneNumber : Long,
var city : String,
var state : String,
var zip : Int,
var country : String,
var landmark : String,
var addressType : Int,
var emailId : String,
var addedAsBillingAddress : Boolean,
var usedAsBillingAddress: Boolean,
var isDefault : Boolean,
var address2 : String)
The biggest problem you're going to have is that guids (I assume that is what UUID
is) aren't a primitive type in .proto, and map<,>
in .proto only works with string and integer types. I'm going to assume you're happy to use string
as the closest match (and because it works in maps).
You can't do nested maps, but you can have a map where each element is something that has a map.
Combine those two caveats, and you can do something like:
syntax = "proto3";
message CRMData {
map<string, NeedAGoodName> customerShipToGroups = 1;
map<string, ShipToGroup> shipToGroups = 2;
string shipToGroupLastUsed = 3;
string defaultShipToGroup = 4;
}
message NeedAGoodName {
map<string, ShipToGroup> items = 1;
}
message ShipToGroup {
string customerUUID = 1;
string shipToGroupUUID = 2;
// ...
string address2 = 17;
}
Note: it might look like I'm using string
throughout, but that's just because of the specific example; .proto supports more primitives than that - I would expect to see some bool
and uint32
in your final version. Maybe some fixed64
for the phone number, although a string might be more common for that. You might also want an enum
for the addressType
.