-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Issues/775 #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pavelstudeny
wants to merge
17
commits into
protobufjs:master
Choose a base branch
from
pavelstudeny:issues/775
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Issues/775 #779
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a7488ab
unknown fields test
pavelstudeny 710e318
read bytes instead of skipping a field
pavelstudeny 8a1ed7c
deserialize all unknown fields into __unknownFields
pavelstudeny 42c1617
fix multi-byte IDs
pavelstudeny d1602d6
serialize unknown fields
pavelstudeny e290bbb
discardUnknownFields() on a Type
pavelstudeny a5452b8
multiple and nested fields
pavelstudeny 31bc076
rename fields to better mark what's going on
pavelstudeny 6f8b512
remove commented code
pavelstudeny a95eb08
cameCase public methods
pavelstudeny e50c170
test that mutibyte ids are preserved correctly
pavelstudeny e0d2acf
make __unknownFields non-enumerable so that they don't appear e.g. in…
pavelstudeny 92a09ce
fix line ends
pavelstudeny 28c5817
lint warnings
pavelstudeny 4ebca5e
fix crashes due to problems with <TypedArray>.set on older node versions
pavelstudeny 12210cf
EOL fix
pavelstudeny 5b1133d
code coverage fixes
pavelstudeny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
var tape = require("tape"); | ||
|
||
var protobuf = require(".."); | ||
|
||
var proto = "message Simple_v1 {\ | ||
optional string knownName = 1;\ | ||
optional string knownValue = 3;\ | ||
}\ | ||
message Simple_v2 {\ | ||
optional string knownName = 1;\ | ||
optional int32 unknownFlags = 2;\ | ||
optional string knownValue = 3;\ | ||
}"; | ||
|
||
var msg = { inner: [{}, {}, {}] }; | ||
|
||
tape.test("unknown fields", function (test) { | ||
var root = protobuf.parse(proto).root, | ||
Simple_v1 = root.lookup("Simple_v1"); | ||
Simple_v2 = root.lookup("Simple_v2"); | ||
|
||
var s2 = Simple_v2.create({ knownName: "v2", unknownFlags: 2, knownValue: "dummy" }); | ||
var s1 = Simple_v1.decode(Simple_v2.encode(s2).finish()); | ||
|
||
var restored = Simple_v2.decode(Simple_v1.encode(s1).finish()); | ||
|
||
test.equal(s2.knownName, restored.knownName, "assert: even known fields are missing"); | ||
|
||
test.equal(2, restored.unknownFlags, "are preserved by default"); | ||
test.end(); | ||
}); | ||
|
||
tape.test("discarded unknown fields", function (test) { | ||
var root = protobuf.parse(proto).root, | ||
Simple_v1 = root.lookup("Simple_v1"); | ||
Simple_v2 = root.lookup("Simple_v2"); | ||
|
||
var s2 = Simple_v2.create({ knownName: "v2", unknownFlags: 2, knownValue: "dummy" }); | ||
var s1 = Simple_v1.decode(Simple_v2.encode(s2).finish()); | ||
|
||
try { | ||
Simple_v1.discardUnknownFields(s1); | ||
} | ||
catch (ex) { | ||
test.end("discardUnknownFields() exception: " + ex); | ||
return; | ||
} | ||
|
||
var restored = Simple_v2.decode(Simple_v1.encode(s1).finish()); | ||
|
||
test.equal(0, restored.unknownFlags, "are removed from the message"); | ||
test.end(); | ||
}); | ||
|
||
tape.test("multiple unknown fields", function (test) { | ||
var proto = "message Simple_v1 {\ | ||
optional string knownName = 1;\ | ||
optional string knownValue = 3;\ | ||
}\ | ||
message Simple_v2 {\ | ||
optional string knownName = 1;\ | ||
optional int32 unknownFlags = 2;\ | ||
optional string knownValue = 3;\ | ||
optional int32 unknownOptions = 4;\ | ||
}"; | ||
|
||
var root = protobuf.parse(proto).root, | ||
Simple_v1 = root.lookup("Simple_v1"); | ||
Simple_v2 = root.lookup("Simple_v2"); | ||
|
||
var s2 = Simple_v2.create({ knownName: "v2", unknownFlags: 2, knownValue: "dummy", unknownOptions: 3 }); | ||
var s1 = Simple_v1.decode(Simple_v2.encode(s2).finish()); | ||
|
||
var restored = Simple_v2.decode(Simple_v1.encode(s1).finish()); | ||
|
||
test.equal(2, restored.unknownFlags, "(2) are preserved by default"); | ||
test.equal(3, restored.unknownOptions, "(4) are preserved by default"); | ||
test.end(); | ||
}); | ||
|
||
tape.test("nested unknown fields", function (test) { | ||
var nproto = proto + "\ | ||
message Container_v1 {\ | ||
optional Simple_v1 elem = 1;\ | ||
}\ | ||
message Container_v2 {\ | ||
optional Simple_v2 elem = 1;\ | ||
}"; | ||
|
||
var root = protobuf.parse(nproto).root, | ||
Container_v1 = root.lookup("Container_v1"); | ||
Container_v2 = root.lookup("Container_v2"); | ||
|
||
var c2 = Container_v2.create({ elem: { knownName: "v2", unknownFlags: 2, knownValue: "dummy" } }); | ||
var c1 = Container_v1.decode(Container_v2.encode(c2).finish()); | ||
|
||
var restored = Container_v2.decode(Container_v1.encode(c1).finish()); | ||
|
||
test.equal(c2.elem.knownName, restored.elem.knownName, "assert: even known fields are missing"); | ||
|
||
test.equal(2, restored.elem.unknownFlags, "are preserved by default"); | ||
test.end(); | ||
}); | ||
|
||
tape.test("multibyte-id unknown fields", function (test) { | ||
var proto = "message Simple_v1 {\ | ||
optional string knownName = 1;\ | ||
optional string knownValue = 3;\ | ||
}\ | ||
message Simple_v2 {\ | ||
optional string knownName = 1;\ | ||
optional int32 unknownFlags = 296;\ | ||
optional string knownValue = 3;\ | ||
}"; | ||
|
||
var root = protobuf.parse(proto).root, | ||
Simple_v1 = root.lookup("Simple_v1"); | ||
Simple_v2 = root.lookup("Simple_v2"); | ||
|
||
var s2 = Simple_v2.create({ knownName: "v2", unknownFlags: 2, knownValue: "dummy", unknownOptions: 3 }); | ||
var s1 = Simple_v1.decode(Simple_v2.encode(s2).finish()); | ||
|
||
var restored = Simple_v2.decode(Simple_v1.encode(s1).finish()); | ||
|
||
test.equal(2, restored.unknownFlags, "are preserved by default"); | ||
test.end(); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems that writeBytes (the one using util.Array) might be incorrect on older node versions, but it was probably never called until now