Skip to content

Commit

Permalink
Add support for long strings, fixes #509
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 1, 2016
1 parent 6e5fdb6 commit 799c1c1
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 31 deletions.
22 changes: 14 additions & 8 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/util/longbits.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ LongBits.fromNumber = function fromNumber(value) {
};

/**
* Constrcuts new long bits from a number or long.
* @param {Long|number} value Value
* Constructs new long bits from a number, long or string.
* @param {Long|number|string} value Value
* @returns {util.LongBits} Instance
* @throws {TypeError} If `value` is a string and no long library is present.
*/
LongBits.from = function from(value) {
switch (typeof value) {
Expand Down
15 changes: 10 additions & 5 deletions src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ 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`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
WriterPrototype.uint64 = function write_uint64(value) {
var bits = LongBits.from(value);
Expand All @@ -225,15 +226,17 @@ WriterPrototype.uint64 = function write_uint64(value) {
/**
* 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`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
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`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
WriterPrototype.sint64 = function sint64(value) {
var bits = LongBits.from(value).zzEncode();
Expand Down Expand Up @@ -286,11 +289,13 @@ WriterPrototype.fixed64 = function write_fixed64(value) {

/**
* Writes a 64 bit value as fixed 64 bits, zig-zag encoded.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
WriterPrototype.sfixed64 = function write_sfixed64(value) {
return this.push(writeFixed64, 8, LongBits.from(value).zzEncode());
var bits = LongBits.from(value).zzEncode();
return this.push(writeFixed32, 4, bits.hi).push(writeFixed32, 4, bits.lo);
};

function writeFloat(buf, pos, val) {
Expand Down
29 changes: 17 additions & 12 deletions types/protobuf.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*
* protobuf.js v6.0.1 TypeScript definitions
* Generated Wed, 30 Nov 2016 22:50:15 UTC
* Generated Thu, 01 Dec 2016 10:14:01 UTC
*/
declare module protobuf {

Expand Down Expand Up @@ -1595,11 +1595,12 @@ declare module protobuf {
static fromNumber(value: number): util.LongBits;

/**
* Constrcuts new long bits from a number or long.
* @param {Long|number} value Value
* Constructs new long bits from a number, long or string.
* @param {Long|number|string} value Value
* @returns {util.LongBits} Instance
* @throws {TypeError} If `value` is a string and no long library is present.
*/
static from(value: (Long|number)): util.LongBits;
static from(value: (Long|number|string)): util.LongBits;

/**
* Converts this long bits to a possibly unsafe JavaScript number.
Expand Down Expand Up @@ -1925,25 +1926,28 @@ declare module protobuf {

/**
* 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`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
uint64(value: (Long|number)): Writer;
uint64(value: (Long|number|string)): Writer;

/**
* 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`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
int64(value: (Long|number)): Writer;
int64(value: (Long|number|string)): Writer;

/**
* 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`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
sint64(value: (Long|number)): Writer;
sint64(value: (Long|number|string)): Writer;

/**
* Writes a boolish value as a varint.
Expand Down Expand Up @@ -1975,10 +1979,11 @@ declare module protobuf {

/**
* Writes a 64 bit value as fixed 64 bits, zig-zag encoded.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
sfixed64(value: (Long|number)): Writer;
sfixed64(value: (Long|number|string)): Writer;

/**
* Writes a float (32 bit).
Expand Down

0 comments on commit 799c1c1

Please sign in to comment.