本文整理汇总了Python中struct._calcsize函数的典型用法代码示例。如果您正苦于以下问题:Python _calcsize函数的具体用法?Python _calcsize怎么用?Python _calcsize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_calcsize函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: minimum_size
def minimum_size(format):
"""
Return the minimum possible size of the given packed data format.
"""
if not format[:1] in b"@=<>!":
format = b"!" + format
return _calcsize(format.replace(b"$", b""))
示例2: unpack
def unpack(self, format_text):
"""Unpack bytes using struct modules format
:param format_text: struct's module format
:type format_text: :class:`str`
:return data: result from :func:`struct.unpack_from`
:rtype: :class:`tuple`
"""
data = _unpack_from(format_text, self.data, self.offset)
self.offset += _calcsize(format_text)
return data
示例3: initial_size
def initial_size(format):
"""
Return the size of the given packed data format up to the first
variable-length string.
"""
if format[:1] in b"@=<>!":
byte_order = format[:1]
format = format[1:]
else:
byte_order = b"!"
index = format.find(b"$")
if not index:
return 0
elif index > 0:
if b"$$" in format:
raise error("invalid sequence in netstruct format")
format = format[:index]
return _calcsize(byte_order + format)
示例4: _check_size
_type_ = "h"
_check_size(c_short)
class c_ushort(_SimpleCData):
_type_ = "H"
_check_size(c_ushort)
class c_long(_SimpleCData):
_type_ = "l"
_check_size(c_long)
class c_ulong(_SimpleCData):
_type_ = "L"
_check_size(c_ulong)
if _calcsize("i") == _calcsize("l"):
# if int and long have the same size, make c_int an alias for c_long
c_int = c_long
c_uint = c_ulong
else:
class c_int(_SimpleCData):
_type_ = "i"
_check_size(c_int)
class c_uint(_SimpleCData):
_type_ = "I"
_check_size(c_uint)
class c_float(_SimpleCData):
_type_ = "f"
_check_size(c_float)
示例5: _check_size
_check_size(c_ushort)
class c_long(_SimpleCData):
_type_ = 'l'
_check_size(c_long)
class c_ulong(_SimpleCData):
_type_ = 'L'
_check_size(c_ulong)
if _calcsize('i') == _calcsize('l'):
c_int = c_long
c_uint = c_ulong
else:
class c_int(_SimpleCData):
_type_ = 'i'
_check_size(c_int)
class c_uint(_SimpleCData):
_type_ = 'I'
_check_size(c_uint)