Interfaces can be marshaled by value. For an interface marshaled by value (as opposed to a class instance derived from that interface), only the type ID of the most-derived interface is encoded. We use the following Slice definitions in our discussion:
interface Base { /* ... */ } interface Derived extends Base { /* ... */ } interface Example { void doSomething(Base b); }
We assume that the client passes a class instance to doSomething
that does not have a Slice definition (but implements Derived
).
Interface Encoding version 1.0
The on-the-wire representation of the interface parameter using encoding version 1.0 is as follows:
Marshaled Value | Size in Bytes | Type | Byte offset |
---|---|---|---|
| 4 |
| 0 |
| 1 |
| 4 |
| 10 |
| 5 |
| 4 |
| 15 |
| 1 |
| 19 |
| 14 |
| 20 |
| 4 |
| 34 |
| 1 |
| 38 |
Interface Encoding version 1.1
With encoding version 1.1, the interface parameter is encoded as if it was a class with no data members. Here is the on-the-wire representation using the sliced format:
Marshaled value | Size in bytes | Type | Byte offset |
---|---|---|---|
| 1 |
| 0 |
| 1 |
| 1 |
| 10 |
| 2 |
| 4 |
| 12 |
The compact format omits the byte count for the slice:
Marshaled value | Size in bytes | Type | Byte offset |
---|---|---|---|
| 1 |
| 0 |
| 1 |
| 1 |
| 10 |
| 2 |