forked from cainus/Prozess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OffsetsRequest.js
40 lines (33 loc) · 1.06 KB
/
OffsetsRequest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var bignum = require('bignum');
var binary = require('binary');
var Request = require('./Request');
var BufferMaker = require('buffermaker');
var _ = require('underscore');
var OffsetsRequest = function(topic, partition, since, maxOffsets){
this.topic = topic;
this.partition = partition;
this.since = since;
this.maxOffsets = maxOffsets;
};
OffsetsRequest.prototype.toBytes = function(){
var maxOffsets = this.maxOffsets;
var time;
switch(this.since){
case -1:
time = new Buffer([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
break;
case -2:
time = new Buffer([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE]);
break;
default :
throw "TODO: support unix timestamp";
}
var requestBody = new BufferMaker()
.string(time)
.UInt32BE(maxOffsets)
.make();
// 12 for the body
var req = new Request(this.topic, this.partition, Request.Types.OFFSETS, requestBody);
return req.toBytes();
};
module.exports = OffsetsRequest;