Skip to content

Fix code block formatting in README.md #187

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

Merged
merged 1 commit into from
Jan 24, 2024
Merged
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
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.