def _CopyDocumentToProtocolBuffer(document, pb):
 pb.set_storage(document_pb.Document.DISK)
 if document.doc_id:
  pb.set_id(document.doc_id.encode('utf-8'))
 if document.language:
  pb.set_language(document.language.encode('utf-8'))
 for field in document.fields:
  field_pb = pb.add_field()
  _CopyFieldToProtocolBuffer(field, field_pb)
 pb.set_order_id(document.rank)
 return pb

def _CopyDocumentToProtocolBuffer ( document , pb ) : pb . set_storage ( document_pb . Document . DISK ) if document . doc_id : pb . set_id ( document . doc_id . encode ( 'utf-8' ) ) if document . language : pb . set_language ( document . language . encode ( 'utf-8' ) ) for field in document . fields : field_pb = pb . add_field ( ) _CopyFieldToProtocolBuffer ( field , field_pb ) pb . set_order_id ( document . rank ) return pb
copies document to a document_pb .