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


Python wire_format.WIRETYPE_VARINT屬性代碼示例

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


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

示例1: testCanonicalSerializationOrder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def testCanonicalSerializationOrder(self):
    proto = more_messages_pb2.OutOfOrderFields()
    # These are also their tag numbers.  Even though we're setting these in
    # reverse-tag order AND they're listed in reverse tag-order in the .proto
    # file, they should nonetheless be serialized in tag order.
    proto.optional_sint32 = 5
    proto.Extensions[more_messages_pb2.optional_uint64] = 4
    proto.optional_uint32 = 3
    proto.Extensions[more_messages_pb2.optional_int64] = 2
    proto.optional_int32 = 1
    serialized = proto.SerializeToString()
    self.assertEqual(proto.ByteSize(), len(serialized))
    d = _MiniDecoder(serialized)
    ReadTag = d.ReadFieldNumberAndWireType
    self.assertEqual((1, wire_format.WIRETYPE_VARINT), ReadTag())
    self.assertEqual(1, d.ReadInt32())
    self.assertEqual((2, wire_format.WIRETYPE_VARINT), ReadTag())
    self.assertEqual(2, d.ReadInt64())
    self.assertEqual((3, wire_format.WIRETYPE_VARINT), ReadTag())
    self.assertEqual(3, d.ReadUInt32())
    self.assertEqual((4, wire_format.WIRETYPE_VARINT), ReadTag())
    self.assertEqual(4, d.ReadUInt64())
    self.assertEqual((5, wire_format.WIRETYPE_VARINT), ReadTag())
    self.assertEqual(5, d.ReadSInt32()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:reflection_test.py

示例2: _DecodeUnknownField

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def _DecodeUnknownField(buffer, pos, wire_type):
  """Decode a unknown field.  Returns the UnknownField and new position."""

  if wire_type == wire_format.WIRETYPE_VARINT:
    (data, pos) = _DecodeVarint(buffer, pos)
  elif wire_type == wire_format.WIRETYPE_FIXED64:
    (data, pos) = _DecodeFixed64(buffer, pos)
  elif wire_type == wire_format.WIRETYPE_FIXED32:
    (data, pos) = _DecodeFixed32(buffer, pos)
  elif wire_type == wire_format.WIRETYPE_LENGTH_DELIMITED:
    (size, pos) = _DecodeVarint(buffer, pos)
    data = buffer[pos:pos+size].tobytes()
    pos += size
  elif wire_type == wire_format.WIRETYPE_START_GROUP:
    (data, pos) = _DecodeUnknownFieldSet(buffer, pos)
  elif wire_type == wire_format.WIRETYPE_END_GROUP:
    return (0, -1)
  else:
    raise _DecodeError('Wrong wire type in tag.')

  return (data, pos) 
開發者ID:luci,項目名稱:luci-py,代碼行數:23,代碼來源:decoder.py

示例3: BoolEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def BoolEncoder(field_number, is_repeated, is_packed):
  """Returns an encoder for a boolean field."""

  false_byte = b'\x00'
  true_byte = b'\x01'
  if is_packed:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
    local_EncodeVarint = _EncodeVarint
    def EncodePackedField(write, value, deterministic):
      write(tag_bytes)
      local_EncodeVarint(write, len(value), deterministic)
      for element in value:
        if element:
          write(true_byte)
        else:
          write(false_byte)
    return EncodePackedField
  elif is_repeated:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
    def EncodeRepeatedField(write, value, unused_deterministic=None):
      for element in value:
        write(tag_bytes)
        if element:
          write(true_byte)
        else:
          write(false_byte)
    return EncodeRepeatedField
  else:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
    def EncodeField(write, value, unused_deterministic=None):
      write(tag_bytes)
      if value:
        return write(true_byte)
      return write(false_byte)
    return EncodeField 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:37,代碼來源:encoder.py

示例4: MessageSetItemEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def MessageSetItemEncoder(field_number):
  """Encoder for extensions of MessageSet.

  The message set message looks like this:
    message MessageSet {
      repeated group Item = 1 {
        required int32 type_id = 2;
        required string message = 3;
      }
    }
  """
  start_bytes = b"".join([
      TagBytes(1, wire_format.WIRETYPE_START_GROUP),
      TagBytes(2, wire_format.WIRETYPE_VARINT),
      _VarintBytes(field_number),
      TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)])
  end_bytes = TagBytes(1, wire_format.WIRETYPE_END_GROUP)
  local_EncodeVarint = _EncodeVarint

  def EncodeField(write, value, deterministic):
    write(start_bytes)
    local_EncodeVarint(write, value.ByteSize(), deterministic)
    value._InternalSerialize(write, deterministic)
    return write(end_bytes)

  return EncodeField


# --------------------------------------------------------------------
# As before, Map is special. 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:32,代碼來源:encoder.py

示例5: BoolEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def BoolEncoder(field_number, is_repeated, is_packed):
  """Returns an encoder for a boolean field."""

  false_byte = b'\x00'
  true_byte = b'\x01'
  if is_packed:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
    local_EncodeVarint = _EncodeVarint
    def EncodePackedField(write, value):
      write(tag_bytes)
      local_EncodeVarint(write, len(value))
      for element in value:
        if element:
          write(true_byte)
        else:
          write(false_byte)
    return EncodePackedField
  elif is_repeated:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
    def EncodeRepeatedField(write, value):
      for element in value:
        write(tag_bytes)
        if element:
          write(true_byte)
        else:
          write(false_byte)
    return EncodeRepeatedField
  else:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
    def EncodeField(write, value):
      write(tag_bytes)
      if value:
        return write(true_byte)
      return write(false_byte)
    return EncodeField 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:37,代碼來源:encoder.py

示例6: MessageSetItemEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def MessageSetItemEncoder(field_number):
  """Encoder for extensions of MessageSet.

  The message set message looks like this:
    message MessageSet {
      repeated group Item = 1 {
        required int32 type_id = 2;
        required string message = 3;
      }
    }
  """
  start_bytes = b"".join([
      TagBytes(1, wire_format.WIRETYPE_START_GROUP),
      TagBytes(2, wire_format.WIRETYPE_VARINT),
      _VarintBytes(field_number),
      TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)])
  end_bytes = TagBytes(1, wire_format.WIRETYPE_END_GROUP)
  local_EncodeVarint = _EncodeVarint

  def EncodeField(write, value):
    write(start_bytes)
    local_EncodeVarint(write, value.ByteSize())
    value._InternalSerialize(write)
    return write(end_bytes)

  return EncodeField


# --------------------------------------------------------------------
# As before, Map is special. 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:32,代碼來源:encoder.py

示例7: BoolEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def BoolEncoder(field_number, is_repeated, is_packed):
  """Returns an encoder for a boolean field."""

##!PY25  false_byte = b'\x00'
##!PY25  true_byte = b'\x01'
  false_byte = '\x00'.encode('latin1')  ##PY25
  true_byte = '\x01'.encode('latin1')  ##PY25
  if is_packed:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
    local_EncodeVarint = _EncodeVarint
    def EncodePackedField(write, value):
      write(tag_bytes)
      local_EncodeVarint(write, len(value))
      for element in value:
        if element:
          write(true_byte)
        else:
          write(false_byte)
    return EncodePackedField
  elif is_repeated:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
    def EncodeRepeatedField(write, value):
      for element in value:
        write(tag_bytes)
        if element:
          write(true_byte)
        else:
          write(false_byte)
    return EncodeRepeatedField
  else:
    tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
    def EncodeField(write, value):
      write(tag_bytes)
      if value:
        return write(true_byte)
      return write(false_byte)
    return EncodeField 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:39,代碼來源:encoder.py

示例8: MessageSetItemEncoder

# 需要導入模塊: from google.protobuf.internal import wire_format [as 別名]
# 或者: from google.protobuf.internal.wire_format import WIRETYPE_VARINT [as 別名]
def MessageSetItemEncoder(field_number):
  """Encoder for extensions of MessageSet.

  The message set message looks like this:
    message MessageSet {
      repeated group Item = 1 {
        required int32 type_id = 2;
        required string message = 3;
      }
    }
  """
  start_bytes = "".encode("latin1").join([  ##PY25
##!PY25  start_bytes = b"".join([
      TagBytes(1, wire_format.WIRETYPE_START_GROUP),
      TagBytes(2, wire_format.WIRETYPE_VARINT),
      _VarintBytes(field_number),
      TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)])
  end_bytes = TagBytes(1, wire_format.WIRETYPE_END_GROUP)
  local_EncodeVarint = _EncodeVarint

  def EncodeField(write, value):
    write(start_bytes)
    local_EncodeVarint(write, value.ByteSize())
    value._InternalSerialize(write)
    return write(end_bytes)

  return EncodeField 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:29,代碼來源:encoder.py


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