Basic Types

Basic Types

Built-In Basic Types
Slice provides a number of built-in basic types, as shown in this table:

内置基本类型
Slice 提供了许多内置的基本类型,如下表所示:

Type Range of Mapped Type Size of Mapped Type
bool false or true ≥ 1bit
byte -128-127 or 0-255 ≥ 8 bits
short -2^15 to 2^15 -1 ≥ 16 bits
int -2^31 to 2^31 -1 ≥ 32 bits
long -2^63 to 2^63 -1 ≥ 64 bits
float IEEE single-precision ≥ 32 bits
double IEEE double-precision ≥ 64 bits
string All Unicode characters Variable-length

The range depends on whether byte maps to a signed or an unsigned type.

范围取决于字节映射到有符号类型还是无符号类型。

All the basic types (except byte) are subject to changes in representation as they are transmitted between clients and servers. For example, a long value is byte-swapped when sent from a little-endian to a big-endian machine. However, these changes are transparent to the programmer and do exactly what is required.

所有基本类型(字节除外)在客户端和服务器之间传输时都会发生表示形式的变化。 例如,长值在从小端机器发送到大端机器时会进行字节交换。 然而,这些更改对程序员来说是透明的,并且完全按照要求进行。

Integer Types

Slice provides integer types short, int, and long, with 16-bit, 32-bit, and 64-bit ranges, respectively. Note that, on some architectures, any of these types may be mapped to a native type that is wider. Also note that no unsigned types are provided. (This choice was made because unsigned types are difficult to map into languages without native unsigned types, such as Java. In addition, the unsigned integers add little value to a language.

Slice 提供整数类型short、int 和long,分别具有16 位、32 位和64 位范围。 请注意,在某些体系结构上,这些类型中的任何一个都可以映射到更宽的本机类型。 另请注意,不提供无符号类型。 (做出这个选择是因为无符号类型很难映射到没有本机无符号类型的语言,例如 Java。此外,无符号整数对语言几乎没有增加价值。

Floating-Point Types

These types follow the IEEE specification for single- and double-precision floating-point representation [1]. If an implementation cannot support IEEE format floating-point values, the Ice run time converts values into the native floating-point representation (possibly at a loss of precision or even magnitude, depending on the capabilities of the native floating-point format).

这些类型遵循单精度和双精度浮点表示的 IEEE 规范 [1]。 如果实现无法支持 IEEE 格式浮点值,Ice run time 会将值转换为本机浮点表示形式(可能会损失精度甚至幅度,具体取决于本机浮点格式的功能)。

Strings

Slice strings use the Unicode character set and are encoded using UTF-8 when transmitted between clients and servers.

Slice字符串使用 Unicode 字符集,并在客户端和服务器之间传输时使用 UTF-8 进行编码。

Booleans

Boolean values can have only the values false and true. Language mappings use the corresponding native boolean type if one is available.

布尔值只能有 false 和 true 值。 语言映射使用相应的本机布尔类型(如果可用)。

Bytes

The Slice type byte is an (at least) 8-bit type that is guaranteed not to undergo any changes in representation as it is transmitted between address spaces. This guarantee permits exchange of binary data such that it is not tampered with in transit. All other Slice types are subject to changes in representation during transmission.

Slice 类型字节是(至少)8 位类型,保证在地址空间之间传输时不会发生任何表示形式的变化。 此保证允许交换二进制数据,使其在传输过程中不会被篡改。 所有其他切片类型在传输过程中的表示形式都会发生变化。