Redecode unknown protobuf fields before writing
This commit is contained in:
parent
efe5d86424
commit
6e4a3561f1
2 changed files with 50 additions and 7 deletions
|
@ -88,8 +88,31 @@ describe('Proto#__unknownFields', () => {
|
|||
const decodedConcat = Full.decode(concat);
|
||||
|
||||
assert.strictEqual(decodedConcat.a, 'hello');
|
||||
assert.strictEqual(decodedConcat.b, true);
|
||||
assert.isTrue(decodedConcat.b);
|
||||
assert.strictEqual(decodedConcat.c, 42);
|
||||
assert.strictEqual(Buffer.from(decodedConcat.d).toString(), 'ohai');
|
||||
});
|
||||
|
||||
it('should decode unknown fields before reencoding them', () => {
|
||||
const full = Full.encode({
|
||||
a: 'hello',
|
||||
b: true,
|
||||
c: 42,
|
||||
d: Buffer.from('ohai'),
|
||||
}).finish();
|
||||
|
||||
const partial = Partial.decode(full);
|
||||
assert.isUndefined(partial.b);
|
||||
|
||||
const encoded = Full.encode({
|
||||
...partial,
|
||||
b: false,
|
||||
}).finish();
|
||||
const decoded = Full.decode(encoded);
|
||||
|
||||
assert.strictEqual(decoded.a, 'hello');
|
||||
assert.isFalse(decoded.b);
|
||||
assert.strictEqual(decoded.c, 42);
|
||||
assert.strictEqual(Buffer.from(decoded.d).toString(), 'ohai');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue