【问题标题】:difference between "enum" and "choice" type in ASN1ASN1中“enum”和“choice”类型的区别
【发布时间】:2020-11-05 10:33:57
【问题描述】:

有人可以解释一下在 ASN1 中何时使用“枚举”变量与何时使用“选择”变量?

【问题讨论】:

    标签: asn.1 lte 4g 3gp 5g


    【解决方案1】:

    ASN.1 中的 ENUMERATED 类型用于当您有一个您想从中选择的命名项目列表时使用,例如

    Colors ::= ENUMERATED {red, green, blue, yellow, purple}
    

    当您想在不同的 ASN.1 类型之间进行选择时,使用 CHOICE 类型。

    PreferredContactMethod ::= CHOICE {
      mail        PrintableString,
      mobilePhone NumericString,
      email       VisibleString,
      homephone   NumericString
    }
    

    一次只能选择选项中的一项。

    【讨论】:

      【解决方案2】:

      CHOICE 更丰富,因为替代品可以是您想要的任何类型。

      PreferredContactMethod ::= CHOICE {
        mail        PrintableString,
        identity    SEQUENCE { 
           firstName PrintableString,
           lastName PrintableString
        }
      }
      

      但是,你是对的。您可以使用 CHOICE 来定义枚举(也可以使用命名的 INTEGER)...

      Colors ::= ENUMERATED {red, green, blue, yellow, purple}
      
      Colors ::= INTEGER {red(0), green(1), blue(2), yellow(3), purple(4)}
      
      Colors ::= CHOICE {red NULL, green NULL, blue NULL, yellow NULL, purple NULL}
      

      我见过规范中使用的3种方式(注意编码会有所不同)

      我的 2 美分:如果您的类型显然是枚举,请使用 ENUMERATED

      【讨论】:

        猜你喜欢
        • 2015-09-17
        • 1970-01-01
        • 2021-11-27
        • 2019-03-26
        • 1970-01-01
        • 2013-09-15
        • 2013-05-18
        • 1970-01-01
        • 2012-12-09
        相关资源
        最近更新 更多