def _NewFieldFromPb(pb):
 name = _DecodeUTF8(pb.name())
 val_type = pb.value().type()
 value = _DecodeValue(_GetValue(pb.value()), val_type)
 lang = None
 if pb.value().has_language():
  lang = _DecodeUTF8(pb.value().language())
 if (val_type == document_pb.FieldValue.TEXT):
  return TextField(name, value, lang)
 elif (val_type == document_pb.FieldValue.HTML):
  return HtmlField(name, value, lang)
 elif (val_type == document_pb.FieldValue.ATOM):
  return AtomField(name, value, lang)
 elif (val_type == document_pb.FieldValue.UNTOKENIZED_PREFIX):
  return UntokenizedPrefixField(name, value, lang)
 elif (val_type == document_pb.FieldValue.TOKENIZED_PREFIX):
  return TokenizedPrefixField(name, value, lang)
 elif (val_type == document_pb.FieldValue.DATE):
  return DateField(name, value)
 elif (val_type == document_pb.FieldValue.NUMBER):
  return NumberField(name, value)
 elif (val_type == document_pb.FieldValue.GEO):
  return GeoField(name, value)
 return InvalidRequest(('Unknown field value type %d' % val_type))

def _NewFieldFromPb ( pb ) : name = _DecodeUTF8 ( pb . name ( ) ) val_type = pb . value ( ) . type ( ) value = _DecodeValue ( _GetValue ( pb . value ( ) ) , val_type ) lang = None if pb . value ( ) . has_language ( ) : lang = _DecodeUTF8 ( pb . value ( ) . language ( ) ) if ( val_type == document_pb . FieldValue . TEXT ) : return TextField ( name , value , lang ) elif ( val_type == document_pb . FieldValue . HTML ) : return HtmlField ( name , value , lang ) elif ( val_type == document_pb . FieldValue . ATOM ) : return AtomField ( name , value , lang ) elif ( val_type == document_pb . FieldValue . UNTOKENIZED_PREFIX ) : return UntokenizedPrefixField ( name , value , lang ) elif ( val_type == document_pb . FieldValue . TOKENIZED_PREFIX ) : return TokenizedPrefixField ( name , value , lang ) elif ( val_type == document_pb . FieldValue . DATE ) : return DateField ( name , value ) elif ( val_type == document_pb . FieldValue . NUMBER ) : return NumberField ( name , value ) elif ( val_type == document_pb . FieldValue . GEO ) : return GeoField ( name , value ) return InvalidRequest ( ( 'Unknown field value type %d' % val_type ) )
constructs a field from a document_pb .