我试图将一个协议缓冲区消息导入另一个,但无法识别导入。只要我不尝试将一个 protobuf 导入另一个,就会生成 protobuf 代码(在 Java 中),代码会按预期编译和运行。
我正在使用:
我的 gradle 构建文件如下所示:
plugins {
id 'java'
id 'com.google.protobuf' version "0.8.8"
}
group 'tech.tablesaw'
version '1.0-SNAPSHOT'
sourceCompatibility = 9.0
def grpcVersion = '1.30.1' // CURRENT_GRPC_VERSION
def protobufVersion = '3.12.0'
def protocVersion = protobufVersion
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
dependencies {
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
// advanced - need this for JsonFormat
implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
testImplementation …Run Code Online (Sandbox Code Playgroud) 对于这个看似简单的问题,我找不到明确的答案。如果我写一个这样的方法:
public Integer getAnInt() {
int[] i = {4};
return i[0];
}
Run Code Online (Sandbox Code Playgroud)
返回值是否自动装箱为 Integer,还是取决于返回值后发生的情况(例如,分配给它的变量是否被声明为 Integer 或 int)?
我正在研究一个不断处理千兆字节数据的程序,主要是基元和字符串.我需要避免通过自动装箱将原语转换为对象,因为这会爆炸堆大小和GC时间.
目前,我在VisualVM中进行更改并运行代码,看看我有数百万个额外的整数或短片或对象.然后我将调试器中的代码单步执行到我的库和JDK类中,以找到装箱发生的位置.有工具来帮助解决这个问题吗?
我使用Intellij作为我的IDE.在Intellij中,您可以使用检查在您自己的代码中查找自动装箱,但它似乎不会扩展到库代码.为此,请从菜单中选择:
Analyzye >>按名称运行检查...
然后在提示符下键入"auto".应出现自动装箱检查以供选择.
但是,在这一点上,我已经从我自己的代码中删除了基本上所有的自动装箱.我需要的是能够找出当我将原语传递给库方法时,库代码是否在任何时刻自动装箱基元.
例如:给出这个json文档:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
Run Code Online (Sandbox Code Playgroud)
我想生产(类似)这个输出:
store.book.category: "reference"
store.book.author: "Nigel Rees"
store.book.title: "Sayings of the Century"
store.book.price: 8.95
store.book.category: "fiction"
store.book.author: "Herman Melville"
store.book.title: "Moby Dick"
store.book.isbn: "0-553-21311-3"
store.book.price: 8.99
store.bicycle.color: "red"
store.bicycle.price: 19.95
expensive:10
Run Code Online (Sandbox Code Playgroud)
我宁愿选择一个基于强大的json库(gson,jackson等)之一的有效解决方案,而不是使用原始文本.
官方航空公司的出发和到达时间通常以小时和分钟提供.以下是典型示例:
1830 - 6:30 pm
730 - 7:30 am
30 - 30 minutes after midnight (ie 12:30 am)
Run Code Online (Sandbox Code Playgroud)
前两个可以使用带有HHmm和Hmm的DateTimeFormatter进行解析.第三个导致解析错误,并且尝试仅用几分钟(mm)解析它会导致不同的错误:无法从TemporalAccessor获取LocalTime:{MinuteOfHour = 30}
约束:
我想提供一个通用的解决方案,如果可能的话,使用格式化器处理这个问题,因为我不想破解所有其他时间变量的解析.
显然我可以预处理传入的数据以预先缺少零,但我有很多GB的数据,并希望避免额外的传递.
谢谢你的帮助.
更新:一个明显的解决方案是在同一个传递中添加零.例如,使用Guava:
stringValue = Strings.padStart(stringValue, 4, '0');
LocalTime.parse(stringValue, TypeUtils.timeFormatter);
Run Code Online (Sandbox Code Playgroud)
仍然很好奇是否有办法只使用标准的格式代码,如hh和mm.
我有一个字节流,返回一个字节数组序列,每个字节数组代表一个记录.
我想将流解析为单个byte []的列表.目前,我已经入侵了一个三字节分隔符,以便我可以识别每条记录的结尾,但是有疑虑.
我看到有一个标准的Ascii记录分隔符.
30 036 1E 00011110 RS  Record Separator
Run Code Online (Sandbox Code Playgroud)
如果字节数组(UTF-8编码)已被压缩和/或加密,使用从该字符派生的byte []是否安全?我担心的是加密/压缩输出可能会出于某种其他目的而产生记录分隔符.请注意,单个byte []记录是压缩/加密的,而不是整个流.
我正在使用Java 8并使用Snappy进行压缩.我还没有选择加密库,但它肯定是更强大,标准的私钥方法之一.
我正在将贡献.md 文件从项目根移动到 docs/ 目录,以便它可以与文档的其余部分一起使用。在 github 页面中查看时,文档中的其他 Markdown 文件可以正确呈现。例如,页面
https://jtablesaw.github.io/tablesaw/userguide/toc 按预期呈现页面 toc.md。
然而,
https://jtablesaw.github.io/tablesaw/contributing
返回 404,同时只需添加 .md 扩展名
https://jtablesaw.github.io/tablesaw/contributing.md
返回页面作为 Markdown 源
github 项目是https://github.com/jtablesaw/tablesaw。贡献的.md 文件位于 docs/ 文件夹中。
我正在尝试使用Caffeine创建一个简单(非加载)缓存.
Cache<String, MyObject> countsCache =
CacheBuilder.newBuilder().build();
Run Code Online (Sandbox Code Playgroud)
无法编译,报告错误:
Error:(42, 31) java: incompatible types:
no instance(s) of type variable(s) K1,V1 exist so that org.elasticsearch.common.cache.Cache<K1,V1> conforms to com.github.benmanes.caffeine.cache.Cache<java.lang.String,com.foo.bar.MyObject>
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激.
在 ANSI SQL(或重要的实现)中连接浮点列是否合法?
我确信这通常不是一个好主意,但我正在开发一个 API,并寻求 SQL 的指导来确定是否应该阻止它,或者留给开发人员选择。
如果合法,您是否可以选择指定在比较中使用的精度?