tree: 4b6b2b9d2246d67ac974752ca71ee9eae5cf571d [path history] [tgz]
  1. index.d.ts
  2. index.js
  3. README.md
  4. test.js
ext/descriptor/README.md

protobufjs/ext/descriptor

Experimental extension for interoperability with descriptor.proto types.

Usage

var protobuf   = require("protobufjs"), // requires the full library
    descriptor = require("protobufjs/ext/descriptor");

var root = ...;

// convert any existing root instance to the corresponding descriptor type
var descriptorMsg = root.toDescriptor("proto2");
// ^ returns a FileDescriptorSet message, see table below

// encode to a descriptor buffer
var buffer = descriptor.FileDescriptorSet.encode(descriptorMsg).finish();

// decode from a descriptor buffer
var decodedDescriptor = descriptor.FileDescriptorSet.decode(buffer);

// convert any existing descriptor to a root instance
root = protobuf.Root.fromDescriptor(decodedDescriptor);
// ^ expects a FileDescriptorSet message or buffer, see table below

// and start all over again

API

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:

Descriptor typeprotobuf.js typeRemarks
FileDescriptorSetRoot
FileDescriptorProtodependencies are not supported
FileOptions
FileOptionsOptimizeMode
SourceCodeInfonot supported
SourceCodeInfoLocation
GeneratedCodeInfonot supported
GeneratedCodeInfoAnnotation
DescriptorProtoType
MessageOptions
DescriptorProtoExtensionRange
DescriptorProtoReservedRange
FieldDescriptorProtoField
FieldDescriptorProtoLabel
FieldDescriptorProtoType
FieldOptions
FieldOptionsCType
FieldOptionsJSType
OneofDescriptorProtoOneOf
OneofOptions
EnumDescriptorProtoEnum
EnumOptions
EnumValueDescriptorProto
EnumValueOptionsnot supported
ServiceDescriptorProtoService
ServiceOptions
MethodDescriptorProtoMethod
MethodOptions
UninterpretedOptionnot supported
UninterpretedOptionNamePart

Note that 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 and generating fictional file names.

When using TypeScript, the respective interface types can be used to reference specific message instances (i.e. protobuf.Message<IDescriptorProto>).