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


Python wire_format.ZigZagEncode方法代碼示例

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


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

示例1: testZigZagEncode

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import ZigZagEncode [as 別名]
def testZigZagEncode(self):
    Z = wire_format.ZigZagEncode
    self.assertEqual(0, Z(0))
    self.assertEqual(1, Z(-1))
    self.assertEqual(2, Z(1))
    self.assertEqual(3, Z(-2))
    self.assertEqual(4, Z(2))
    self.assertEqual(0xfffffffe, Z(0x7fffffff))
    self.assertEqual(0xffffffff, Z(-0x80000000))
    self.assertEqual(0xfffffffffffffffe, Z(0x7fffffffffffffff))
    self.assertEqual(0xffffffffffffffff, Z(-0x8000000000000000))

    self.assertRaises(TypeError, Z, None)
    self.assertRaises(TypeError, Z, 'abcd')
    self.assertRaises(TypeError, Z, 0.0)
    self.assertRaises(TypeError, Z, object()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:18,代碼來源:wire_format_test.py

示例2: _ModifiedSizer

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import ZigZagEncode [as 別名]
def _ModifiedSizer(compute_value_size, modify_value):
  """Like SimpleSizer, but modify_value is invoked on each value before it is
  passed to compute_value_size.  modify_value is typically ZigZagEncode."""

  def SpecificSizer(field_number, is_repeated, is_packed):
    tag_size = _TagSize(field_number)
    if is_packed:
      local_VarintSize = _VarintSize
      def PackedFieldSize(value):
        result = 0
        for element in value:
          result += compute_value_size(modify_value(element))
        return result + local_VarintSize(result) + tag_size
      return PackedFieldSize
    elif is_repeated:
      def RepeatedFieldSize(value):
        result = tag_size * len(value)
        for element in value:
          result += compute_value_size(modify_value(element))
        return result
      return RepeatedFieldSize
    else:
      def FieldSize(value):
        return tag_size + compute_value_size(modify_value(value))
      return FieldSize

  return SpecificSizer 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:29,代碼來源:encoder.py

示例3: _ModifiedEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import ZigZagEncode [as 別名]
def _ModifiedEncoder(wire_type, encode_value, compute_value_size, modify_value):
  """Like SimpleEncoder but additionally invokes modify_value on every value
  before passing it to encode_value.  Usually modify_value is ZigZagEncode."""

  def SpecificEncoder(field_number, is_repeated, is_packed):
    if is_packed:
      tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
      local_EncodeVarint = _EncodeVarint
      def EncodePackedField(write, value, deterministic):
        write(tag_bytes)
        size = 0
        for element in value:
          size += compute_value_size(modify_value(element))
        local_EncodeVarint(write, size, deterministic)
        for element in value:
          encode_value(write, modify_value(element), deterministic)
      return EncodePackedField
    elif is_repeated:
      tag_bytes = TagBytes(field_number, wire_type)
      def EncodeRepeatedField(write, value, deterministic):
        for element in value:
          write(tag_bytes)
          encode_value(write, modify_value(element), deterministic)
      return EncodeRepeatedField
    else:
      tag_bytes = TagBytes(field_number, wire_type)
      def EncodeField(write, value, deterministic):
        write(tag_bytes)
        return encode_value(write, modify_value(value), deterministic)
      return EncodeField

  return SpecificEncoder 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:34,代碼來源:encoder.py

示例4: _ModifiedEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import ZigZagEncode [as 別名]
def _ModifiedEncoder(wire_type, encode_value, compute_value_size, modify_value):
  """Like SimpleEncoder but additionally invokes modify_value on every value
  before passing it to encode_value.  Usually modify_value is ZigZagEncode."""

  def SpecificEncoder(field_number, is_repeated, is_packed):
    if is_packed:
      tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
      local_EncodeVarint = _EncodeVarint
      def EncodePackedField(write, value):
        write(tag_bytes)
        size = 0
        for element in value:
          size += compute_value_size(modify_value(element))
        local_EncodeVarint(write, size)
        for element in value:
          encode_value(write, modify_value(element))
      return EncodePackedField
    elif is_repeated:
      tag_bytes = TagBytes(field_number, wire_type)
      def EncodeRepeatedField(write, value):
        for element in value:
          write(tag_bytes)
          encode_value(write, modify_value(element))
      return EncodeRepeatedField
    else:
      tag_bytes = TagBytes(field_number, wire_type)
      def EncodeField(write, value):
        write(tag_bytes)
        return encode_value(write, modify_value(value))
      return EncodeField

  return SpecificEncoder 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:34,代碼來源:encoder.py


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