Permalink
Browse files

Docs: Clarified typescript example in README, see #744

  • Loading branch information...
dcodeIO committed Apr 4, 2017
1 parent 3d23eed commit 602065e16862751c515c2f3391ee8b880e8140b1
Showing with 13 additions and 7 deletions.
  1. +12 −6 README.md
  2. +1 −1 src/encoder.js
@@ -444,18 +444,24 @@ 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();
...
const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
let message = AwesomeMessage.create({ awesomeField: "hello" });
console.log(`message = ${JSON.stringify(message)}`);
let buffer = AwesomeMessage.encode(message).finish();
console.log(`buffer = ${Array.prototype.slice.call(buffer)}`);
let decoded = AwesomeMessage.decode(buffer);
console.log(`decoded = ${JSON.stringify(decoded)}`);
});
```
@@ -42,7 +42,7 @@ function encoder(mtype) {
type = field.resolvedType instanceof Enum ? "uint32" : field.type,
wireType = types.basic[type];
ref = "m" + util.safeProp(field.name);
// Map fields
if (field.map) {
gen

0 comments on commit 602065e

Please sign in to comment.