1b3a3667创建于 2025年7月30日历史提交
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * This source file is part of the Cangjie project, licensed under Apache-2.0
 * with Runtime Library Exception.
 *
 * See https://cangjie-lang.cn/pages/LICENSE for license information.
 */

package stdx.net.http

public enum Protocol <: Equatable<Protocol> & ToString {
    | HTTP1_0 //HTTP/1.0
    | HTTP1_1 //HTTP/1.1
    | HTTP2_0 //HTTP/2.0
    | UnknownProtocol(String)

    static func fromString(str: String): Protocol {
        match (str) {
            case "HTTP/1.0" => HTTP1_0
            case "HTTP/1.1" => HTTP1_1
            case "HTTP/2.0" => HTTP2_0
            case _ => UnknownProtocol(str)
        }
    }

    public override func toString(): String {
        match (this) {
            case HTTP1_0 => return "HTTP/1.0"
            case HTTP1_1 => return "HTTP/1.1"
            case HTTP2_0 => return "HTTP/2.0"
            case UnknownProtocol(v) => return v
        }
    }

    public override operator func ==(that: Protocol): Bool {
        match ((this, that)) {
            case (HTTP1_0, HTTP1_0) => true
            case (HTTP1_1, HTTP1_1) => true
            case (HTTP2_0, HTTP2_0) => true
            case (UnknownProtocol(v1), UnknownProtocol(v2)) => v1 == v2
            case _ => false
        }
    }

    public override operator func !=(that: Protocol): Bool {
        return !(this == that)
    }
}