当前位置: 首页>>代码示例>>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;未经允许,请勿转载。