当前位置: 首页 > news >正文

Mac上protobuf环境构建-java

参考文献
getting-started
官网pb java介绍
maven protobuf插件
简单入门1
简单入门2

1. protoc编译器下载安装

https://github.com/protocolbuffers/protobuf/releases?page=10
在这里插入图片描述
放入.zshrc中配置环境变量

 ~/IdeaProjects/test2/ protoc --version
libprotoc 3.12.1
 ~/IdeaProjects/test2/ 
 ~/IdeaProjects/test2/ protoc -h       
Usage: protoc [OPTION] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:-IPATH, --proto_path=PATH   Specify the directory in which to search forimports.  May be specified multiple times;directories will be searched in order.  If notgiven, the current working directory is used.If not found in any of the these directories,the --descriptor_set_in descriptors will bechecked for required proto file.--version                   Show version info and exit.-h, --help                  Show this text and exit.--encode=MESSAGE_TYPE       Read a text-format message of the given typefrom standard input and write it in binaryto standard output.  The message type mustbe defined in PROTO_FILES or their imports.--decode=MESSAGE_TYPE       Read a binary message of the given type fromstandard input and write it in text formatto standard output.  The message type mustbe defined in PROTO_FILES or their imports.--decode_raw                Read an arbitrary protocol message fromstandard input and write the raw tag/valuepairs in text format to standard output.  NoPROTO_FILES should be given when using thisflag.--descriptor_set_in=FILES   Specifies a delimited list of FILESeach containing a FileDescriptorSet (aprotocol buffer defined in descriptor.proto).The FileDescriptor for each of the PROTO_FILESprovided will be loaded from theseFileDescriptorSets. If a FileDescriptorappears multiple times, the first occurrencewill be used.-oFILE,                     Writes a FileDescriptorSet (a protocol buffer,--descriptor_set_out=FILE defined in descriptor.proto) containing all ofthe input files to FILE.--include_imports           When using --descriptor_set_out, also includeall dependencies of the input files in theset, so that the set is self-contained.--include_source_info       When using --descriptor_set_out, do not stripSourceCodeInfo from the FileDescriptorProto.This results in vastly larger descriptors thatinclude information about the originallocation of each decl in the source file aswell as surrounding comments.--dependency_out=FILE       Write a dependency output file in the formatexpected by make. This writes the transitiveset of input file paths to FILE--error_format=FORMAT       Set the format in which to print errors.FORMAT may be 'gcc' (the default) or 'msvs'(Microsoft Visual Studio format).--print_free_field_numbers  Print the free field numbers of the messagesdefined in the given proto files. Groups sharethe same field number space with the parent message. Extension ranges are counted as occupied fields numbers.--plugin=EXECUTABLE         Specifies a plugin executable to use.Normally, protoc searches the PATH forplugins, but you may specify additionalexecutables not in the path using this flag.Additionally, EXECUTABLE may be of the formNAME=PATH, in which case the given plugin nameis mapped to the given executable even ifthe executable's own name differs.--cpp_out=OUT_DIR           Generate C++ header and source.--csharp_out=OUT_DIR        Generate C# source file.--java_out=OUT_DIR          Generate Java source file.--js_out=OUT_DIR            Generate JavaScript source.--objc_out=OUT_DIR          Generate Objective C header and source.--php_out=OUT_DIR           Generate PHP source file.--python_out=OUT_DIR        Generate Python source file.--ruby_out=OUT_DIR          Generate Ruby source file.@<filename>                 Read options and filenames from file. If arelative file path is specified, the filewill be searched in the working directory.The --proto_path option will not affect howthis argument file is searched. Content ofthe file will be expanded in the position of@<filename> as in the argument list. Notethat shell expansion is not applied to thecontent of the file (i.e., you cannot usequotes, wildcards, escapes, commands, etc.).Each line corresponds to a single argument,even if it contains spaces.
 ~/IdeaProjects/test2/ 

安装好上面的编译器就可以手动编译proto文件了,但是java程序员肯定是用maven项目的方式使用了,如何操作呢?下面介绍

2. demo项目构建

在这里插入图片描述

2.1 pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.tom</groupId><artifactId>lnacos</artifactId><version>1.0-SNAPSHOT</version><properties><os.detected.classifier>osx-x86_64</os.detected.classifier><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><!-- https://mvnrepository.com/artifact/com.alibaba.nacos/nacos-client --><dependencies><!-- https://mvnrepository.com/artifact/com.alibaba.nacos/nacos-client --><dependency><groupId>com.alibaba.nacos</groupId><artifactId>nacos-client</artifactId><version>1.1.4</version></dependency><dependency><groupId>com.google.protobuf</groupId><artifactId>protobuf-java</artifactId><version>3.12.1</version></dependency><dependency><groupId>com.google.protobuf</groupId><artifactId>protobuf-java-util</artifactId><version>3.12.1</version></dependency></dependencies><build><plugins><plugin><groupId>org.xolstice.maven.plugins</groupId><artifactId>protobuf-maven-plugin</artifactId><version>0.6.1</version><configuration><protocArtifact>com.google.protobuf:protoc:3.12.0:exe:${os.detected.classifier}</protocArtifact><pluginId>proto</pluginId><pluginArtifact>io.grpc:protoc-gen-grpc-java:1.32.1:exe:${os.detected.classifier}</pluginArtifact><protoSourceRoot>src/main/resources/proto3</protoSourceRoot><outputDirectory>src/main/java</outputDirectory><clearOutputDirectory>false</clearOutputDirectory></configuration><executions><execution><goals><goal>compile</goal><goal>test-compile</goal>
<!--                            <goal>compile-custom</goal>--></goals></execution></executions></plugin></plugins></build>
</project>

2.2 mvn clean complie 生成java文件

测试类LProto

package com.tom.model;import com.google.protobuf.util.JsonFormat;import java.util.Arrays;public class LProto {public static void main(String[] args) throws Exception{DemoModel.Demo.Builder builder = DemoModel.Demo.newBuilder();DemoModel.Demo build = builder.setId(123).setName("123").build();byte[] byteArray = build.toByteArray();System.out.println(Arrays.toString(byteArray));System.out.println(byteArray.length);String print = JsonFormat.printer().print(build);System.out.println(print);System.out.println(print.length());}
}
输出
[8, 123, 26, 3, 49, 50, 51]
7
{"id": 123,"name": "123"
}
32

可以看到使用pb压缩后的字段小了很多。

问题1-os.detected.classifier

在这里插入图片描述
增加配置

    <properties><os.detected.classifier>osx-x86_64</os.detected.classifier><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties>

相关文章:

Mac上protobuf环境构建-java

参考文献 getting-started 官网pb java介绍 maven protobuf插件 简单入门1 简单入门2 1. protoc编译器下载安装 https://github.com/protocolbuffers/protobuf/releases?page10 放入.zshrc中配置环境变量  ~/IdeaProjects/test2/ protoc --version libprotoc 3.12.1  …...

CocosCreator3.8研究笔记(二十二)CocosCreator 动画系统-动画剪辑和动画组件介绍

国庆假期&#xff0c;闲着没事&#xff0c;在家研究技术~ 大家都知道在Cocos Creator3.x 的版本的动画编辑器中&#xff0c;可以实现不用写一行代码就能实现各种动态效果。 Cocos Creator动画编辑器中主要实现关键帧动画&#xff0c;不仅支持位移、旋转、缩放、帧动画&#xff…...

信看课堂-厘米GNSS定位

我们常常说GPS 定位&#xff0c;不过定位远不止GPS定位&#xff0c;通过本节课程&#xff0c;我们将会了解到&#xff0c;原来GPS只是定位的一种&#xff1a; GNSS概述 不同的GNSS系统使用不同的频段来传输导航信号。以下是一些主要的GNSS系统及其相应的频段&#xff0c;用表…...

2023CCPC网络赛(A E)

2023CCPC网络赛(A E) The 2nd Universal Cup. Stage 3: Binjiang - Dashboard - Contest - Universal Cup Judging System A. Almost Prefix Concatenation 思路&#xff1a;首先考虑如何求出每个位置允许失配一次的LCP长度 &#xff0c; 可以二分哈希求LCP &#xff0c; 即…...

使用 python 检测泛洪攻击的案例

使用 python 检测泛洪攻击的案例 本案例只使用python标准库通过执行命令来监控异常请求, 并封锁IP, 不涉及其他第三方库工具. import os import time from collections import Counter# 1、update 命令, 采集CPU的平均负载 def get_cpu_load():"""uptime 命令…...

SCROLLINFO scrollInfo; 2023/10/5 下午3:38:53

2023/10/5 下午3:38:53 SCROLLINFO scrollInfo;scrollInfo.cbSize = sizeof(SCROLLINFO);scrollInfo.fMask = SIF_ALL;//scrollInfo.nMin = 0; // 最小位置//scrollInfo.nMax = nRowCountToShow; // 最大位置//scrollInfo.nPage = nRowCountToShow; // 页面大小//scrollInf…...

Python--控制台获取输入与正则表达式

前言一、控制台获取输入1.1 字符串输入1.2 整数输入1.3 浮点数输入1.4 布尔值输入1.5 列表输入1.6 汇总 二、正则表达式2.1 匹配数字2.2 模式检查2.3 替换字符2.4 切分字符串2.5 搜索并提取匹配的部分2.6 使用捕获组提取匹配的部分2.7 非贪婪匹配2.8 忽略大小写匹配2.9 使用预定…...

网络基础知识面试题1

VC++常用功能开发汇总(专栏文章列表,欢迎订阅,持续更新...)https://blog.csdn.net/chenlycly/article/details/124272585C++软件异常排查从入门到精通系列教程(专栏文章列表,欢迎订阅,持续更新...)...

JavaScript系列从入门到精通系列第十五篇:JavaScript中函数的实参介绍返回值介绍以及函数的立即执行

文章目录 一&#xff1a;函数的参数 1&#xff1a;形参如何定义 2&#xff1a;形参的使用规则 二&#xff1a;函数的返回值 1&#xff1a;函数返回值如何定义 2&#xff1a;函数返回值种类 三&#xff1a;实参的任意性 1&#xff1a;方法可以作为实参 2&#xff1a;将匿…...

js中的原型链

编写思路&#xff1a; 简单介绍构造函数介绍原型对象原型对象、实例的关系&#xff0c;从而引出原型链的基本概念 原型链基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法。 1. 什么是构造函数 构造函数本身跟普通函数一样&#xff0c;也不存在定义构造函数…...

一文搞懂APT攻击

APT攻击 1. 基本概念2. APT的攻击阶段3. APT的典型案例参考 1. 基本概念 高级持续性威胁&#xff08;APT&#xff0c;Advanced Persistent Threat&#xff09;&#xff0c;又叫高级长期威胁&#xff0c;是一种复杂的、持续的网络攻击&#xff0c;包含高级、长期、威胁三个要素…...

在pandas中通过一列数据映射出另一列的几种思路和方法

如果一句话中出现某个品牌的关键词&#xff0c;那么就将该品牌进行提取&#xff0c;开始我的做法是写了很多elif&#xff0c;如下&#xff1a; def brand_describe(x):if TRUM in x.upper():return "通快"elif BYSTRONIC in x.upper():return "百超"elif …...

数据分析视角中的商业分析学习笔记

数据分析一大堆&#xff0c;结果却是大家早就知道的结论&#xff1f;是工具和方法出问题了吗&#xff1f;真正原因可能是你的思维有误区。 为什么分析的这么辛苦&#xff0c;得出的结论大家早知道&#xff0c;谁谁都不满意&#xff1f;核心原因有3个&#xff1a; 分析之前&am…...

剑指offer——JZ26 树的子结构 解题思路与具体代码【C++】

一、题目描述与要求 树的子结构_牛客题霸_牛客网 (nowcoder.com) 题目描述 输入两棵二叉树A&#xff0c;B&#xff0c;判断B是不是A的子结构。&#xff08;我们约定空树不是任意一个树的子结构&#xff09; 假如给定A为{8,8,7,9,2,#,#,#,#,4,7}&#xff0c;B为{8,9,2}&…...

NEFU数字图像处理(1)绪论

一、简介 1.1什么是数字图像 图像是三维场景在二维平面上的影像。根据其存储方式和表现形式&#xff0c;可以将图像分为模拟图像和数字图像两大类 图像处理方法&#xff1a;光学方法、电子学方法 模拟图像&#xff1a;连续的图像数字图像&#xff1a;通过对时间上和数值上连续…...

数值分析学习笔记——绪论【华科B站教程版本】

绪论 数值分析概念 用计算机求解数学问题的数值方法和理论 三大科学研究方法 实验理论分析科学计算&#xff08;用计算机去辅助研究&#xff09;&#xff1a;数值方法计算机 解析解和近似解 解析解&#xff1a;使用数学方法求出或推导出的结果&#xff0c;往往可以求解出…...

节日灯饰灯串灯出口欧洲CE认证办理

灯串&#xff08;灯带&#xff09;&#xff0c;这个产品的形状就象一根带子一样&#xff0c;再加上产品的主要原件就是LED&#xff0c;因此叫做灯串或者灯带。2022年&#xff0c;我国灯具及相关配件产品出口总额超过460亿美元。其中北美是最大的出口市场。其次是欧洲市场&#…...

一线大厂Redis高并发缓存架构实战与性能优化

文章目录 一、redis主从架构锁失效问题分析二、从CAP角度剖析redis与zookeeper分布式锁区别三、redlock分布式锁原理与存在的问题分析四、大促场景如何将分布式锁性能提升100倍五、高并发redis架构代码实战 一、redis主从架构锁失效问题分析 我们都知道&#xff0c;一般的互联…...

PHP 行事准则:allow_url_fopen 与 allow_url_include

文章目录 参考环境allow_url_fopenallow_url_fopen 配置项操作远程文件file 协议 allow_url_includeallow_url_include 配置项 allow_url_include 与 allow_url_fopen区别联系默认配置配置项关闭所导致异常运行时配置ini_set()限制 参考 项目描述搜索引擎Bing、GoogleAI 大模型…...

Replicate + ngrok云端大模型API实现教程

ChatGPT 的诞生预示着人工智能和机器学习领域的新时代。 日新月异&#xff0c;Hugging Face 不断推出突破性的语言模型&#xff0c;重新定义人机交互的界限。欢迎来到未来&#xff01; 当然&#xff0c;有很多选项可以对它们进行推断。在本文中&#xff0c;我将告诉大家如何使…...

Arm CoreLink CMN-600硬件错误解析与解决方案

1. Arm CoreLink CMN-600硬件错误深度解析在复杂SoC设计中&#xff0c;互连架构的质量直接决定整个系统的稳定性和性能。作为Arm Neoverse平台的核心组件&#xff0c;CoreLink CMN-600&#xff08;Coherent Mesh Network&#xff09;承担着处理器集群、内存控制器和I/O设备之间…...

InferenceX:大模型高效推理引擎核心原理与生产部署实战

1. 项目概述&#xff1a;从模型训练到高效推理的最后一公里如果你在AI领域&#xff0c;特别是大模型应用开发上投入过精力&#xff0c;那么对“InferenceX”这个名字可能不会感到陌生。它不是一个全新的训练框架&#xff0c;也不是一个模型仓库&#xff0c;而是精准地瞄准了当前…...

从零手写CNN:理解卷积网络的生物学原理与工程逻辑

1. 项目概述&#xff1a;从人眼到机器之眼&#xff0c;一次真实的视觉理解之旅你有没有盯着一张照片发过呆&#xff1f;比如朋友刚发来的旅行照——蓝天、雪山、一只歪头的雪豹。你几乎是一瞬间就认出了“雪豹”&#xff0c;甚至能判断它“在看镜头”“毛很厚”“可能刚睡醒”。…...

跨平台文件自由:Free-NTFS-for-Mac 终极解决方案深度解析

跨平台文件自由&#xff1a;Free-NTFS-for-Mac 终极解决方案深度解析 【免费下载链接】Free-NTFS-for-Mac Nigate: An open-source NTFS utility for Mac. It supports all Mac models (Intel and Apple Silicon), providing full read-write access, mounting, and management…...

Vivado里配置RFSoC数据转换器IP,这10个参数新手最容易搞错(附PG269避坑指南)

Vivado中RFSoC数据转换器IP配置的10个关键参数解析与实战避坑指南 第一次在Vivado中配置RFSoC的数据转换器IP核时&#xff0c;面对密密麻麻的参数选项&#xff0c;即使是经验丰富的FPGA工程师也可能感到无从下手。RFSoC作为集成了高速数据转换器的异构计算平台&#xff0c;其配…...

WarcraftHelper 2024:魔兽争霸3终极优化指南

WarcraftHelper 2024&#xff1a;魔兽争霸3终极优化指南 【免费下载链接】WarcraftHelper Warcraft III Helper , support 1.20e, 1.24e, 1.26a, 1.27a, 1.27b 项目地址: https://gitcode.com/gh_mirrors/wa/WarcraftHelper 还在为《魔兽争霸3》在现代电脑上运行卡顿、画…...

SkillPilot:AI编程助手技能一键管理与安全部署实战

1. 项目概述与核心价值最近在折腾AI编程助手的时候&#xff0c;发现了一个挺有意思的痛点&#xff1a;虽然Claude Code、Cursor这些工具都支持通过SKILL.md文件来扩展功能&#xff0c;但每次想找个新技能&#xff0c;都得手动去GitHub上翻找、下载、配置&#xff0c;还得担心代…...

别再为Matlab App打包发愁了!手把手教你从Web部署到桌面应用(含Runtime安装避坑)

从零到一&#xff1a;Matlab App Designer全流程打包实战指南 第一次尝试将Matlab App Designer开发的应用程序打包成可执行文件时&#xff0c;那种既期待又忐忑的心情相信很多开发者都深有体会。作为一款强大的交互式开发环境&#xff0c;Matlab App Designer让图形用户界面(G…...

JavaScript零基础到精通

&#x1f4da; 教程定位与目标 本教程专为‌零基础学习者‌设计&#xff0c;覆盖从‌语法入门‌到‌现代JavaScript精通‌的完整路径&#xff0c;内容严格遵循‌ES2026标准‌&#xff0c;融合‌MDN、freeCodeCamp、W3Schools‌权威结构&#xff0c;并适配‌中文学习者习惯‌。…...

微信小程序二维码生成神器:5分钟搞定前端二维码生成

微信小程序二维码生成神器&#xff1a;5分钟搞定前端二维码生成 【免费下载链接】weapp-qrcode weapp.qrcode.js 在 微信小程序 中&#xff0c;快速生成二维码 项目地址: https://gitcode.com/gh_mirrors/we/weapp-qrcode 还在为微信小程序中的二维码功能而烦恼吗&#…...