Exemplo n.º 1
0
 def testPOST(self):
     c = httplib.HTTPConnection('localhost:8500')
     data = ''
     for i in range(30):
         c.request('POST', '/post', data)
         r = c.getresponse()
         self.assertEqual(200, r.status)
         tmp = r.read()
         # The server responds with the hash of the sent content
         self.assertEqual(dlib.dmHashBuffer64(data), int(tmp))
         if i < 15:
             char = ord('a') + ((i*97 + i) % (ord('z') - ord('a')))
             data += chr(char)
         else:
             # And some larger chunks
             data += 'X' * (35261)
     c.close()
Exemplo n.º 2
0
def compile_animationset(task):
    try:
        import google.protobuf.text_format
        import rig.rig_ddf_pb2
        import dlib
        msg = rig.rig_ddf_pb2.AnimationSetDesc()
        with open(task.inputs[0].srcpath(task.env), 'rb') as in_f:
            google.protobuf.text_format.Merge(in_f.read(), msg)
        msg_animset = rig.rig_ddf_pb2.AnimationSet()
        msg_riganim = msg_animset.animations.add()
        msg_riganim.id = dlib.dmHashBuffer64(os.path.splitext(os.path.basename(msg.animations[0].animation))[0])
        msg_riganim.duration = 0.0
        msg_riganim.sample_rate = 30.0
        with open(task.outputs[0].bldpath(task.env), 'wb') as out_f:
            out_f.write(msg_animset.SerializeToString())
        return 0
    except google.protobuf.text_format.ParseError,e:
        print >>sys.stderr, '%s:%s' % (task.inputs[0].srcpath(task.env), str(e))
        return 1
Exemplo n.º 3
0
    def testHash(self):
        h1 = dlib.dmHashBuffer32("foo")
        h2 = dlib.dmHashBuffer64("foo")

        self.assertEqual(0xd861e2f7L, h1)
        self.assertEqual(0x97b476b3e71147f7L, h2)
Exemplo n.º 4
0
def to_cxx_descriptor(context, pp_cpp, pp_h, message_type, namespace_lst):
    namespace = "_".join(namespace_lst)
    pp_h.p('extern dmDDF::Descriptor %s_%s_DESCRIPTOR;', namespace,
           message_type.name)

    for nt in message_type.nested_type:
        to_cxx_descriptor(context, pp_cpp, pp_h, nt,
                          namespace_lst + [message_type.name])

    for f in message_type.field:
        default = to_cxx_default_value_string(context, f)
        if '"' in default:
            pp_cpp.p('char DM_ALIGNED(4) %s_%s_%s_DEFAULT_VALUE[] = %s;',
                     namespace, message_type.name, f.name, default)

    lst = []
    for f in message_type.field:
        tpl = (f.name, f.number, f.type, f.label)
        if f.type == FieldDescriptor.TYPE_MESSAGE:
            tmp = f.type_name.replace(".", "_")
            if tmp.startswith("_"):
                tmp = tmp[1:]
            tpl += ("&" + tmp + "_DESCRIPTOR", )
        else:
            tpl += ("0x0", )

        tpl += ("(uint32_t)DDF_OFFSET_OF(%s::%s, m_%s)" % (namespace.replace(
            "_", "::"), message_type.name, to_camel_case(f.name)), )

        default = to_cxx_default_value_string(context, f)
        if '"' in default:
            tpl += ('%s_%s_%s_DEFAULT_VALUE' %
                    (namespace, message_type.name, f.name), )
        else:
            tpl += ('0x0', )

        lst.append(tpl)

    if len(lst) > 0:
        pp_cpp.begin("dmDDF::FieldDescriptor %s_%s_FIELDS_DESCRIPTOR[] = ",
                     namespace, message_type.name)
        for name, number, type, label, msg_desc, offset, default_value in lst:
            pp_cpp.p(
                '{ "%s", %d, %d, %d, %s, %s, %s},' %
                (name, number, type, label, msg_desc, offset, default_value))
        pp_cpp.end()
    else:
        pp_cpp.p("dmDDF::FieldDescriptor* %s_%s_FIELDS_DESCRIPTOR = 0x0;",
                 namespace, message_type.name)

    pp_cpp.begin("dmDDF::Descriptor %s_%s_DESCRIPTOR = ", namespace,
                 message_type.name)
    pp_cpp.p('%d, %d,', DDF_MAJOR_VERSION, DDF_MINOR_VERSION)
    pp_cpp.p('"%s",', to_lower_case(message_type.name))
    pp_cpp.p('0x%016XLL,',
             dlib.dmHashBuffer64(to_lower_case(message_type.name)))
    pp_cpp.p('sizeof(%s::%s),', namespace.replace("_", "::"),
             message_type.name)
    pp_cpp.p('%s_%s_FIELDS_DESCRIPTOR,', namespace, message_type.name)
    if len(lst) > 0:
        pp_cpp.p(
            'sizeof(%s_%s_FIELDS_DESCRIPTOR)/sizeof(dmDDF::FieldDescriptor),',
            namespace, message_type.name)
    else:
        pp_cpp.p('0,')
    pp_cpp.end()

    pp_cpp.p(
        'dmDDF::Descriptor* %s::%s::m_DDFDescriptor = &%s_%s_DESCRIPTOR;' %
        ('::'.join(namespace_lst), message_type.name, namespace,
         message_type.name))

    # TODO: This is not optimal. Hash value is sensitive on googles format string
    # Also dependent on type invariant values?
    hash_string = str(message_type).replace(" ",
                                            "").replace("\n",
                                                        "").replace("\r", "")
    pp_cpp.p('const uint64_t %s::%s::m_DDFHash = 0x%016XLL;' %
             ('::'.join(namespace_lst), message_type.name,
              dlib.dmHashBuffer64(hash_string)))

    pp_cpp.p(
        'dmDDF::InternalRegisterDescriptor g_Register_%s_%s(&%s_%s_DESCRIPTOR);'
        % (namespace, message_type.name, namespace, message_type.name))

    pp_cpp.p('')