我需要我的代码帮助。我有两个结构,它们使用第三个。在
class Bar(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('first',univ.Integer().subtype(implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,0))),
namedtype.NamedType('second',univ.Integer().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
)
class Foo(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.OptionalNamedType('test', Bar().subtype(implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,3))),
)
class Foo1(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.OptionalNamedType('test', Bar().subtype(implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,2))),
)
因此,在Foo类中,Bar有一个标记[3],而在Foo1类中,例如[2]。我要是上一节课就好了
^{pr2}$在酒吧课上(而且很管用)。但我该如何应对这种问题呢? 任何帮助都将不胜感激。在
编辑: 以下是asn1表示:
Bar ::= SEQUENCE {
first [0] INTEGER,
second [1] INTEGER
}
Foo ::= SEQUENCE {
first [0] INTEGER,
second [1] INTEGER OPTIONAL,
third [2] INTEGER OPTIONAL,
bar [3] Bar
}
Foo1 ::= SEQUENCE {
first [0] INTEGER,
second [1] INTEGER OPTIONAL,
bar [2] Bar
}
代码:运行然后删除注释(我得到不兼容的标记。在这两种情况下,Bar中也没有tagSet):
from pyasn1.type import univ,namedtype,tag
class Bar(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('first',univ.Integer().subtype(implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,0))),
namedtype.NamedType('second',univ.Integer().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
)
tagSet = tagBaseSet = tag.initTagSet(tag.Tag(tag.tagClassContext,tag.tagFormatConstructed,3))
class Foo(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.OptionalNamedType('test', Bar().subtype(implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,3))),
)
class Foo1(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.OptionalNamedType('test', Bar().subtype(implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,2))),
)
bar = Bar()
bar.setComponentByName('first',1)
bar.setComponentByName('second',2)
fo = Foo()
fo.setComponentByName('test',bar)
# fo1 = Foo1()
# fo1.setComponentByName('test',bar)
print fo.prettyPrint()
# print fo1.prettyPrint()
目前没有回答
相关问题 更多 >
编程相关推荐