Slice

Slice (Specification Language for Ice)

Each Ice object has an interface with a number of operations. Interfaces, operations, and the types of data that are exchanged between client and server are defined using the Slice language. Slice allows you to define the client-server contract in a way that is independent of a specific programming language, such as C++, Java, or C#. The Slice definitions are compiled by a compiler into an API for a specific programming language, that is, the part of the API that is specific to the interfaces and types you have defined consists of generated code.

每个 Ice 对象都有一个包含许多操作的接口。 客户端和服务器之间交换的接口、操作和数据类型都是使用 Slice 语言定义的。 Slice 允许您以独立于特定编程语言(例如 C++、Java 或 C#)的方式定义客户端-服务器协定。 Slice 定义由编译器编译为特定编程语言的 API,即 API 中特定于您定义的接口和类型的部分由生成的代码组成。

The Slice Language

Slice (Specification Language for Ice) is the fundamental abstraction mechanism for separating object interfaces from their implementations. Slice establishes a contract between client and server that describes the interfaces, operations and parameter types used by an application. This description is independent of the implementation language, so it does not matter whether the client is written in the same language as the server.

Even though Slice is an acronym, it is pronounced as a single syllable, like a slice of bread.

Slice definitions are compiled for a particular implementation language by a compiler. The language-specific Slice compiler translates the language-independent Slice definitions into language-specific type definitions and APIs. These types and APIs are used by the developer to provide application functionality and to interact with Ice. The translation algorithms for various implementation languages are known as language mappings, and Ice provides a number of language mappings (for C++, C#, Java, JavaScript, Python and more).

Because Slice describes interfaces and types (but not implementations), it is a purely declarative language; there is no way to write executable statements in Slice.

Slice definitions focus on object interfaces, the operations supported by those interfaces, and exceptions that may be raised by operations. This requires quite a bit of supporting machinery; in particular, much of Slice is concerned with the definition of data types. This is because data can be exchanged between client and server only if their types are defined in Slice. You cannot exchange arbitrary C++ data between a client and a server because it would destroy the language independence of Ice. However, you can always create a Slice type definition that corresponds to the C++ data you want to send, and then you can transmit the Slice type.

We present the full syntax and semantics of Slice here. Because much of Slice is based on C++ and Java, we focus on those areas where Slice differs from C++ or Java or constrains the equivalent C++ or Java feature in some way. Slice features that are identical to C++ and Java are mentioned mostly by example.

Slice(Ice 规范语言)是将对象接口与其实现分离的基本抽象机制。 Slice 在客户端和服务器之间建立契约,描述应用程序使用的接口、操作和参数类型。 这种描述与实现语言无关,因此客户端是否与服务器使用相同的语言编写并不重要。

尽管 Slice 是一个缩写词,但它的发音是一个音节,就像一片面包一样。

Slice定义由编译器针对特定的实现语言进行编译。 特定于语言的 Slice 编译器将独立于语言的 Slice 定义转换为特定于语言的类型定义和 API。 开发人员使用这些类型和 API 来提供应用程序功能并与 Ice 进行交互。 各种实现语言的翻译算法称为语言映射,Ice 提供了多种语言映射(针对 C++、C#、Java、JavaScript、Python 等)。

因为 Slice 描述了接口和类型(但不描述实现),所以它是一种纯粹的声明性语言; 无法在 Slice 中编写可执行语句。

Slice定义重点关注对象接口、这些接口支持的操作以及操作可能引发的异常。 这需要相当多的配套机械; 特别是,Slice 的大部分内容都与数据类型的定义有关。 这是因为只有在 Slice 中定义了数据类型,客户端和服务器之间才能交换数据。 您不能在客户端和服务器之间交换任意 C++ 数据,因为这会破坏 Ice 的语言独立性。 但是,您始终可以创建与要发送的 C++ 数据相对应的 Slice 类型定义,然后就可以传输该 Slice 类型。

我们在这里展示 Slice 的完整语法和语义。 由于 Slice 的大部分内容都基于 C++ 和 Java,因此我们重点关注 Slice 与 C++ 或 Java 不同的领域,或者以某种方式限制等效的 C++ 或 Java 功能的领域。 与 C++ 和 Java 相同的 Slice 功能主要通过示例来提及。