mirror of
https://github.com/openstf/stf
synced 2025-10-05 02:29:26 +02:00
Shorten UUIDs to 16 bytes by using raw buffers.
This commit is contained in:
parent
0bf07ab776
commit
87e7815183
1 changed files with 12 additions and 2 deletions
|
@ -2,11 +2,21 @@ var uuid = require('node-uuid')
|
|||
var Promise = require('bluebird')
|
||||
|
||||
function newId() {
|
||||
return uuid.v4()
|
||||
return uuid.v4(null, new Buffer(16))
|
||||
}
|
||||
|
||||
module.exports.newId = newId
|
||||
|
||||
function compareId(id1, id2) {
|
||||
for (var i = 0; i < 16; ++i) {
|
||||
if (id1[i] < id2[i]) return -1
|
||||
if (id1[i] > id2[i]) return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
module.exports.compareId = compareId
|
||||
|
||||
function q(output, input, channel, args) {
|
||||
var deferred = Promise.defer()
|
||||
, ourId = newId()
|
||||
|
@ -15,7 +25,7 @@ function q(output, input, channel, args) {
|
|||
, remaining = 0 // @todo pass expected number to query
|
||||
|
||||
function onMessage(theirId, serial, state, data) {
|
||||
if (ourId === theirId.toString()) {
|
||||
if (compareId(ourId, theirId) === 0) {
|
||||
serial = serial.toString()
|
||||
state = state.toString()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue