Skip to content

Commit b596607

Browse files
authored
Merge pull request #768 from manni83/protobuf-any-wrapper
Improved fromObject wrapper for google.protobuf.Any.
2 parents 0e471a2 + 8f7111c commit b596607

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/wrappers.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ wrappers[".google.protobuf.Any"] = {
4444
if (object && object["@type"]) {
4545
var type = this.lookup(object["@type"]);
4646
/* istanbul ignore else */
47-
if (type)
48-
return type.fromObject(object);
47+
if (type) {
48+
var obj = this.create({
49+
type_url: object["@type"],
50+
value: type.encode(object).finish()
51+
});
52+
return obj;
53+
}
4954
}
5055

5156
return this.fromObject(object);

tests/comp_google_protobuf_any.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ tape.test("google.protobuf.Any", function(test) {
5050
bar: "a"
5151
}
5252
});
53-
test.ok(foo.foo instanceof Bar.ctor, "should unwrap wrapped Bar in fromObject");
54-
test.same(foo.foo, { bar: "a" }, "should unwrap wrapper Bar in fromObject properly");
55-
56-
obj = Foo.toObject(foo);
57-
test.same(obj.foo, { "@type": ".Bar", bar: "a" }, "should wrap Bar in toObject properly");
53+
test.ok(foo.foo instanceof Any.ctor, "should convert to Any in fromObject");
54+
test.same(foo.foo, { type_url: ".Bar", value: [10, 1, 97] }, "should have correct Any object when converted with fromObject");
5855

5956
test.end();
6057
});

0 commit comments

Comments
 (0)