Skip to content

Commit 799c1c1

Browse files
committed
Add support for long strings, fixes #509
1 parent 6e5fdb6 commit 799c1c1

8 files changed

+48
-31
lines changed

Diff for: dist/protobuf.js

+14-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/protobuf.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/protobuf.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/protobuf.min.js.gz

-9 Bytes
Binary file not shown.

Diff for: dist/protobuf.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/util/longbits.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ LongBits.fromNumber = function fromNumber(value) {
6666
};
6767

6868
/**
69-
* Constrcuts new long bits from a number or long.
70-
* @param {Long|number} value Value
69+
* Constructs new long bits from a number, long or string.
70+
* @param {Long|number|string} value Value
7171
* @returns {util.LongBits} Instance
72+
* @throws {TypeError} If `value` is a string and no long library is present.
7273
*/
7374
LongBits.from = function from(value) {
7475
switch (typeof value) {

Diff for: src/writer.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ function writeVarint64(buf, pos, val) {
214214

215215
/**
216216
* Writes an unsigned 64 bit value as a varint.
217-
* @param {Long|number} value Value to write
217+
* @param {Long|number|string} value Value to write
218218
* @returns {Writer} `this`
219+
* @throws {TypeError} If `value` is a string and no long library is present.
219220
*/
220221
WriterPrototype.uint64 = function write_uint64(value) {
221222
var bits = LongBits.from(value);
@@ -225,15 +226,17 @@ WriterPrototype.uint64 = function write_uint64(value) {
225226
/**
226227
* Writes a signed 64 bit value as a varint.
227228
* @function
228-
* @param {Long|number} value Value to write
229+
* @param {Long|number|string} value Value to write
229230
* @returns {Writer} `this`
231+
* @throws {TypeError} If `value` is a string and no long library is present.
230232
*/
231233
WriterPrototype.int64 = WriterPrototype.uint64;
232234

233235
/**
234236
* Writes a signed 64 bit value as a varint, zig-zag encoded.
235-
* @param {Long|number} value Value to write
237+
* @param {Long|number|string} value Value to write
236238
* @returns {Writer} `this`
239+
* @throws {TypeError} If `value` is a string and no long library is present.
237240
*/
238241
WriterPrototype.sint64 = function sint64(value) {
239242
var bits = LongBits.from(value).zzEncode();
@@ -286,11 +289,13 @@ WriterPrototype.fixed64 = function write_fixed64(value) {
286289

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

296301
function writeFloat(buf, pos, val) {

Diff for: types/protobuf.js.d.ts

+17-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/*
55
* protobuf.js v6.0.1 TypeScript definitions
6-
* Generated Wed, 30 Nov 2016 22:50:15 UTC
6+
* Generated Thu, 01 Dec 2016 10:14:01 UTC
77
*/
88
declare module protobuf {
99

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

15971597
/**
1598-
* Constrcuts new long bits from a number or long.
1599-
* @param {Long|number} value Value
1598+
* Constructs new long bits from a number, long or string.
1599+
* @param {Long|number|string} value Value
16001600
* @returns {util.LongBits} Instance
1601+
* @throws {TypeError} If `value` is a string and no long library is present.
16011602
*/
1602-
static from(value: (Long|number)): util.LongBits;
1603+
static from(value: (Long|number|string)): util.LongBits;
16031604

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

19261927
/**
19271928
* Writes an unsigned 64 bit value as a varint.
1928-
* @param {Long|number} value Value to write
1929+
* @param {Long|number|string} value Value to write
19291930
* @returns {Writer} `this`
1931+
* @throws {TypeError} If `value` is a string and no long library is present.
19301932
*/
1931-
uint64(value: (Long|number)): Writer;
1933+
uint64(value: (Long|number|string)): Writer;
19321934

19331935
/**
19341936
* Writes a signed 64 bit value as a varint.
19351937
* @function
1936-
* @param {Long|number} value Value to write
1938+
* @param {Long|number|string} value Value to write
19371939
* @returns {Writer} `this`
1940+
* @throws {TypeError} If `value` is a string and no long library is present.
19381941
*/
1939-
int64(value: (Long|number)): Writer;
1942+
int64(value: (Long|number|string)): Writer;
19401943

19411944
/**
19421945
* Writes a signed 64 bit value as a varint, zig-zag encoded.
1943-
* @param {Long|number} value Value to write
1946+
* @param {Long|number|string} value Value to write
19441947
* @returns {Writer} `this`
1948+
* @throws {TypeError} If `value` is a string and no long library is present.
19451949
*/
1946-
sint64(value: (Long|number)): Writer;
1950+
sint64(value: (Long|number|string)): Writer;
19471951

19481952
/**
19491953
* Writes a boolish value as a varint.
@@ -1975,10 +1979,11 @@ declare module protobuf {
19751979

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

19831988
/**
19841989
* Writes a float (32 bit).

0 commit comments

Comments
 (0)