INTEGER

The ASN.1 INTEGER type is converted into one of several XSD built-in types depending on value range constraints on the integer type definition.

The default conversion if the INTEGER value contains no constraints is to the XSD integer type:

ASN.1 production:

   TypeName ::= INTEGER

Generated XSD code:

   <xsd:simpleType name="TypeName">
      <xsd:restriction base="xsd:integer"/>
   </xsd:simpleType>

If the integer has a value range constraint that allows a more restrictive XSD type to be used, then that type will be used. For example, if a range of 0 to 255 (inclusive) is specified, an XSD unsignedByte would be used because it maps exactly to this range. The following table shows the range values for each of the INTEGER type mappings

Lower Bound Upper Bound XSD Type
-128 127 byte
0 255 unsignedByte
-32768 32767 short
0 65535 unsignedShort
-2147483648 2147483647 integer
0 4294967295 unsignedInt
-9223372036854775808 9223372036854775807 long
0 18446744073709551615 unsignedLong

Ranges beyond "long" or "unsignedLong" will cause the integer value to be treated as a "big integer". This will map to an xsd:string type. An integer can also be specified to be a big integer using the ASN1C <isBigInteger/> configuration file setting.

If constraints are present on the INTEGER type that are not exactly equal to the lower and upper bounds specified above, then xsd:minInclusive and xsd:maxInclusive facets will be added to the XSD type mapping. For example, the mapping of "I ::= INTEGER (0..10)" would be done as follows:

  1. The most restrictive type would first be chosen based on the constraints. In this case, xsd:byte would be used because it appears first on the list above.

  2. Then the xsd:minInclusive and xsd:maxInclusive facets would be added to further restrict the type.

This would result in the following mapping

   <xsd:simpleType name="I">
      <xsd:restriction base="xsd:byte">
         <xsd:minInclusive value="0">
         <xsd:maxInclusive value="10">
      </xsd:restriction>
   </xsd:simpleType>