feat(0): [java]-[wcferry-mvn]-1.maven插件中集成protobuf插件用于生成proto文

2.定义了proto配置序列化
This commit is contained in:
chandler 2024-09-22 19:22:13 +08:00
parent a486816f02
commit 6863a7f99c
5 changed files with 332 additions and 0 deletions

View File

@ -86,6 +86,7 @@ wcferry-mvn
│ │ │ └─WcferryApplication.java 启动类 │ │ │ └─WcferryApplication.java 启动类
│ │ │resources 数据库脚本 │ │ │resources 数据库脚本
│ │ │ ├─libs 本程序内置依赖包 │ │ │ ├─libs 本程序内置依赖包
│ │ │ ├─proto proto文件
│ │ │ ├─win32-x86-64 依赖程序 │ │ │ ├─win32-x86-64 依赖程序
│ │ │ ├─application.yml 本程序主配置文件 │ │ │ ├─application.yml 本程序主配置文件
│ │ │ └─logback-spring.xml 日志配置文件 │ │ │ └─logback-spring.xml 日志配置文件
@ -110,6 +111,13 @@ wcferry:
dll-path: /dll/sdk.dll dll-path: /dll/sdk.dll
``` ```
#### 生成proto文件
本程序已经集成了生成proto文件的maven插件直接install即可生成proto文件且会在打包程序中去除 src/main/resources/proto
下面的内容,只保留实体类中的文件
默认install会重新根据 生成实体,如果不想被替换,请删除 src/main/resources/proto 下对应的文件即可
### 提交规范 ### 提交规范
本模块希望大家使用统一提交格式,便于区分 本模块希望大家使用统一提交格式,便于区分

View File

@ -61,4 +61,54 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.5.0.Final</version>
</extension>
</extensions>
<!-- 同时添加maven插件用于编译protobuf生成java文件 -->
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<!-- 注意,需要与 com.google.protobuf:protobuf-java 一致 -->
<protocArtifact>
com.google.protobuf:protoc:3.22.2:exe:${os.detected.classifier}
</protocArtifact>
<!-- 默认值proto源文件路径 -->
<protoSourceRoot>${project.basedir}/src/main/resources/proto</protoSourceRoot>
<!-- 默认值proto目标java文件路径如果不指定则只在jar与编译中生成 -->
<outputDirectory>src/main/java</outputDirectory>
<pluginId>grpc-java</pluginId>
<!-- 设置是否在生成java文件之前清空outputDirectory的文件默认值为true设置为false时也会覆盖同名文件 -->
<clearOutputDirectory>false</clearOutputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<excludes>
<exclude>**/*.proto</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -0,0 +1,35 @@
package com.iamteer.config;
import java.util.Collections;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
/**
* 配置类-protobuf
*
* @author chandler
* @date 2024-09-26 21:35
*/
@Configuration
public class ProtobufConfig {
/**
* protobuf 序列化
*/
@Bean
ProtobufHttpMessageConverter protobufHttpMessageConverter() {
return new ProtobufHttpMessageConverter();
}
/**
* protobuf 反序列化
*/
@Bean
RestTemplate restTemplate(ProtobufHttpMessageConverter protobufHttpMessageConverter) {
return new RestTemplate(Collections.singletonList(protobufHttpMessageConverter));
}
}

View File

@ -0,0 +1,3 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

View File

@ -0,0 +1,236 @@
syntax = "proto3";
package wcf;
option java_package = "com.iamteer.entity";
enum Functions {
FUNC_RESERVED = 0x00;
FUNC_IS_LOGIN = 0x01;
FUNC_GET_SELF_WXID = 0x10;
FUNC_GET_MSG_TYPES = 0x11;
FUNC_GET_CONTACTS = 0x12;
FUNC_GET_DB_NAMES = 0x13;
FUNC_GET_DB_TABLES = 0x14;
FUNC_GET_USER_INFO = 0x15;
FUNC_GET_AUDIO_MSG = 0x16;
FUNC_SEND_TXT = 0x20;
FUNC_SEND_IMG = 0x21;
FUNC_SEND_FILE = 0x22;
FUNC_SEND_XML = 0x23;
FUNC_SEND_EMOTION = 0x24;
FUNC_SEND_RICH_TXT = 0x25;
FUNC_SEND_PAT_MSG = 0x26;
FUNC_FORWARD_MSG = 0x27;
FUNC_ENABLE_RECV_TXT = 0x30;
FUNC_DISABLE_RECV_TXT = 0x40;
FUNC_EXEC_DB_QUERY = 0x50;
FUNC_ACCEPT_FRIEND = 0x51;
FUNC_RECV_TRANSFER = 0x52;
FUNC_REFRESH_PYQ = 0x53;
FUNC_DOWNLOAD_ATTACH = 0x54;
FUNC_GET_CONTACT_INFO = 0x55;
FUNC_REVOKE_MSG = 0x56;
FUNC_REFRESH_QRCODE = 0x57;
FUNC_DECRYPT_IMAGE = 0x60;
FUNC_EXEC_OCR = 0x61;
FUNC_ADD_ROOM_MEMBERS = 0x70;
FUNC_DEL_ROOM_MEMBERS = 0x71;
FUNC_INV_ROOM_MEMBERS = 0x72;
}
message Request
{
Functions func = 1;
oneof msg
{
Empty empty = 2; //
string str = 3; //
TextMsg txt = 4; //
PathMsg file = 5; //
DbQuery query = 6; //
Verification v = 7; //
MemberMgmt m = 8; //
XmlMsg xml = 9; // XML参数结构
DecPath dec = 10; //
Transfer tf = 11; //
uint64 ui64 = 12 [ jstype = JS_STRING ]; // 64
bool flag = 13; //
AttachMsg att = 14; //
AudioMsg am = 15; //
RichText rt = 16; //
PatMsg pm = 17; //
ForwardMsg fm = 18; //
}
}
message Response
{
Functions func = 1;
oneof msg
{
int32 status = 2; // Int
string str = 3; //
WxMsg wxmsg = 4; //
MsgTypes types = 5; //
RpcContacts contacts = 6; //
DbNames dbs = 7; //
DbTables tables = 8; //
DbRows rows = 9; //
UserInfo ui = 10; //
OcrMsg ocr = 11; // OCR
};
}
message Empty { }
message WxMsg
{
bool is_self = 1; //
bool is_group = 2; //
uint64 id = 3 [ jstype = JS_STRING ]; // id
uint32 type = 4; //
uint32 ts = 5; //
string roomid = 6; // id
string content = 7; //
string sender = 8; //
string sign = 9; // Sign
string thumb = 10; //
string extra = 11; //
string xml = 12; // xml
}
message TextMsg
{
string msg = 1; //
string receiver = 2; // @
string aters = 3; // @
}
message PathMsg
{
string path = 1; //
string receiver = 2; //
}
message XmlMsg
{
string receiver = 1; //
string content = 2; // xml
string path = 3; //
int32 type = 4; //
}
message MsgTypes { map<int32, string> types = 1; }
message RpcContact
{
string wxid = 1; // id
string code = 2; //
string remark = 3; //
string name = 4; //
string country = 5; //
string province = 6; // /
string city = 7; //
int32 gender = 8; //
}
message RpcContacts { repeated RpcContact contacts = 1; }
message DbNames { repeated string names = 1; }
message DbTable
{
string name = 1; //
string sql = 2; // SQL
}
message DbTables { repeated DbTable tables = 1; }
message DbQuery
{
string db = 1; //
string sql = 2; // SQL
}
message DbField
{
int32 type = 1; //
string column = 2; //
bytes content = 3; //
}
message DbRow { repeated DbField fields = 1; }
message DbRows { repeated DbRow rows = 1; }
message Verification
{
string v3 = 1; //
string v4 = 2; // Ticket
int32 scene = 3; // 17 30
}
message MemberMgmt
{
string roomid = 1; // ID
string wxids = 2; //
}
message UserInfo
{
string wxid = 1; // ID
string name = 2; //
string mobile = 3; //
string home = 4; // /
}
message DecPath
{
string src = 1; //
string dst = 2; //
}
message Transfer
{
string wxid = 1; //
string tfid = 2; // id transferid
string taid = 3; // Transaction id
}
message AttachMsg
{
uint64 id = 1 [ jstype = JS_STRING ]; // id
string thumb = 2; // thumb
string extra = 3; // extra
}
message AudioMsg
{
uint64 id = 1 [ jstype = JS_STRING ]; // id
string dir = 2; //
}
message RichText
{
string name = 1; //
string account = 2; // id
string title = 3; //
string digest = 4; //
string url = 5; //
string thumburl = 6; //
string receiver = 7; //
}
message PatMsg
{
string roomid = 1; // id
string wxid = 2; // wxid
}
message OcrMsg
{
int32 status = 1; //
string result = 2; //
}
message ForwardMsg
{
uint64 id = 1 [ jstype = JS_STRING ]; // ID
string receiver = 2; // roomId wxid
}