Skip to content

Commit

Permalink
add support on the Long string value
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamershl committed Dec 1, 2016
1 parent d3ae961 commit b233c43
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,37 +214,28 @@ function writeVarint64(buf, pos, val) {

/**
* Writes an unsigned 64 bit value as a varint.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
*/
WriterPrototype.uint64 = function write_uint64(value) {
var bits;
if (typeof value === 'number')
bits = value ? LongBits.fromNumber(value) : LongBits.zero;
else if (value.low || value.high)
bits = new LongBits(value.low >>> 0, value.high >>> 0);
else
bits = LongBits.zero;
var bits = LongBits.from(value).zzEncode();
return this.push(writeVarint64, bits.length(), bits);
};

/**
* Writes a signed 64 bit value as a varint.
* @function
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
*/
WriterPrototype.int64 = WriterPrototype.uint64;

/**
* Writes a signed 64 bit value as a varint, zig-zag encoded.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
*/
WriterPrototype.sint64 = function sint64(value) {
var bits = LongBits.from(value).zzEncode();
return this.push(writeVarint64, bits.length(), bits);
};
WriterPrototype.sint64 = WriterPrototype.uint64;

/**
* Writes a boolish value as a varint.
Expand Down

0 comments on commit b233c43

Please sign in to comment.