文本内容
syntax = "proto3";
option csharp_namespace = "Protocol";;
option java_package = "com.fd.protocol.auto";
message RouterOuter {
enum RouteEnum {
none = 0;
// Request
game_ActorHandler_hello = 1; // 回显模块
game_AccountHandler_accountLogin = 2; // 注册和登录
// Event
game_ActorHandler_pushKickOff = 3; // 玩家被踢
}
}
需要匹配 game_ActorHandler_hello
和其数字值,注释:
\s*(\w*)\s*=\s*(\d*);\s*//\s(.*)
java
代码
/**
* 读取现有的路由文件内容.
*/
public void readFile(){
String content = FileUtil.readString(routeEnumPath, StandardCharsets.UTF_8);
Pattern pattern = Pattern.compile(routePattern);
Matcher matcher = pattern.matcher(content);
while (matcher.find()){
if ("none".equals(matcher.group(1))){
continue;
}
routeInfos.put(matcher.group(1),
new RouteInfo(matcher.group(1), Integer.parseInt(matcher.group(2)), matcher.group(3)));
}
log.debug("扫描路由: {}", JSON.toJSONString(routeInfos, SerializerFeature.PrettyFormat));
}