summaryrefslogtreecommitdiff
path: root/swift/src/Ice/UnknownSlicedValue.swift
blob: 1cec3095fad6e09d01454a8ab0e4d9a4b98c05df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

/// Unknown sliced value holds an instance of an unknown Slice class type.
public final class UnknownSlicedValue: Value {
    private let unknownTypeId: String
    private var slicedData: SlicedData?

    public required init() {
        unknownTypeId = ""
    }

    public init(unknownTypeId: String) {
        self.unknownTypeId = unknownTypeId
    }

    /// Returns the Slice type ID associated with this object.
    ///
    /// - returns: `String` - The type ID.
    public override func ice_id() -> String {
        return unknownTypeId
    }

    public override class func ice_staticId() -> String {
        return "::Ice::UnknownSlicedValue"
    }

    /// Returns the sliced data if the value has a preserved-slice base class and has been sliced during
    /// un-marshaling of the value, nil is returned otherwise.
    ///
    /// - returns: `Ice.SlicedData?` - The sliced data or nil.
    public override func ice_getSlicedData() -> SlicedData? {
        return slicedData
    }

    public override func _iceRead(from ins: InputStream) throws {
        ins.startValue()
        slicedData = try ins.endValue(preserve: true)
    }

    public override func _iceWrite(to os: OutputStream) {
        os.startValue(data: slicedData)
        os.endValue()
    }
}