示例#1
0
def context_encode(tag):
    """Encode the object into a tag, encode it in a PDU, return the data."""
    if _debug: context_encode._debug("context_encode %r", tag)

    data = PDUData()
    tag.encode(data)
    return data.pduData
示例#2
0
    def test_tag(self):
        if _debug: TestTag._debug("test_tag")

        # test tag construction
        tag = Tag()
        assert (tag.tagClass, tag.tagNumber) == (None, None)

        # must have a valid encoded tag to extract from the data
        data = PDUData(xtob(''))
        with self.assertRaises(DecodingError):
            tag = Tag(data)

        # must have two values, class and number
        with self.assertRaises(ValueError):
            tag = Tag(0)

        tag = Tag(0, 1)
        assert (tag.tagClass, tag.tagNumber) == (0, 1)

        tag = Tag(0, 1, 2)
        assert (tag.tagClass, tag.tagNumber, tag.tagLVT) == (0, 1, 2)

        # tag data must be bytes or bytearray
        with self.assertRaises(TypeError):
            tag = Tag(0, 1, 2, 3)
示例#3
0
def context_decode(blob):
    """Build PDU from the string, decode the tag, convert to an object."""
    if _debug: context_decode._debug("context_decode %r", blob)

    data = PDUData(blob)
    tag = ContextTag(data)
    return tag
示例#4
0
def opening_decode(blob):
    """Build PDU from the string, decode the tag, convert to an object."""
    if _debug: opening_decode._debug("opening_decode %r", blob)

    data = PDUData(blob)
    tag = OpeningTag(data)
    return tag
示例#5
0
def obj_decode(blob):
    """Build PDU from the string, decode the tag, convert to an object."""
    if _debug: obj_decode._debug("obj_decode %r", blob)

    data = PDUData(blob)
    tag = Tag(data)
    obj = tag.app_to_object()
    return obj
示例#6
0
def obj_encode(obj):
    """Encode the object into a tag, encode it in a PDU, return the data."""
    if _debug: obj_encode._debug("obj_encode %r", obj)

    tag = Tag()
    obj.encode(tag)
    data = PDUData()
    tag.encode(data)
    return data.pduData
示例#7
0
    def bvlpdu_contents(self, use_dict=None, as_class=dict):
        """Return the contents of an object as a dict."""

        # make/extend the dictionary of content
        if use_dict is None:
            use_dict = as_class()

        # call the normal procedure
        key_value_contents(use_dict=use_dict, as_class=as_class,
            key_values=(
                ('function', 'OriginalBroadcastNPDU'),
                ('address', self.bvlciAddress),
            ))

        # this message has data
        PDUData.dict_contents(self, use_dict=use_dict, as_class=as_class)

        # return what we built/updated
        return use_dict
示例#8
0
    def test_endec_0(self):
        """Test empty tag list encoding and decoding.
        """
        if _debug: TestTagList._debug("test_endec_0")

        taglist = TagList([])

        data = PDUData()
        taglist.encode(data)
        assert data.pduData == xtob('')

        taglist = TagList()
        taglist.decode(data)
        assert taglist.tagList == []
示例#9
0
    def test_endec_3(self):
        """Test bracketed application tagged integer encoding and decoding."""
        if _debug: TestTagList._debug("test_endec_2")

        tag0 = OpeningTag(0)
        tag1 = IntegerTag(0x0102)
        tag2 = ClosingTag(0)
        taglist = TagList([tag0, tag1, tag2])

        data = PDUData()
        taglist.encode(data)
        assert data.pduData == xtob('0E3201020F')

        taglist = TagList()
        taglist.decode(data)
        assert taglist.tagList == [tag0, tag1, tag2]
示例#10
0
    def test_endec_2(self):
        """Test short tag list encoding and decoding, context tags.
        """
        if _debug: TestTagList._debug("test_endec_2")

        tag0 = ContextTag(0, xtob('00'))
        tag1 = ContextTag(1, xtob('01'))
        taglist = TagList([tag0, tag1])

        data = PDUData()
        taglist.encode(data)
        assert data.pduData == xtob('09001901')

        taglist = TagList()
        taglist.decode(data)
        assert taglist.tagList == [tag0, tag1]
示例#11
0
    def test_endec_1(self):
        """Test short tag list encoding and decoding, application tags.
        """
        if _debug: TestTagList._debug("test_endec_1")

        tag0 = IntegerTag(0x00)
        tag1 = IntegerTag(0x01)
        taglist = TagList([tag0, tag1])

        data = PDUData()
        taglist.encode(data)
        assert data.pduData == xtob('31003101')

        taglist = TagList()
        taglist.decode(data)
        assert taglist.tagList == [tag0, tag1]
示例#12
0
 def bvlpdu_contents(self, use_dict=None, as_class=dict):
     return PDUData.pdudata_contents(self, use_dict=use_dict, as_class=as_class)