Skip to content

Commit

Permalink
fix: issues #5
Browse files Browse the repository at this point in the history
Allow negative numbers in int32 and int64
  • Loading branch information
askuzminov committed Mar 25, 2021
1 parent 9035439 commit 8124b1f
Show file tree
Hide file tree
Showing 15 changed files with 800 additions and 203 deletions.
13 changes: 12 additions & 1 deletion proto/whisk/api/shared/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ message Big {
}

message Sign {
sint64 b = 1;
optional double double = 1;
optional float float = 2;
optional int32 int32 = 3;
optional int64 int64 = 4;
optional uint32 uint32 = 5;
optional uint64 uint64 = 6;
optional sint32 sint32 = 7;
optional sint64 sint64 = 8;
optional fixed32 fixed32 = 9;
optional fixed64 fixed64 = 10;
optional sfixed32 sfixed32 = 11;
optional sfixed64 sfixed64 = 12;
}

message Double {
Expand Down
10 changes: 5 additions & 5 deletions src/binary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Field, FieldGet, FieldItem, FieldType } from '../types';
import { Bytes, MapStruct, WrapperStruct } from './constant';
import { getDefault } from './default';
import { PACKED } from './packed';
import { BufRead, ReadMapKeys, readMap, readPacked, readVarint, skip } from './read';
import { BufRead, ReadMapKeys, readMap, readPacked, skip, uint32 } from './read';
import {
BufWrite,
WriteMapKeys,
Expand Down Expand Up @@ -148,7 +148,7 @@ function DecodeHelper<T extends Record<string, any>>(
b.path = path;

while (b.pos < end) {
const val = readVarint(b);
const val = uint32(b);
const tag = val >> 3;
const startPos = b.pos;

Expand Down Expand Up @@ -181,7 +181,7 @@ function DecodeRead(b: BufRead, fieldName: string, result: Record<string, unknow
result[fieldName] = getDefault(item, readMap[item as ReadMapKeys](b));
}
} else if (isFunction(item)) {
result[fieldName] = DecodeHelper(b, item, {}, path, readVarint(b) + b.pos);
result[fieldName] = DecodeHelper(b, item, {}, path, uint32(b) + b.pos);
} else if (isArray(item)) {
if (item[0] === 'repeated') {
if (isString(item[1]) && PACKED[item[1]]) {
Expand All @@ -198,10 +198,10 @@ function DecodeRead(b: BufRead, fieldName: string, result: Record<string, unknow
const mm = result[fieldName];
const m = isObject(mm) ? mm : {};
result[fieldName] = m;
const o = DecodeHelper(b, MapStruct(item), {} as { key: string; value: unknown }, path, readVarint(b) + b.pos);
const o = DecodeHelper(b, MapStruct(item), {} as { key: string; value: unknown }, path, uint32(b) + b.pos);
m[o.key] = o.value;
} else if (item[0] === 'wrapper') {
const o = DecodeHelper(b, WrapperStruct(item[1]), {} as { value: unknown }, path, readVarint(b) + b.pos);
const o = DecodeHelper(b, WrapperStruct(item[1]), {} as { value: unknown }, path, uint32(b) + b.pos);
result[fieldName] = o.value;
}
}
Expand Down

0 comments on commit 8124b1f

Please sign in to comment.