fuwaneko / node-protobuf

Google Protocol Buffers wrapper for Node.js [UNMAINTAINED]
180 stars 42 forks source link

How to get enum value #10

Closed maoziliang closed 10 years ago

maoziliang commented 10 years ago
// test.proto
enum TestEnum {
   first = 0,
   second = 1
}

how to get the value of enum first from node

fuwaneko commented 10 years ago

While serializing you can supply either strings or integers as enum values. E.g. you can pass

obj = {
  enumValue: "first"
}

// also valid
obj = {
  enumValue: 0
}

While parsing you always get string. E.g. after parsing buffers serialized from both objects from above you'll get this:

parsedObj = {
  enumValue: "first"
}