Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Znav
nextRuby Mapping for Dictionaries
prevRuby Mapping for Structures

On this page:

Table of Contents
maxLevel3

Mapping Slice Sequences to Ruby Arrays

A Slice sequence maps to a Ruby array; the only exception is a sequence of bytes, which maps to a string. The use of a Ruby array means that the mapping does not generate a separate named type for a Slice sequence. It also means that you can take advantage of all the array functionality provided by Ruby. For example:

Wiki Markup
{zcode:slice}
sequence<Fruit> FruitPlatter;
{zcode}

We can use the FruitPlatter sequence as shown below:

Wiki Markup
{zcode:rb}
platter = [ Fruit::Apple, Fruit::Pear ]
platter.push(Fruit::Orange)
{zcode}

The Ice run time validates the elements of a sequence to ensure that they are compatible with the declared type; a TypeError exception is raised if an incompatible type is encountered.

Ztop

Mapping for Byte Sequences in Ruby

A Ruby string can contain arbitrary 8-bit binary data, therefore it is a more efficient representation of a byte sequence than a Ruby array in both memory utilization and throughput performance.

When receiving a byte sequence (as the result of an operation, as an out parameter, or as a member of a data structure), the value is always represented as a string. When sending a byte sequence as an operation parameter or data member, the Ice run time accepts both a string and an array of integers as legal values. For example, consider the following Slice definitions:

Wiki Markup
{zcode:slice}
// Slice
sequence<byte> Data;

interface I {
    void sendData(Data d);
    Data getData();
};
{zcode}

The interpreter session below uses these Slice definitions to demonstrate the mapping for a sequence of bytes:

Wiki Markup
{zcode:rb}
> proxy = ...
> proxy.sendData("\0\1\2\3")   # Send as a string
> proxy.sendData([0, 1, 2, 3]) # Send as an array
> d = proxy.getData()
> d.class
=> String
> d
=> "\000\001\002\003"
{zcode}

The two invocations of sendData are equivalent; however, the second invocation incurs additional overhead as the Ice run time must validate the type and range of each array element.

Ztop
See Also
Zret
Znav
nextRuby Mapping for Dictionaries
prevRuby Mapping for Structures