proto文件编译使用(java版)

1 maven插件方式

1.1 pom文件

		<os-maven-plugin.version>1.6.2</os-maven-plugin.version>
        <protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
        <com.google.protobuf.protoc.version>3.12.0</com.google.protobuf.protoc.version>
        <protoc-gen-grpc-java.plugin.version>1.32.1</protoc-gen-grpc-java.plugin.version>
        <grpc.version>1.32.1</grpc.version>
<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!--获取操作系统信息
                os.detected.name	操作系统名称	linux/windows/osx等
                os.detected.arch	操作系统架构	x86_32/x86_64/arm_32/aarch_64等
                os.detected.bitness	操作系统位数	32/64
                os.detected.version.*	操作系统版本相关	
                os.detected.classifier	操作系统名称和架构	${os.detected.name}-${os.detected.arch}
            -->
            <plugin>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>${os-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>detect</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>${protobuf-maven-plugin.version}</version>
                <configuration>
                    <protocArtifact>
                        com.google.protobuf:protoc:${com.google.protobuf.protoc.version}:exe:${os.detected.classifier}
                    </protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>
                        io.grpc:protoc-gen-grpc-java:${protoc-gen-grpc-java.plugin.version}:exe:${os.detected.classifier}
                    </pluginArtifact>
                </configuration>
                <executions>
                    <execution>
                        <id>grpc-build</id>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

2. 使用样例

在这里插入图片描述

2.1 proto文件

syntax = "proto3";

package demo.sw;

message DemoProto {
    string service = 1;
    // Service version in browser is the Instance concept in the backend.
    string serviceVersion = 2;
    // Perf data time, set by the backend side.
    int64 time = 3;
    // Page path in browser is the endpoint concept in the backend
    // Page path in the browser, mostly it is URI, without parameter
    string pagePath = 4;
    // Unit of all time related field should be `ms`.
    int32 redirectTime = 5;
    // DNS query time
    int32 dnsTime = 6;
    // Time to first Byte
    int32 ttfbTime = 7;
    //  TCP connection time
    int32 tcpTime = 8;
    // Content transfer time
    int32 transTime = 9;
    // Dom parsing time
    int32 domAnalysisTime = 10;
    // First paint time or blank screen time
    int32 fptTime = 11;
    // Dom ready time
    int32 domReadyTime = 12;
    // Page full load time
    int32 loadPageTime = 13;
    // Synchronous load resources in the page
    int32 resTime = 14;
    // Only valid for HTTPS
    int32 sslTime = 15;
    // Time to interact
    int32 ttlTime = 16;
    // First pack time
    int32 firstPackTime = 17;
    // First Meaningful Paint
    int32 fmpTime = 18;
}

2.2 idea编译

在这里插入图片描述
在这里插入图片描述

2.3 将生成文件目录加入Sources Root

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值