diff --git a/src/ProtoQueueMessage.js b/src/ProtoQueueMessage.js index fbcaadd..3a63afc 100644 --- a/src/ProtoQueueMessage.js +++ b/src/ProtoQueueMessage.js @@ -13,18 +13,22 @@ class ProtoQueueMessage extends QueueMessage { return this.ContentSchema.encode(message).finish() } + static getUnserializeOptions () { + return { + enums: String, // enums as string names + longs: Number, // longs as numbers + bytes: Buffer, // bytes as base64 encoded strings + defaults: true, // includes default values + arrays: true, // populates empty arrays (repeated fields) even if defaults=false + objects: true, // populates empty objects (map fields) even if defaults=false + oneofs: true // includes virtual oneof fields set to the present field's name + } + } + static unserialize (buffer, ContentSchema) { try { const message = ContentSchema.decode(buffer) - const data = ContentSchema.toObject(message, { - enums: String, // enums as string names - longs: Number, // longs as strings (requires long.js) - bytes: Buffer, // bytes as base64 encoded strings - defaults: true, // includes default values - arrays: true, // populates empty arrays (repeated fields) even if defaults=false - objects: true, // populates empty objects (map fields) even if defaults=false - oneofs: true // includes virtual oneof fields set to the present field's name - }) + const data = ContentSchema.toObject(message, this.getUnserializeOptions()) return new ProtoQueueMessage('ok', data, null, ContentSchema) } catch (err) {