-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b43bdd
commit 62941d4
Showing
6 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var path = require("path"); | ||
var tape = require("tape"); | ||
var protobuf = require("../index"); | ||
// to extend Root | ||
require("../ext/descriptor"); | ||
tape.test("extensions", function (test) { | ||
// load document with extended field imported multiple times | ||
var root = protobuf.loadSync(path.resolve(__dirname, "data/test-import-extend/main.proto")); | ||
root.resolveAll(); | ||
// convert to Descriptor Set | ||
var decodedDescriptorSet = root.toDescriptor("proto3"); | ||
// load back from descriptor set | ||
var root2 = protobuf.Root.fromDescriptor(decodedDescriptorSet); | ||
test.pass("should parse and resolve without errors"); | ||
test.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import path = require("path"); | ||
import * as tape from "tape"; | ||
|
||
import * as protobuf from "../index"; | ||
import { IFileDescriptorSet } from "../ext/descriptor"; | ||
// to extend Root | ||
require("../ext/descriptor"); | ||
|
||
interface Descriptor { | ||
toDescriptor( | ||
protoVersion: string | ||
): protobuf.Message<IFileDescriptorSet> & IFileDescriptorSet; | ||
fromDescriptor( | ||
descriptor: IFileDescriptorSet | protobuf.Reader | Uint8Array | ||
): protobuf.Root; | ||
} | ||
|
||
tape.test("extensions", function (test) { | ||
// load document with extended field imported multiple times | ||
const root = protobuf.loadSync( | ||
path.resolve(__dirname, "data/test-import-extend/main.proto") | ||
); | ||
root.resolveAll(); | ||
|
||
// convert to Descriptor Set | ||
const decodedDescriptorSet = (root as unknown as Descriptor).toDescriptor( | ||
"proto3" | ||
); | ||
|
||
// load back from descriptor set | ||
const root2 = (protobuf.Root as unknown as Descriptor).fromDescriptor( | ||
decodedDescriptorSet | ||
); | ||
|
||
test.pass("should parse and resolve without errors"); | ||
test.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
syntax = "proto3"; | ||
|
||
package test.import.extend; | ||
|
||
import "source_a.proto"; | ||
import "source_b.proto"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
syntax = "proto3"; | ||
|
||
package source.a; | ||
|
||
import "validation.proto"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
syntax = "proto3"; | ||
|
||
package source.b; | ||
|
||
import "validation.proto"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
|
||
package validation; | ||
|
||
import "../google/protobuf/descriptor.proto"; | ||
|
||
option java_package = "com.reserve.validation"; | ||
option java_outer_classname = "ValidationRules"; | ||
|
||
extend google.protobuf.FieldOptions { FieldRules rules = 70001; } | ||
|
||
message FieldRules { | ||
reserved 1; | ||
reserved "optional"; | ||
} |