当前位置: 首页>>代码示例>>Python>>正文


Python support.pack_single_uint32函数代码示例

本文整理汇总了Python中support.pack_single_uint32函数的典型用法代码示例。如果您正苦于以下问题:Python pack_single_uint32函数的具体用法?Python pack_single_uint32怎么用?Python pack_single_uint32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pack_single_uint32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_load_buffer

 def generate_load_buffer(self):
     '''
     lift tuple (ID, start decider, end decider, chair_count, chair_capacity)
     '''
     return sp.pack_single_uint32(self.id) + sp.pack_single_uint32(self.start_decider) + \
             sp.pack_single_uint32(self.end_decider) + sp.pack_single_uint32(self.chair_count) + \
             sp.pack_single_uint32(self.chair_capacity)
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:7,代码来源:resort.py

示例2: pack_orders_tuples

    def pack_orders_tuples(self, orders):
        packed = []

        if [] == orders:
            return packed

        # for each order
        for o in orders:
            #  table id
            p_tid = sp.pack_single_uint32(o.tid)
            #  customer id
            p_cid = sp.pack_single_uint32(o.cid)
            #  ftype
            p_ft = sp.pack_single_uint32(o.ftype)
            #  food details

            food = o.fitem
            p_fi = ''
            if o.ftype == m.FOOD_TYPE['APP_TYPE']:
                p_fi += self._pad_and_pack_str(food.name, CONFIG['APP_NAME_SZ'])
            elif o.ftype == m.FOOD_TYPE['MEAL_TYPE']:
                p_fi += self._pad_and_pack_str(food.name, CONFIG['MEAL_NAME_SZ'])
                p_fi += self._pad_and_pack_str(food.main, CONFIG['MEAL_MAIN_SZ'])
                p_fi += self._pad_and_pack_str(food.veggie, CONFIG['MEAL_VEG_SZ'])
                p_fi += self._pad_and_pack_str(food.side, CONFIG['MEAL_SIDE_SZ'])
            elif o.ftype == m.FOOD_TYPE['DES_TYPE']:
                p_fi += self._pad_and_pack_str(food.name, CONFIG['DES_NAME_SZ'])

            packed.append( (p_tid, p_cid, p_ft, p_fi) )

        return packed
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:31,代码来源:orderup.py

示例3: find_are_related

    def find_are_related(self):
        '''
        Determine if 2 people are related.
        '''
        if DEBUG:
            print "cmd: find are related -----------"

        [parent1, parent2] = self.state['s'].get_random_people(2)
  
        if self.state['s'].p_unk == parent1 or \
           self.state['s'].p_unk == parent2:
            return -1

        buf = parent1.get_id_bytes()
        buf += parent2.get_id_bytes()
        buf = self.ARE_RELATED + sp.pack_single_uint32(len(buf)) + buf
        self.write(buf)

        ret = self.state['s'].find_are_related(parent1, parent2)
        msg = ''
        if CONFIG['RELATED'] == ret:
            msg = sp.pack_single_uint32(CONFIG['RELATED'])
            if DEBUG:
                print "{0} and {1} are related".format(parent1.id, parent2.id)
        elif CONFIG['NOT_RELATED'] == ret:
            if DEBUG:
                print "{0} and {1} are NOT related".format(parent1.id, parent2.id)
            msg = sp.pack_single_uint32(CONFIG['NOT_RELATED'])

        msg += self.OK
        self.read(length=len(msg), expect=msg)
        return 0
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:32,代码来源:machine.py

示例4: gen_new_taxpayer_data_bytes

    def gen_new_taxpayer_data_bytes(self):
        """
        Generate byte string sent to create a new taxpayer.
        """
        byte_str = ""
        for v in [self.fname, self.mname, self.lname, self.addy, self.csz]:
            byte_str += sp.pack_single_string(v)
        byte_str += sp.pack_single_uint32(self.dob)
        byte_str += sp.pack_single_uint32(self.id)

        return byte_str
开发者ID:trailofbits,项目名称:cb-multios,代码行数:11,代码来源:template.py

示例5: lift_stats_buffer

    def lift_stats_buffer(self):
        '''
        Examine all lifts and collect their stats into a buffer.

        For each lift, get id and rider_total
        '''
        buf = ''
        for l in self.lifts:
            if DEBUG:
                print "L{0} had {1} riders".format(l.id, l.rider_total)
            buf += sp.pack_single_uint32(l.id)
            buf += sp.pack_single_uint32(l.rider_total)
        return buf
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:13,代码来源:resort.py

示例6: trail_stats_buffer

    def trail_stats_buffer(self):
        '''
        Examine all trails and collect their stats into a buffer.

        For each trail, get id and rider_total
        '''
        buf = ''
        for t in self.trails:
            if DEBUG:
                print "T{0} had {1} riders".format(t.id, t.rider_total)
            buf += sp.pack_single_uint32(t.id)
            buf += sp.pack_single_uint32(t.rider_total)
        return buf
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:13,代码来源:resort.py

示例7: get_plain_content

 def get_plain_content(self):
     pc = ""
     pc += sp.pack_single_uint32(self.serialVersionUID)
     pc += sp.pack_single_uint16(1 + len(self.args))
     pc += sp.pack_single_string(self.fn_addr)
     pc += sp.pack_single_char(" ")
     pc += sp.pack_single_uint32(self.args[0])
     pc += sp.pack_single_char(" ")
     pc += sp.pack_single_uint32(self.args[1])
     pc += sp.pack_single_char(" ")
     pc += sp.pack_single_uint32(self.args[2])
     pc += sp.pack_single_char("\0")
     return pc
开发者ID:trailofbits,项目名称:cb-multios,代码行数:13,代码来源:breakfast.py

示例8: get_serialized_content

 def get_serialized_content(self):
     sc = ""
     sc += sp.pack_single_uint32(self.serialVersionUID)
     sc += sp.pack_single_string(self.typeName)
     sc += sp.pack_single_uint16(1 + len(self.args))
     sc += sp.pack_single_string(self.fn_addr)
     sc += sp.pack_single_char(" ")
     sc += sp.pack_single_uint32(self.args[0])
     sc += sp.pack_single_char(" ")
     sc += sp.pack_single_uint32(self.args[1])
     sc += sp.pack_single_char(" ")
     sc += sp.pack_single_uint32(self.args[2])
     sc += sp.pack_single_char("\0")
     return sc
开发者ID:trailofbits,项目名称:cb-multios,代码行数:14,代码来源:breakfast.py

示例9: load_rider_group

    def load_rider_group(self):
        '''
        Load a group of riders.
        '''
        if DEBUG:
            print "cmd: load rider group -----------"

        riders = []        
        count = randint(10,200)
        # count = 20
        rider_buf = self.LOAD_RIDER_GROUP + sp.pack_single_uint32(count)
        for _ in range(count):
            r = self._gen_random_rider()
            riders.append(r)
            rider_buf += r.generate_load_buffer()

        self.resort.riders += riders
        self.resort.rider_count += len(riders)

        if DEBUG:
            print "Adding {0} riders".format(len(riders))
            for r in riders:
                print " [r{0}] added".format(r.id)

        self.write(rider_buf)
        self.read(length=len(self.OK), expect=self.OK)

        return 0
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:28,代码来源:machine.py

示例10: new_deck

    def new_deck(self, deck=[], allow_bad=True):
        """
        Give the dealer a new deck.
        """
        if DEBUG:
            print "cmd: new deck -----------"

        # cmd
        byte_str = self.state["e"].make_trigger_buf("DECK")

        bad_cards = False
        if True == allow_bad and self.chance(0.001):
            if DEBUG:
                print "deck includes bad cards"
            bad_cards = True

        if [] == deck:
            deck = self.state["e"].make_new_random_deck(randint(500, 3500), bad_cards)

        # number of cards (uint32)
        byte_str += sp.pack_single_uint32(len(deck))
        # cards (array of uint8)
        byte_str += sp.pack_single_string("".join(deck))
        self.write(byte_str)

        # self.state['e'].ok
        self.read(length=len(self.state["e"].ok), expect=self.state["e"].ok)

        if False == bad_cards:
            self.state["e"].deck = deck
            return 0
        else:
            return -1
开发者ID:trailofbits,项目名称:cb-multios,代码行数:33,代码来源:machine.py

示例11: degrees_of_separation

    def degrees_of_separation(self):
        '''
        Determine the degrees of separation between 2 people.
        '''
        if DEBUG:
            print "cmd: degrees of separation -----------"

        [parent1, parent2] = self.state['s'].get_random_people(2)
  
        if self.state['s'].p_unk == parent1 or \
           self.state['s'].p_unk == parent2:
            return -1

        buf = parent1.get_id_bytes()
        buf += parent2.get_id_bytes()
        buf = self.DEGREES + sp.pack_single_uint32(len(buf)) + buf
        self.write(buf)

        self.state['s'].new_search_map()

        ret = self.state['s'].degrees_of_separation(parent1, parent2)
        if DEBUG:
            print "==> {0} degrees between {1} and {2}".format(ret, parent1.id, parent2.id)

        msg = sp.pack_single_int32(ret)
        msg += self.OK
        self.read(length=len(msg), expect=msg)
        return 0
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:28,代码来源:machine.py

示例12: get_packed_results

 def get_packed_results(self):
     p_res = ''
     if DEBUG:
         print " results were: {0}".format(self.results)
     for r in self.results:
         p_res += sp.pack_single_uint32(r)
     return p_res
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:7,代码来源:dealer.py

示例13: get_packed_wagers

 def get_packed_wagers(self):
     p_wag = ''
     if DEBUG:
         print " wagers were:  {0}".format(self.wagers)
     for w in self.wagers:
         p_wag += sp.pack_single_uint32(w)
     return p_wag
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:7,代码来源:dealer.py

示例14: set_union

    def set_union(self, people=[]):
        '''
        Set a union relationship between 2 people

        people => [parent1, parent2]
        '''
        if DEBUG:
            print "cmd: set union -----------"

        if people != []:
            [parent1, parent2] = people
        else:
            [parent1, parent2] = self.state['s'].get_random_people(2)
  
        if parent1 == parent2 or self.state['s'].p_unk == parent1 or \
            self.state['s'].p_unk == parent2:
            return -1

        buf = parent1.get_id_bytes()
        buf += parent2.get_id_bytes()
        buf = self.SET_UNION + sp.pack_single_uint32(len(buf)) + buf
        self.write(buf)

        ret = self.state['s'].set_union(parent1, parent2)
        if 0 != ret:
            self.read(length=len(self.ERR), expect=self.ERR)
            return -1

        self.read(length=len(self.OK), expect=self.OK)
        return 0
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:30,代码来源:machine.py

示例15: add_product

    def add_product(self):
        '''
        Add a new product.
        '''
        self.send_cmd(self.CMD_ADD)
        if DEBUG:
            print "cmd: add product"

        # gen new product
        p = self.state['e'].get_new_rand_product()
        #send bc
        self.write(p.barcode)
        # if bc is not unique -> STATUS_ERR
        if False == self.state['e'].is_barcode_unique(p.barcode):
            self.recv_status(self.STATUS_ERR)
            return -1

        write_str = ''
        #send model_num
        write_str += sp.pack_single_uint32(p.model_num)

        #send cost
        write_str += sp.pack_single_float(p.cost)

        #send desc + CONFIG['DESC_TERM']
        write_str += sp.pack_single_string(p.description + CONFIG['DESC_TERM'])
        self.write(write_str)

        # add new product to inventory
        self.state['e'].add_prod_to_inventory(p)

        self.recv_status(self.STATUS_OK)

        return 0
开发者ID:CyberGrandChallenge,项目名称:samples,代码行数:34,代码来源:machine.py


注:本文中的support.pack_single_uint32函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。