Thursday, 12 April 2018

ASN.1: INTEGER : Represent integer values

Type: INTEGER
Description: It is used to represent integer values. It does not have any upper and lower limits, it can be of any magnitude.

Examples
id  INTEGER
age INTEGER (15..60)

In the second example, age is of type integer and the valid values are from 15 to 60.

Example Schema
Employee ::= SEQUENCE {
 firstName VisibleString,
 lastName VisibleString,
 isPermanentEmployee BOOLEAN,
 id INTEGER,
 age INTEGER (15..60)
}

Sample data for above schema
employee1 Employee ::= {
 firstName "Rama Krishna",
 lastName "Gurram",
 isPermanentEmployee FALSE,
 id 12345,
 age 30
}

XML encoding of above data
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <firstName>Rama Krishna</firstName>
  <lastName>Gurram</lastName>
  <isPermanentEmployee><false/></isPermanentEmployee>
  <id>12345</id>
  <age>30</age>
</Employee>

INTEGER type has also one possible notation, where you can name the possible values associated with this integer.

FavoriteColors ::= INTEGER {
  red    (0),
  green  (1),       
  yellow (2),
  blue   (3)
}


Example Schema
FavoriteColors ::= INTEGER {
  red    (0),
  green  (1), 
  yellow (2),
  blue   (3)
}

Person ::= SEQUENCE {
  firstName VisibleString,
  lastName VisibleString,
  favoriteColor FavoriteColors
}

Sample data for above schema

person Person ::= {
  firstName "Rama Krishna",
  lastName "Gurram",
  favoriteColor green
}

XML encoding of above data

<?xml version="1.0" encoding="UTF-8"?>
<Person>
  <firstName>Rama Krishna</firstName>
  <lastName>Gurram</lastName>
  <favoriteColor>1</favoriteColor>
</Person>


Previous                                                 Next                                                 Home

No comments:

Post a Comment