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


Python message.EncodeError方法代碼示例

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


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

示例1: _VarUInt64ByteSizeNoTag

# 需要導入模塊: from google.protobuf import message [as 別名]
# 或者: from google.protobuf.message import EncodeError [as 別名]
def _VarUInt64ByteSizeNoTag(uint64):
  """Returns the number of bytes required to serialize a single varint
  using boundary value comparisons. (unrolled loop optimization -WPierce)
  uint64 must be unsigned.
  """
  if uint64 <= 0x7f: return 1
  if uint64 <= 0x3fff: return 2
  if uint64 <= 0x1fffff: return 3
  if uint64 <= 0xfffffff: return 4
  if uint64 <= 0x7ffffffff: return 5
  if uint64 <= 0x3ffffffffff: return 6
  if uint64 <= 0x1ffffffffffff: return 7
  if uint64 <= 0xffffffffffffff: return 8
  if uint64 <= 0x7fffffffffffffff: return 9
  if uint64 > UINT64_MAX:
    raise message.EncodeError('Value out of range: %d' % uint64)
  return 10 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:wire_format.py

示例2: _BytesForNonRepeatedElement

# 需要導入模塊: from google.protobuf import message [as 別名]
# 或者: from google.protobuf.message import EncodeError [as 別名]
def _BytesForNonRepeatedElement(value, field_number, field_type):
  """Returns the number of bytes needed to serialize a non-repeated element.
  The returned byte count includes space for tag information and any
  other additional space associated with serializing value.

  Args:
    value: Value we're serializing.
    field_number: Field number of this value.  (Since the field number
      is stored as part of a varint-encoded tag, this has an impact
      on the total bytes required to serialize the value).
    field_type: The type of the field.  One of the TYPE_* constants
      within FieldDescriptor.
  """
  try:
    fn = type_checkers.TYPE_TO_BYTE_SIZE_FN[field_type]
    return fn(field_number, value)
  except KeyError:
    raise message_mod.EncodeError('Unrecognized field type: %d' % field_type) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:python_message.py

示例3: PackTag

# 需要導入模塊: from google.protobuf import message [as 別名]
# 或者: from google.protobuf.message import EncodeError [as 別名]
def PackTag(field_number, wire_type):
  """Returns an unsigned 32-bit integer that encodes the field number and
  wire type information in standard protocol message wire format.

  Args:
    field_number: Expected to be an integer in the range [1, 1 << 29)
    wire_type: One of the WIRETYPE_* constants.
  """
  if not 0 <= wire_type <= _WIRETYPE_MAX:
    raise message.EncodeError('Unknown wire type: %d' % wire_type)
  return (field_number << TAG_TYPE_BITS) | wire_type 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:13,代碼來源:wire_format.py

示例4: assertNotInitialized

# 需要導入模塊: from google.protobuf import message [as 別名]
# 或者: from google.protobuf.message import EncodeError [as 別名]
def assertNotInitialized(self, proto, error_size=None):
    errors = []
    self.assertFalse(proto.IsInitialized())
    self.assertFalse(proto.IsInitialized(errors))
    self.assertEqual(error_size, len(errors))
    self.assertRaises(message.EncodeError, proto.SerializeToString)
    # "Partial" serialization doesn't care if message is uninitialized.
    proto.SerializePartialToString() 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:reflection_test.py

示例5: testSerializeUninitializedSubMessage

# 需要導入模塊: from google.protobuf import message [as 別名]
# 或者: from google.protobuf.message import EncodeError [as 別名]
def testSerializeUninitializedSubMessage(self):
    proto = unittest_pb2.TestRequiredForeign()

    # Sub-message doesn't exist yet, so this succeeds.
    proto.SerializeToString()

    proto.optional_message.a = 1
    self._CheckRaises(
        message.EncodeError,
        proto.SerializeToString,
        'Message protobuf_unittest.TestRequiredForeign '
        'is missing required fields: '
        'optional_message.b,optional_message.c')

    proto.optional_message.b = 2
    proto.optional_message.c = 3
    proto.SerializeToString()

    proto.repeated_message.add().a = 1
    proto.repeated_message.add().b = 2
    self._CheckRaises(
        message.EncodeError,
        proto.SerializeToString,
        'Message protobuf_unittest.TestRequiredForeign is missing required fields: '
        'repeated_message[0].b,repeated_message[0].c,'
        'repeated_message[1].a,repeated_message[1].c')

    proto.repeated_message[0].b = 2
    proto.repeated_message[0].c = 3
    proto.repeated_message[1].a = 1
    proto.repeated_message[1].c = 3
    proto.SerializeToString() 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:34,代碼來源:reflection_test.py

示例6: _AddSerializeToStringMethod

# 需要導入模塊: from google.protobuf import message [as 別名]
# 或者: from google.protobuf.message import EncodeError [as 別名]
def _AddSerializeToStringMethod(message_descriptor, cls):
  """Helper for _AddMessageMethods()."""

  def SerializeToString(self, **kwargs):
    # Check if the message has all of its required fields set.
    errors = []
    if not self.IsInitialized():
      raise message_mod.EncodeError(
          'Message %s is missing required fields: %s' % (
          self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
    return self.SerializePartialToString(**kwargs)
  cls.SerializeToString = SerializeToString 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:14,代碼來源:python_message.py

示例7: testPackTag

# 需要導入模塊: from google.protobuf import message [as 別名]
# 或者: from google.protobuf.message import EncodeError [as 別名]
def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag
    # Number too high.
    self.assertRaises(message.EncodeError, PackTag, field_number, 6)
    # Number too low.
    self.assertRaises(message.EncodeError, PackTag, field_number, -1) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:12,代碼來源:wire_format_test.py


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