Skip to content

Commit

Permalink
Docs: Clarified typescript example in README, see #744
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Apr 4, 2017
1 parent 3d23eed commit 602065e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
});
```

Expand Down
2 changes: 1 addition & 1 deletion src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 602065e

Please sign in to comment.