Skip to content

Commit 6493f52

Browse files
committed
Docs: Added more info to ext/descriptor README, see #757
1 parent 1fc911c commit 6493f52

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

ext/descriptor/README.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
protobufjs/ext/descriptor
22
=========================
33

4-
Experimental [protobuf.js](https://github.com/dcodeIO/protobuf.js) extension for interoperability with descriptor.proto types.
4+
Experimental extension for interoperability with descriptor.proto types.
55

66
Usage
77
-----
@@ -10,12 +10,50 @@ Usage
1010
var protobuf = require("protobufjs"),
1111
descriptor = require("protobufjs/ext/descriptor");
1212

13-
var descriptor = ...; // either a FieldDescriptorSet buffer, a FieldDescriptorSet message instance or a corresponding valid JSON object
14-
var root = protobuf.Root.fromDescriptor(descriptor);
15-
var rootDescriptor = root.toDescriptor("proto3");
13+
// take any extisting root object
14+
var root = ...;
15+
16+
// convert it to the corresponding descriptor type
17+
var fileDescriptorSet = root.toDescriptor("proto2");
18+
19+
// encode it
20+
var buffer = descriptor.FileDescriptorSet.encode(fileDescriptorSet).finish();
21+
22+
// decode it back
23+
var decoded = descriptor.FileDescriptorSet.decode(buffer);
24+
25+
// convert it back to a protobuf.js root
26+
root = protobuf.Root.fromDescriptor(decoded, "proto2");
27+
28+
// and start all over again
1629
```
1730

1831
API
1932
---
2033

21-
The extension adds `.fromDescriptor(descriptor[, syntax])` and `#toDescriptor([syntax])` methods to reflection objects and exports the `.google.protobuf` namespace of the internally used `Root` instance containing the types present in descriptor.proto.
34+
The extension adds `.fromDescriptor(descriptor[, syntax])` and `#toDescriptor([syntax])` methods to reflection objects and exports the `.google.protobuf` namespace of the internally used `Root` instance containing the following types present in descriptor.proto.
35+
36+
| Descriptor type | protobuf.js type | Remarks
37+
|--------------------------|------------------|---------
38+
| FileDescriptorSet | Root |
39+
| FileDescriptorProto | Root | not supported: dependencies, sourceCodeInfo
40+
| FileOptions | Root | not supported
41+
| DescriptorProto | Type |
42+
| MessageOptions | Type | not supported
43+
| FieldDescriptorProto | Field | not supported: defaultValue, jsonValue
44+
| FieldOptions | Field | only packed
45+
| OneofDescriptorProto | OneOf |
46+
| OneofOptions | OneOf | not supported
47+
| EnumDescriptorProto | Enum |
48+
| EnumValueDescriptorProto | Enum |
49+
| EnumOptions | Enum | only allowAlias
50+
| EnumValueOptions | Enum | not supported
51+
| ServiceDescriptorProto | Service |
52+
| ServiceOptions | Service | not supported
53+
| MethodDescriptorProto | Method |
54+
| MethodOptions | Method | not supported
55+
| UninterpretedOption | | not supported
56+
| SourceCodeInfo | | not supported
57+
| GeneratedCodeInfo | | not supported
58+
59+
Additionally, not all features of descriptor.proto translate perfectly to a protobuf.js root instance. A root instance has only limited knowlege of packages or individual files for example, which is then compensated by guessing.

0 commit comments

Comments
 (0)