Open kennberg opened 12 years ago
I've come across this myself. I like #2, but with the following options:
a) enums as ints b) enums as strings c) enums as objects of the form { int:13, string:"EACCES" }
I've done #3 for one enum:
var reasonToNum = createReasonToNum();
/*
* create a reason text -> num lookup table
*/
function createReasonToNum() {
var map = {};
for (var i = 1; i < 255; i++) {
try {
var ad = ApplicationData.parse(ApplicationData.serialize({ reason: i }));
map[ad.reason] = i;
} catch (e) {
// FIXME: be more discerning and eat only protobuf generated errors
}
}
return map;
}
Thanks for the loop idea. It probably makes sense to break on exception?
Hey, I've created and open sourced a convenience wrapper for this. Maybe there is a path that we can merge it into this module? I don't mind.
See #19 for another field type which needs some form of 'retrieval type parameterisation'.
Right now when I parse a message in node, the enum value is set to string. However, string is not an efficient representation of enum. It takes longer to compare, it takes more space in the database, etc.
Possible solutions:
Solutions #2 + #3 are likely to generate the nicest and most efficient server-side code.