GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.4 KiB

2 months ago
  1. protobufjs/ext/descriptor
  2. =========================
  3. Experimental extension for interoperability with [descriptor.proto](https://github.com/google/protobuf/blob/master/src/google/protobuf/descriptor.proto) types.
  4. Usage
  5. -----
  6. ```js
  7. var protobuf = require("protobufjs"), // requires the full library
  8. descriptor = require("protobufjs/ext/descriptor");
  9. var root = ...;
  10. // convert any existing root instance to the corresponding descriptor type
  11. var descriptorMsg = root.toDescriptor("proto2");
  12. // ^ returns a FileDescriptorSet message, see table below
  13. // encode to a descriptor buffer
  14. var buffer = descriptor.FileDescriptorSet.encode(descriptorMsg).finish();
  15. // decode from a descriptor buffer
  16. var decodedDescriptor = descriptor.FileDescriptorSet.decode(buffer);
  17. // convert any existing descriptor to a root instance
  18. root = protobuf.Root.fromDescriptor(decodedDescriptor);
  19. // ^ expects a FileDescriptorSet message or buffer, see table below
  20. // and start all over again
  21. ```
  22. API
  23. ---
  24. 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:
  25. | Descriptor type | protobuf.js type | Remarks
  26. |-------------------------------|------------------|---------
  27. | **FileDescriptorSet** | Root |
  28. | FileDescriptorProto | | dependencies are not supported
  29. | FileOptions | |
  30. | FileOptionsOptimizeMode | |
  31. | SourceCodeInfo | | not supported
  32. | SourceCodeInfoLocation | |
  33. | GeneratedCodeInfo | | not supported
  34. | GeneratedCodeInfoAnnotation | |
  35. | **DescriptorProto** | Type |
  36. | MessageOptions | |
  37. | DescriptorProtoExtensionRange | |
  38. | DescriptorProtoReservedRange | |
  39. | **FieldDescriptorProto** | Field |
  40. | FieldDescriptorProtoLabel | |
  41. | FieldDescriptorProtoType | |
  42. | FieldOptions | |
  43. | FieldOptionsCType | |
  44. | FieldOptionsJSType | |
  45. | **OneofDescriptorProto** | OneOf |
  46. | OneofOptions | |
  47. | **EnumDescriptorProto** | Enum |
  48. | EnumOptions | |
  49. | EnumValueDescriptorProto | |
  50. | EnumValueOptions | | not supported
  51. | **ServiceDescriptorProto** | Service |
  52. | ServiceOptions | |
  53. | **MethodDescriptorProto** | Method |
  54. | MethodOptions | |
  55. | UninterpretedOption | | not supported
  56. | UninterpretedOptionNamePart | |
  57. 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.
  58. When using TypeScript, the respective interface types can be used to reference specific message instances (i.e. `protobuf.Message<IDescriptorProto>`).