mirror of
https://github.com/protobufjs/protobuf.js.git
synced 2025-12-08 20:58:55 +00:00
20 lines
838 B
TypeScript
20 lines
838 B
TypeScript
import * as protobuf from "../..";
|
|
import * as test from "./test";
|
|
|
|
// should encode an object implementing the interface
|
|
let mInterface: test.jspb.test.ISimple1 = { aString: "a-string", aRepeatedString: [ "a", "repeated", "string" ], aBoolean: true };
|
|
let mInterfaceWriter: protobuf.Writer = test.jspb.test.Simple1.encode(mInterface);
|
|
|
|
// should encode a message
|
|
let mMessage: test.jspb.test.Simple1 = test.jspb.test.Simple1.create(mInterface);
|
|
let mMessageWritter: protobuf.Writer = test.jspb.test.Simple1.encode(mMessage);
|
|
|
|
// should allow to assign a message to an interface
|
|
mInterface = mMessage;
|
|
|
|
// should not allow to assign an interface to a message
|
|
// mMessage = mInterface;
|
|
|
|
// should always decode to a message, not an interface
|
|
let dMessage: test.jspb.test.Simple1 = test.jspb.test.Simple1.decode(mInterfaceWriter.finish());
|