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


Python type_checkers.TYPE_TO_ENCODER屬性代碼示例

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


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

示例1: _AttachFieldHelpers

# 需要導入模塊: from google.protobuf.internal import type_checkers [as 別名]
# 或者: from google.protobuf.internal.type_checkers import TYPE_TO_ENCODER [as 別名]
def _AttachFieldHelpers(cls, field_descriptor):
  is_repeated = (field_descriptor.label == _FieldDescriptor.LABEL_REPEATED)
  is_packed = (field_descriptor.has_options and
               field_descriptor.GetOptions().packed)

  if _IsMessageSetExtension(field_descriptor):
    field_encoder = encoder.MessageSetItemEncoder(field_descriptor.number)
    sizer = encoder.MessageSetItemSizer(field_descriptor.number)
  else:
    field_encoder = type_checkers.TYPE_TO_ENCODER[field_descriptor.type](
        field_descriptor.number, is_repeated, is_packed)
    sizer = type_checkers.TYPE_TO_SIZER[field_descriptor.type](
        field_descriptor.number, is_repeated, is_packed)

  field_descriptor._encoder = field_encoder
  field_descriptor._sizer = sizer
  field_descriptor._default_constructor = _DefaultValueConstructorForField(
      field_descriptor)

  def AddDecoder(wiretype, is_packed):
    tag_bytes = encoder.TagBytes(field_descriptor.number, wiretype)
    cls._decoders_by_tag[tag_bytes] = (
        type_checkers.TYPE_TO_DECODER[field_descriptor.type](
            field_descriptor.number, is_repeated, is_packed,
            field_descriptor, field_descriptor._default_constructor))

  AddDecoder(type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type],
             False)

  if is_repeated and wire_format.IsTypePackable(field_descriptor.type):
    # To support wire compatibility of adding packed = true, add a decoder for
    # packed values regardless of the field's options.
    AddDecoder(wire_format.WIRETYPE_LENGTH_DELIMITED, True) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:35,代碼來源:python_message.py


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