本文整理汇总了Python中xdrlib.Packer.pack_float方法的典型用法代码示例。如果您正苦于以下问题:Python Packer.pack_float方法的具体用法?Python Packer.pack_float怎么用?Python Packer.pack_float使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdrlib.Packer
的用法示例。
在下文中一共展示了Packer.pack_float方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _gmetric
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_float [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()
示例2: _gmetric
# 需要导入模块: from xdrlib import Packer [as 别名]
# 或者: from xdrlib.Packer import pack_float [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())