a
    còf¬  ã                   @   s¦   d Z ddlZddlmZmZ ddlmZ ddlmZ ddlm	Z	 eddd	�Z
de
eed
œdd„Zee
 ee
dœdd„Ze
ejddœdd„Zee
 eje
dœdd„ZdS )z,Contains the Nextgen Pythonic protobuf APIs.é    N)ÚTypeÚTypeVar)Údecoder)Úencoder)ÚMessageÚ_MESSAGEr   )Úbound)ÚmessageÚdeterministicÚreturnc                 C   s   | j |d�S )a  Return the serialized proto.

  Args:
    message: The proto message to be serialized.
    deterministic: If true, requests deterministic serialization
        of the protobuf, with predictable ordering of map keys.

  Returns:
    A binary bytes representation of the message.
  )r
   )ZSerializeToString)r	   r
   © r   úR/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/google/protobuf/proto.pyÚ	serialize   s    r   )Úmessage_classÚpayloadr   c                 C   s   | ƒ }|  |¡ |S )zæGiven a serialized data in binary form, deserialize it into a Message.

  Args:
    message_class: The message meta class.
    payload: A serialized bytes in binary form.

  Returns:
    A new message deserialized from payload.
  )ÚParseFromString)r   r   Znew_messager   r   r   Úparse"   s    

r   )r	   Úoutputr   c                 C   sB   |   ¡ }t ¡ |j|ƒ | t| ƒ¡}||kr>td||f ƒ‚dS )a¢  Writes the size of the message as a varint and the serialized message.

  Writes the size of the message as a varint and then the serialized message.
  This allows more data to be written to the output after the message. Use
  parse_length_prefixed to parse messages written by this method.

  The output stream must be buffered, e.g. using
  https://docs.python.org/3/library/io.html#buffered-streams.

  Example usage:
    out = io.BytesIO()
    for msg in message_list:
      proto.serialize_length_prefixed(msg, out)

  Args:
    message: The protocol buffer message that should be serialized.
    output: BytesIO or custom buffered IO that data should be written to.
  z_Failed to write complete message (wrote: %d, expected: %d). Ensure output is using buffered IO.N)ZByteSizer   Z_VarintEncoderÚwriter   Ú	TypeError)r	   r   ÚsizeZout_sizer   r   r   Úserialize_length_prefixed1   s    ÿÿr   )r   Úinput_bytesr   c                 C   sZ   t  |¡}|du rdS | ƒ }|dkr(|S | | |¡¡}||krVtd |||jj¡ƒ‚|S )a‚  Parse a message from input_bytes.

  Args:
    message_class: The protocol buffer message class that parser should parse.
    input_bytes: A buffered input.

  Example usage:
    while True:
      msg = proto.parse_length_prefixed(message_class, input_bytes)
      if msg is None:
        break
      ...

  Returns:
    A parsed message if successful. None if input_bytes is at EOF.
  Nr   zdTruncated message or non-buffered input_bytes: Expected {0} bytes but only {1} bytes parsed for {2}.)r   Z_DecodeVarintr   ÚreadÚ
ValueErrorÚformatZ
DESCRIPTORÚname)r   r   r   r	   Zparsed_sizer   r   r   Úparse_length_prefixedO   s    

þÿr   )N)Ú__doc__ÚioÚtypingr   r   Zgoogle.protobuf.internalr   r   Zgoogle.protobuf.messager   r   ÚboolÚbytesr   r   ÚBytesIOr   r   r   r   r   r   Ú<module>   s   
þ