File tree 1 file changed +13
-4
lines changed
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 4
4
/*eslint-disable strict, no-console*/
5
5
var protobuf = require ( ".." ) ; // require("protobufjs");
6
6
7
+ // traverse-types.proto
7
8
var proto = "syntax=\"proto3\";\
8
9
package example;\
9
10
message Foo {\
@@ -17,17 +18,25 @@ message Bar {\
17
18
}\
18
19
}" ;
19
20
21
+ // the following is loading a string.
22
+ // in a real application, it'd be more like protobuf.load("traverse-types.proto", ...)
23
+ protobuf . parse . filename = "traverse-types.proto" ;
24
+ var root = protobuf . parse ( proto ) . root ;
25
+
20
26
function traverseTypes ( current , fn ) {
21
- if ( current instanceof protobuf . Type )
27
+ if ( current instanceof protobuf . Type ) // and/or protobuf.Enum, protobuf.Service etc.
22
28
fn ( current ) ;
23
29
if ( current . nestedArray )
24
30
current . nestedArray . forEach ( function ( nested ) {
25
31
traverseTypes ( nested , fn ) ;
26
32
} ) ;
27
33
}
28
34
29
- var root = protobuf . parse ( proto ) . root ;
30
-
31
35
traverseTypes ( root , function ( type ) {
32
- console . log ( type . fullName ) ;
36
+ console . log (
37
+ type . constructor . className + " " + type . name
38
+ + "\n fully qualified name: " + type . fullName
39
+ + "\n defined in: " + type . filename
40
+ + "\n parent: " + type . parent + " in " + type . parent . filename
41
+ ) ;
33
42
} ) ;
You can’t perform that action at this time.
0 commit comments