Skip to content

Commit

Permalink
Docs: Additional notes on ext/descriptor [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Apr 12, 2017
1 parent 708552b commit ef92da3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ext/descriptor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Usage
var protobuf = require("protobufjs"),
descriptor = require("protobufjs/ext/descriptor");

var descriptor = ...; // either a FieldDescriptorSet buffer or JSON object
var descriptor = ...; // either a FieldDescriptorSet buffer, a FieldDescriptorSet message instance or a corresponding valid JSON object
var root = protobuf.Root.fromDescriptor(descriptor);
var rootDescriptor = root.toDescriptor("proto3");
```

API
---

The extension adds `.fromDescriptor(descriptor[, syntax])` and `#toDescriptor([syntax])` methods to reflection objects and exports the internally used `Root` instance that contains the types present in descriptor.proto.
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.
2 changes: 1 addition & 1 deletion ext/descriptor/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as $protobuf from "../..";

declare const descriptor: $protobuf.Root;
declare const descriptor: $protobuf.Namespace;

interface IFileDescriptorSet {
file: IFileDescriptorProto[];
Expand Down
12 changes: 7 additions & 5 deletions ext/descriptor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ var $protobuf = require("..");

/**
* Descriptor extension (ext/descriptor).
* Exports the `.google.protobuf` namespace of the internally used {@link Root} instance containing the types present in descriptor.proto.
* @type {Root}
* @tstype $protobuf.Root
* @tstype $protobuf.Namespace
* @const
* @see https://github.com/dcodeIO/protobuf.js/tree/master/ext/descriptor
*/
var descriptor = module.exports = $protobuf.Root.fromJSON(require("../google/protobuf/descriptor.json")).lookup(".google.protobuf");

var google = descriptor,
var google = descriptor, // aliased used where `descriptor` is a local var
Root = $protobuf.Root,
Enum = $protobuf.Enum,
Type = $protobuf.Type,
Expand Down Expand Up @@ -44,7 +46,7 @@ var google = descriptor,

/**
* Creates a root from a descriptor set.
* @param {Properties<IFileDescriptorSet>|Reader|Uint8Array} descriptor Descriptor
* @param {IFileDescriptorSet|Reader|Uint8Array} descriptor Descriptor
* @returns {Root} Root instance
* @see Part of the {@link descriptor} extension (ext/descriptor)
*/
Expand Down Expand Up @@ -144,7 +146,7 @@ var unnamedMessageIndex = 0;

/**
* Creates a type from a descriptor.
* @param {Properties<IDescriptorProto>|Reader|Uint8Array} descriptor Descriptor
* @param {IDescriptorProto|Reader|Uint8Array} descriptor Descriptor
* @param {string} [syntax="proto2"] Syntax
* @returns {Type} Type instance
* @see Part of the {@link descriptor} extension (ext/descriptor)
Expand Down Expand Up @@ -520,7 +522,7 @@ var unnamedServiceIndex = 0;

/**
* Creates a service from a descriptor.
* @param {Properties<IServiceDescriptorProto>|Reader|Uint8Array} descriptor Descriptor
* @param {IServiceDescriptorProto|Reader|Uint8Array} descriptor Descriptor
* @returns {Service} Service instance
* @see Part of the {@link descriptor} extension (ext/descriptor)
*/
Expand Down

0 comments on commit ef92da3

Please sign in to comment.