Skip to content
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

Update the typescript example in README.md #744

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,21 @@ import * as protobuf from "protobufjs";
import * as Long from "long"; // optional

// browser only (alternatively)
import * as protobuf from "./node_modules/protobufjs/index.js";
import * as Long from "./node_modules/long/dist/long.js"; // optional
//import * as protobuf from "./node_modules/protobufjs/index.js";
//import * as Long from "./node_modules/long/dist/long.js"; // optional

protobuf.load("awesome.proto", function(err, root) {
if (err)
throw err;

// example code
var AwesomeMessage = root.lookupType("AwesomeMessage");
var message = AwesomeMessage.create({ awesomeField: "hello" });
var buffer = AwesomeMessage.encode(message).finish();
...
let AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
let message: any = AwesomeMessage.create({ awesomeField: "hello" });
console.log(`message.awesomeField=${message.awesomeField}`);
let buffer = AwesomeMessage.encode(message).finish();
let decodedMessage: any = AwesomeMessage.decode(buffer);
console.log(`decodedMessage.awesomeField=${decodedMessage.awesomeField}`);
// ...
});
```

Expand Down