File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ BinaryCursor.prototype.hashOfVariants = function() {
124
124
125
125
/** Read a int of variable length */
126
126
/* TODO - make it work correctly for values bigger than 32bit integers*/
127
+ // XXX TODO - length checks
127
128
BinaryCursor . prototype . varint = function ( ) {
128
129
var result ;
129
130
var first ;
@@ -138,7 +139,6 @@ BinaryCursor.prototype.varint = function() {
138
139
139
140
need = first >> 4 ;
140
141
141
- // XXX TODO - length checks
142
142
if ( ! need ) {
143
143
// unrolled loop for optimization
144
144
result =
@@ -154,8 +154,19 @@ BinaryCursor.prototype.varint = function() {
154
154
155
155
return result ;
156
156
}
157
- // TODO
158
- throw new Error ( 'Reading a varint with need is NYI' ) ;
157
+
158
+ result = first << 8 * need ;
159
+
160
+ var shift_places = 0 ;
161
+ for ( var i = 0 ; i < need ; i ++ ) {
162
+ var byte = buffer . readUInt8 ( this . offset ++ ) ;
163
+ result |= ( byte << shift_places ) ;
164
+ shift_places += 8 ;
165
+ }
166
+ result = result << ( 64 - 4 - 8 * need ) ;
167
+ result = result >> ( 64 - 4 - 8 * need ) ;
168
+
169
+ return result ;
159
170
}
160
171
161
172
/** Read a variant reference */
You can’t perform that action at this time.
0 commit comments