-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7643983
commit 0ffbc87
Showing
23 changed files
with
576 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const QueueMessage = require('./QueueMessage') | ||
|
||
class ProtoQueueMessage extends QueueMessage { | ||
serialize () { | ||
const errorMessage = this.ContentSchema.verify(this.data) | ||
|
||
if (errorMessage) { | ||
throw new Error(`Error verifying ProtoQueueMessage data: ${errorMessage}`) | ||
} | ||
|
||
const message = this.ContentSchema.create(this.data) | ||
|
||
return this.ContentSchema.encode(message).finish() | ||
} | ||
|
||
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 | ||
}) | ||
|
||
return new ProtoQueueMessage('ok', data, null, ContentSchema) | ||
} catch (err) { | ||
return new ProtoQueueMessage('error', `Cannot decode protobuf: ${err.message}`, null, ContentSchema) | ||
} | ||
} | ||
} | ||
|
||
module.exports = ProtoQueueMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.