summaryrefslogtreecommitdiff
path: root/docs/source/pyasn1/type/namedval/contents.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/source/pyasn1/type/namedval/contents.rst')
-rw-r--r--docs/source/pyasn1/type/namedval/contents.rst43
1 files changed, 43 insertions, 0 deletions
diff --git a/docs/source/pyasn1/type/namedval/contents.rst b/docs/source/pyasn1/type/namedval/contents.rst
new file mode 100644
index 0000000..73f86c7
--- /dev/null
+++ b/docs/source/pyasn1/type/namedval/contents.rst
@@ -0,0 +1,43 @@
+
+.. _type.namedval:
+
+Enumerating numbers
+-------------------
+
+Some ASN.1 types such as :ref:`Integer <univ.Integer>`,
+:ref:`Enumerated <univ.Enumerated>` and :ref:`BitString <univ.BitString>`
+may enumerate their otherwise numeric values associating them with
+human-friendly labels.
+
+.. code-block:: python
+
+ class ErrorStatus(Integer):
+ """
+ ASN.1 specification:
+
+ error-status
+ INTEGER {
+ noError(0),
+ tooBig(1),
+ noSuchName(2),
+ ...
+ }
+ """
+ namedValues = NamedValues(
+ ('noError', 0), ('tooBig', 1), ('noSuchName', 2)
+ )
+
+The enumerated types behave exactly like the non-enumerated ones but,
+additionally, values can be referred by labels.
+
+.. code-block:: python
+
+ errorStatus = ErrorStatus('tooBig')
+
+ assert errorStatus == 1
+
+
+.. toctree::
+ :maxdepth: 2
+
+ /pyasn1/type/namedval/namedval