當前位置: 首頁>>代碼示例>>Python>>正文


Python Packer.pack_double方法代碼示例

本文整理匯總了Python中xdrlib.Packer.pack_double方法的典型用法代碼示例。如果您正苦於以下問題:Python Packer.pack_double方法的具體用法?Python Packer.pack_double怎麽用?Python Packer.pack_double使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xdrlib.Packer的用法示例。


在下文中一共展示了Packer.pack_double方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: send

# 需要導入模塊: from xdrlib import Packer [as 別名]
# 或者: from xdrlib.Packer import pack_double [as 別名]
 def send(self):
     try:
         unp = Packer() 
         unp.pack_fstring(96, self.model.encode())
         unp.pack_double(self.time)
         unp.pack_double(self.lag)
         unp.pack_farray(3, self.position, unp.pack_double)
         unp.pack_farray(3, self.orientation, unp.pack_float)
         unp.pack_farray(3, self.linear_vel, unp.pack_float)
         unp.pack_farray(3, self.angular_vel, unp.pack_float)
         unp.pack_farray(3, self.linear_accel, unp.pack_float)
         unp.pack_farray(3, self.angular_accel, unp.pack_float)
         unp.pack_uint(0)
         self.properties.send(unp)
         msgbuf = unp.get_buffer()
         headbuf = self.header.send()
         self.header.msglen = len(headbuf + msgbuf)
         #print("setting len=",self.header.msglen, len(headbuf + msgbuf))
         headbuf = self.header.send()
         #print("len2=",self.header.msglen, len(headbuf+msgbuf))
         return headbuf + msgbuf
     except:
         llogger.exception("ERROR creating msg")
         print(self.model)
開發者ID:bartacruz,項目名稱:fgatc,代碼行數:26,代碼來源:messages.py

示例2: _gmetric

# 需要導入模塊: from xdrlib import Packer [as 別名]
# 或者: from xdrlib.Packer import pack_double [as 別名]
    def _gmetric(self, name, val, metric_type, units, slope, tmax, dmax, group, title, description, spoof):

        meta = Packer()
        HOSTNAME = socket.gethostname()
        if spoof:
            SPOOF_ENABLED = 1
        else:
            SPOOF_ENABLED = 0

        # Meta data about a metric
        packet_type = 128
        meta.pack_int(packet_type)
        if SPOOF_ENABLED == 1:
            meta.pack_string(spoof)
        else:
            meta.pack_string(HOSTNAME)
        meta.pack_string(name)
        meta.pack_int(SPOOF_ENABLED)
        meta.pack_string(metric_type)
        meta.pack_string(name)
        meta.pack_string(units)
        meta.pack_int(METRIC_SLOPES[slope])  # map slope string to int
        meta.pack_uint(int(tmax))
        meta.pack_uint(int(dmax))

        extra_data = 0
        if group:
            extra_data += 1
        if title:
            extra_data += 1
        if description:
            extra_data += 1

        meta.pack_int(extra_data)
        if group:
            for g in group.split(','):
                meta.pack_string("GROUP")
                meta.pack_string(g)
        if title:
            meta.pack_string("TITLE")
            meta.pack_string(title)
        if description:
            meta.pack_string("DESC")
            meta.pack_string(description)

        # Actual data sent in a separate packet
        data = Packer()
        packet_type = METRIC_TYPES[metric_type]
        data.pack_int(packet_type)
        if SPOOF_ENABLED == 1:
            data.pack_string(spoof)
        else:
            data.pack_string(HOSTNAME)
        data.pack_string(name)
        data.pack_int(SPOOF_ENABLED)

        if metric_type in ['int8', 'uint8', 'int16', 'uint16', 'int32']:
            data.pack_string("%d")
            data.pack_int(int(val))
        if metric_type == 'uint32':
            data.pack_string("%u")
            data.pack_uint(long(val))
        if metric_type == 'string':
            data.pack_string("%s")
            data.pack_string(str(val))
        if metric_type == 'float':
            data.pack_string("%f")
            data.pack_float(float(val))
        if metric_type == 'double':
            data.pack_string("%f")
            data.pack_double(float(val))  # XXX - double or float?

        return meta.get_buffer(), data.get_buffer()
開發者ID:MailOnline,項目名稱:alerta,代碼行數:75,代碼來源:ganglia.py

示例3: _gmetric

# 需要導入模塊: from xdrlib import Packer [as 別名]
# 或者: from xdrlib.Packer import pack_double [as 別名]
    def _gmetric(self, name, val, type, units, slope, tmax, dmax, group, title, description, spoof):
        """
        Arguments are in all upper-case to match XML
        """

        meta = Packer()
        HOSTNAME=socket.gethostname()
        if spoof == "":
            SPOOFENABLED=0
        else :
            SPOOFENABLED=1

        # Meta data about a metric
        packet_type = 128
        meta.pack_int(packet_type)
        if SPOOFENABLED == 1:
            meta.pack_string(spoof)
        else:
            meta.pack_string(HOSTNAME)
        meta.pack_string(name)
        meta.pack_int(SPOOFENABLED)
        meta.pack_string(type)
        meta.pack_string(name)
        meta.pack_string(units)
        meta.pack_int(SLOPES[slope]) # map slope string to int
        meta.pack_uint(int(tmax))
        meta.pack_uint(int(dmax))

        extra_data = 0
        if group != "":
            extra_data += 1
        if title != "":
            extra_data += 1
        if description != "":
            extra_data += 1

        meta.pack_int(extra_data)
        if group != "":
            meta.pack_string("GROUP")
            meta.pack_string(group)
        if title != "":
            meta.pack_string("TITLE")
            meta.pack_string(title)
        if description != "":
            meta.pack_string("DESC")
            meta.pack_string(description)

        # Actual data sent in a separate packet
        data = Packer()
        packet_type = TYPES[type]
        data.pack_int(packet_type)
        if SPOOFENABLED == 1:
            data.pack_string(spoof)
        else:
            data.pack_string(HOSTNAME)
        data.pack_string(name)
        data.pack_int(SPOOFENABLED)

        if type in ['int8','uint8','int16','uint16','int32']:
            data.pack_string("%d")
            data.pack_int(int(val))
        if type == 'uint32':
            data.pack_string("%u")
            data.pack_uint(long(val))
        if type == 'string':
            data.pack_string("%s")
            data.pack_string(str(val))
        if type == 'float':
            data.pack_string("%f")
            data.pack_float(float(val))
        if type == 'double':
            data.pack_string("%f")
            data.pack_double(float(val))  # XXX - double or float?

        return (meta.get_buffer(), data.get_buffer())
開發者ID:satterly,項目名稱:ganglia_contrib,代碼行數:77,代碼來源:gmetric.py


注:本文中的xdrlib.Packer.pack_double方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。