Skip to content

Commit

Permalink
Fix code block formatting in README.md (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
luangong authored Jan 24, 2024
1 parent aa25395 commit 90d7c56
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ For Closure imports, `protoc` will generate a single output file
(`myproto_libs.js` in this example). The generated file will `goog.provide()`
all of the types defined in your .proto files. For example, for the unit
tests the generated files contain many `goog.provide` statements like:

```js
goog.provide('proto.google.protobuf.DescriptorProto');
goog.provide('proto.google.protobuf.DescriptorProto.ExtensionRange');
goog.provide('proto.google.protobuf.DescriptorProto.ReservedRange');
goog.provide('proto.google.protobuf.EnumDescriptorProto');
goog.provide('proto.google.protobuf.EnumOptions');
goog.provide('proto.google.protobuf.DescriptorProto');
goog.provide('proto.google.protobuf.DescriptorProto.ExtensionRange');
goog.provide('proto.google.protobuf.DescriptorProto.ReservedRange');
goog.provide('proto.google.protobuf.EnumDescriptorProto');
goog.provide('proto.google.protobuf.EnumOptions');
```

The generated code will also `goog.require()` many types in the core library,
and they will require many types in the Google Closure library. So make sure
that your `goog.provide()` / `goog.require()` setup can find all of your
Expand All @@ -110,11 +112,13 @@ Google Closure library itself.

Once you've done this, you should be able to import your types with
statements like:

```js
goog.require('proto.my.package.MyMessage');
goog.require('proto.my.package.MyMessage');

var message = proto.my.package.MyMessage();
var message = proto.my.package.MyMessage();
```

If unfamiliar with Closure or its compiler, consider reviewing
[Closure documentation](https://developers.google.com/closure/library).

Expand All @@ -137,11 +141,13 @@ to build it first by running:

Once you've done this, you should be able to import your types with
statements like:

```js
var messages = require('./messages_pb');
var messages = require('./messages_pb');

var message = new messages.MyMessage();
var message = new messages.MyMessage();
```

The `--js_out` flag
-------------------

Expand All @@ -168,17 +174,19 @@ API

The API is not well-documented yet. Here is a quick example to give you an
idea of how the library generally works:

```js
var message = new MyMessage();
var message = new MyMessage();

message.setName("John Doe");
message.setAge(25);
message.setPhoneNumbers(["800-555-1212", "800-555-0000"]);
message.setName("John Doe");
message.setAge(25);
message.setPhoneNumbers(["800-555-1212", "800-555-0000"]);

// Serializes to a UInt8Array.
var bytes = message.serializeBinary();
// Serializes to a UInt8Array.
var bytes = message.serializeBinary();

var message2 = MyMessage.deserializeBinary(bytes);
var message2 = MyMessage.deserializeBinary(bytes);
```

For more examples, see the tests. You can also look at the generated code
to see what methods are defined for your generated messages.

0 comments on commit 90d7c56

Please sign in to comment.