예제 #1
0
파일: tfbuffer.py 프로젝트: jddixon/fieldz
    def put_next(self, field_nbr, value):

        # getter has range check
        field_type = self._msg_spec.field_type_ndx(field_nbr)

        # puts through dispatch table -------------------------------
        if 0 <= field_type and field_type <= ftypes.F_BYTES32:
            # DEBUG
            print(
                "putNext: field type is %d (%s)" %
                (field_type, fstr.as_str(field_type)))
            sys.stdout.flush()
            # END
            T_PUT_FUNCS[field_type](self, value, field_nbr)
            # DEBUG
            if field_type < ftypes.L_STRING:
                print("putNext through dispatch table:\n"
                      "         field   %u\n"
                      "         fType   %u,  %s\n"
                      "         value   %d (0x%x)\n"
                      "         offset  %u" % (
                          field_nbr, field_type, fstr.as_str(field_type),
                          value, value, self._position))
            # END
            return
        else:
            print("unknown/unimplemented field type %s" % str(field_type))

        # -- NOW VESTIGIAL ------------------------------------------
        varint_ = None
예제 #2
0
파일: test_reg.py 프로젝트: jddixon/fieldz
    def test_node_reg(self):
        c_types = CoreTypes()
        test_reg = NodeReg()

        # bootstrap() has loaded fieldTypes and coreTypes
        #       print "DEBUG: FieldTypes.MAX_NDX is %d" % FieldTypes.MAX_NDX        # is 17
        #       print "DEBUG: C.maxNdx is %d" % C.maxNdx        # is  5
        #       print "DEBUG: test_reg.nextRegID is %d test_reg.nextRegID
        self.assertEqual(FieldTypes.MAX_NDX + 1 + c_types.max_ndx + 1, test_reg.next_reg_id)

        # verify that all fieldTypes are defined in the registry, each
        # with the proper index (vBool through fBytes32 at FieldTypes.MAX_NDX)
        for i in range(FieldTypes.MAX_NDX + 1):
            name = test_reg[i].qual_name
            # DEBUG
            #           print '%2u %s' % (i, name)
            # END
            self.assertEqual(FieldStr.as_str(i), name)
            self.assertEqual(i, test_reg.name2reg_id(name))

        for i in range(FieldTypes.MAX_NDX + 1, FieldTypes.MAX_NDX + 1 + c_types.max_ndx + 1):
            name = test_reg[i].qual_name
            # DEBUG
            #           print '%2u %s' % (i, name)
            # END
            self.assertEqual(c_types.as_str(i - (FieldTypes.MAX_NDX + 1)), name)
            self.assertEqual(i, test_reg.name2reg_id(name))

        # F and C range from 0 to maxNdx
        self.assertEqual(FieldTypes.MAX_NDX + 1 + c_types.max_ndx + 1, len(test_reg))

        #       print "DEBUG: len(test_reg) is %u" % len(test_reg)
        #       print "DEBUG: nextRegID is %u"    % test_reg.nextRegID

        self.assertEqual(len(test_reg), test_reg.next_reg_id)
예제 #3
0
파일: msg_spec.py 프로젝트: jddixon/fieldz
 def field_type_name(self):
     if self._type >= 0 and self._type <= FieldTypes.MAX_NDX:
         return FieldStr.as_str(self._type)
     reg_id = self._reg.reg_id2name(self._type)
     if reg_id is None:
         # XXX parent must search upwards if not found
         reg_id = self._reg.parent.reg_id2name(self._type)
     return reg_id
예제 #4
0
    def test_writing_and_reading(self):
        writer = TFWriter.create(LE_MSG_SPEC, BUFSIZE)
        writer.clear()  # should not be necessary

        buf = writer.buffer
        # reader and writer share same buffer
        reader = TFReader(LE_MSG_SPEC, BUFSIZE, buf)

        tstamp = int(time.time())
        node_id = bytearray(20)         # 160 bit
        RNG.next_bytes(node_id)  # .... random value
        key = bytearray(20)         # 160 bit
        RNG.next_bytes(key)  # .... random value
        length = RNG.next_int32()
        by_ = RNG.next_file_name(16)
        path = 'path/to/' + RNG.next_file_name(16)

        nnn = 0                           # 0-based field number
        # write a log entry into the buffer
        writer.put_next(nnn, tstamp)
        nnn = nnn + 1
        writer.put_next(nnn, node_id)
        nnn = nnn + 1
        writer.put_next(nnn, key)
        nnn = nnn + 1
        writer.put_next(nnn, length)
        nnn = nnn + 1
        writer.put_next(nnn, by_)
        nnn = nnn + 1
        writer.put_next(nnn, path)

        # now read the buffer to see what actually was written
        self.assertEqual(0, reader.position)

        reader.get_next()
        self.assertEqual(0, reader.field_nbr)
        self.assertEqual('fuint32', FieldStr.as_str(reader.field_type))
        self.assertEqual(tstamp, reader.value)
        self.assertEqual(5, reader.position)

        reader.get_next()
        self.assertEqual(1, reader.field_nbr)
        self.assertEqual('fbytes20', FieldStr.as_str(reader.field_type))
        self.assertEqual(node_id, reader.value)
        self.assertEqual(26, reader.position)

        reader.get_next()
        self.assertEqual(2, reader.field_nbr)
        self.assertEqual('fbytes20', FieldStr.as_str(reader.field_type))
        self.assertEqual(key, reader.value)
        self.assertEqual(47, reader.position)

        reader.get_next()
        self.assertEqual(3, reader.field_nbr)
        self.assertEqual('vuint32', FieldStr.as_str(reader.field_type))
        self.assertEqual(length, reader.value)

        reader.get_next()
        self.assertEqual(4, reader.field_nbr)
        self.assertEqual('lstring', FieldStr.as_str(reader.field_type))
        self.assertEqual(by_, reader.value)

        reader.get_next()
        self.assertEqual(5, reader.field_nbr)
        self.assertEqual('lstring', FieldStr.as_str(reader.field_type))
        self.assertEqual(path, reader.value)