songjiachao commented on code in PR #323:
URL: https://github.com/apache/dubbo-js/pull/323#discussion_r1035842850


##########
packages/dubbo-serialization/src/proto.ts:
##########
@@ -0,0 +1,64 @@
+import fs from 'fs'
+import path from 'path'
+import _ from 'lodash'
+import { loadSync, Root, Type } from 'protobufjs'
+
+let _proto: Root | undefined = undefined
+
+/**
+ * 加载所有的proto文件
+ * @param dir 文件路径
+ * @returns Root namespace
+ */
+function loadProto(dir: string) {
+  const files = fs.readdirSync(dir)
+  // todo 优化成flatMap
+  const protoFiles = files
+    .filter((fileName) => fileName.endsWith('.proto'))
+    .map((fileName) => path.join(dir, fileName))
+  _proto = loadSync(protoFiles)
+  return _proto
+}
+
+/**
+ * 根据typeName寻找proto
+ * @param typeName
+ * @returns Reflected message type
+ */
+function lookup(typeName: string): Type {
+  if (!_.isString(typeName)) {
+    throw new TypeError('typeName must be a string')
+  }
+  if (!_proto) {

Review Comment:
   OK



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to