File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44/*eslint-disable strict, no-console*/
55var protobuf = require ( ".." ) ; // require("protobufjs");
66
7+ // traverse-types.proto
78var proto = "syntax=\"proto3\";\
89package example;\
910message Foo {\
@@ -17,17 +18,25 @@ message Bar {\
1718 }\
1819}" ;
1920
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+
2026function traverseTypes ( current , fn ) {
21- if ( current instanceof protobuf . Type )
27+ if ( current instanceof protobuf . Type ) // and/or protobuf.Enum, protobuf.Service etc.
2228 fn ( current ) ;
2329 if ( current . nestedArray )
2430 current . nestedArray . forEach ( function ( nested ) {
2531 traverseTypes ( nested , fn ) ;
2632 } ) ;
2733}
2834
29- var root = protobuf . parse ( proto ) . root ;
30-
3135traverseTypes ( 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+ ) ;
3342} ) ;
You can’t perform that action at this time.
0 commit comments