Skip to content

Commit

Permalink
Merge pull request #9 from dcvmoole/fixed-length-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm authored Nov 2, 2024
2 parents e470a8f + 99eae42 commit 97ada75
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 30 deletions.
17 changes: 16 additions & 1 deletion pysmi/codegen/intermediate.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,22 @@ def gen_octetstring_subtype(self, data):
size["max"] = vmax
sizes.append(size)

return {"size": sizes}
outDict = {"size": sizes}

# If the union of ranges consists of a single size, then store that
# information as well, so that pysnmp (which needs to know) does not
# have to compute it itself. We take a slightly elaborate approach so
# that strange ranges such as SIZE(4 | 4) also produce a fixed size.
#
# Note that as per RFC 2578 Sec. 9 point (3), derived types may only
# ever reduce the ranges of their base types, so we never need to
# override a base type's fixed length to be "non-fixed" again.
minSize = min(size["min"] for size in sizes)
maxSize = max(size["max"] for size in sizes)
if minSize == maxSize:
outDict["fixed"] = minSize

return outDict

# noinspection PyUnusedLocal
def gen_oid(self, data):
Expand Down
3 changes: 3 additions & 0 deletions pysmi/codegen/templates/pysnmp/mib-definitions.j2
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ if mibBuilder.loadTexts:
ValueSizeConstraint({{ range['min'] }}, {{ range['max'] }}),
{% endfor %}
)
{% if 'fixed' in spec %}
fixedLength = {{ spec['fixed'] }}
{% endif %}
{% endif %}
{% endmacro -%}

Expand Down
Loading

0 comments on commit 97ada75

Please sign in to comment.