Dev1an / Swift-Atem

Blackmagic Design Atem network protocol implementation in swift 5.1 using NIO 2
MIT License
58 stars 27 forks source link

Missing public initializer for `Message.Title` #25

Open martinprot opened 10 months ago

martinprot commented 10 months ago

The public struct MessageTitle (renamed Message.Title on master) does not expose its init method publicly, preventing the developer to create new Atem Messages.

For example, here's the implementation of a VideoOutput command, driving the Atems video output.

public struct VideoOutput: Serializable {
    public enum Output {
        case in1
        case in2
        case in3
        case in4
        case multiview
        case program
        case preview
    }
    let output: Output

    public static var title = MessageTitle(string: "CAuS")

    public init(with bytes: ArraySlice<UInt8>) throws {
        throw AtemMessageError.notImplemented
    }

    public init(output: Output) {
        self.output = output
    }

    public var dataBytes: [UInt8] {
        return switch output {
        case .in1: [1, 0, 0, 1]
        case .in2: [1, 0, 0, 2]
        case .in3: [1, 0, 0, 3]
        case .in4: [1, 0, 0, 4]
        case .multiview: [1, 0, 35, 41]
        case .program: [1, 0, 39, 26]
        case .preview: [1, 0, 39, 27]
        }
    }

    public var debugDescription: String {
        return "Video output set to \(output)"
    }
}

Without the public MessageTitle init, the compiler produces the following error:

'MessageTitle' initializer is inaccessible due to 'internal' protection level

Adding a public MessageTitle initializer would make this possible.