8. Serialization using the Basic Encoding Rules
8. Serialization using the Basic Encoding Rules
When an SNMP entity serializes an SNMP message, it uses the Basic Encoding Rules (BER) of ASN.1 [BER], with the following restrictions:
-
When encoding the length field, only the definite form is used. Use of the indefinite form is prohibited.
-
When encoding a value of type INTEGER, the restriction that the value be in the range -2^31 to 2^31-1 inclusive applies.
-
When encoding the value of a type Counter32, Counter64, or Gauge32, only non-negative values are used. The value is encoded as an INTEGER, but the restriction in item 2 does not apply.
-
When encoding a value of type TimeTicks, the restriction that the value be in the range 0 to 2^32-1 inclusive applies.
-
When encoding an OCTET STRING, the value is encoded using the primitive definite-length method.
The BER are very forgiving in terms of the encodings it will accept. For example, when decoding the length field, both the definite form and the indefinite form are accepted. In the interest of protocol simplicity and ease of implementation, all SNMP implementations MUST follow the restrictions defined in items 1 through 5 above when encoding values. This ensures that all receivers can decode values.
However, when decoding values, an SNMP implementation SHOULD accept values that are not compliant with the above restrictions. In the case of a non-compliant encoding, the SNMP implementation should interpret the value as best it can and continue with the message.