gpt4 book ai didi

java - Apache Thrift 中 Java 的 int[] 和 i32 有什么区别

转载 作者:行者123 更新时间:2023-12-02 06:49:21 25 4
gpt4 key购买 nike

谁能帮我理解 int[] 之间的区别在 Java 中和 i32 ( NumericDataArray ) 在 Apache Thrift 中?什么时候应该使用后者?另外,我们有类似 i32 的东西吗?对于字符串?

最佳答案

来自Thrift Types

Base Types

The base types were selected with the goal of simplicity and clarity rather than abundance, focusing on the key types available in all programming languages.

bool: A boolean value (true or false)
byte: An 8-bit signed integer
i16: A 16-bit signed integer
i32: A 32-bit signed integer
i64: A 64-bit signed integer
double: A 64-bit floating point number
string: A text string encoded using UTF-8 encoding

所以i32是一个 32 位有符号整数,映射到 java int .

您在 thrift 中没有数组,但有容器类型:

Containers

Thrift containers are strongly typed containers that map to commonly used and commonly available container types in most programming languages.

There are three container types:

list: An ordered list of elements. Translates to an STL vector, Java ArrayList, native arrays in scripting languages, etc.

set: An unordered set of unique elements. Translates to an STL set, Java HashSet, set in Python, etc. Note: PHP does not support sets, so it is treated similar to a List

map: A map of strictly unique keys to values. Translates to an STL map, Java HashMap, PHP associative array, Python/Ruby dictionary, etc. While defaults are provided, the type mappings are not explicitly fixed. Custom code generator directives have been added to allow substitution of custom types in various destination languages.

Container elements may be of any valid Thrift Type.

这些容器映射到相应的 Java List , SetMap .

因此,如果您正在使用 thrift 并且需要传输 int 的集合-values,您将使用 int32 类型的列表容器喜欢 list<i32> ,这将导致 java.util.ArrayList<Integer>在java端。

无需担心String :有一个基本类型string在thrift中,它映射到java java.lang.String 。所以你只需定义一个 string节俭的话,你将拥有 java.lang.String在您生成的 java 代码中。

关于java - Apache Thrift 中 Java 的 int[] 和 i32 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18237626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com