| Server IP : 172.67.201.108 / Your IP : 216.73.217.39 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib64/python3.9/site-packages/awscrt/__pycache__/ |
Upload File : |
a
ů�i*` � @ sh d dl Z d dlmZ d dlmZ d dlmZmZmZ G dd� de�Z G dd� de�Z
G d d
� d
e�ZdS )� N)�NativeResource)�IntEnum)�Callable�Any�Unionc @ sT e Zd ZdZdZdZdZdZdZdZ dZ
d Zd
ZdZ
dZd
ZdZdZdZdZdZdS )�AwsCborTypea CBOR data type enumeration.
Corresponds to `enum aws_cbor_type` in aws/common/cbor.h from AWS C Common Runtime.
These values represent the different types of data items that can be encoded/decoded in CBOR format
according to RFC 8949.
Attributes:
Unknown: Unknown/uninitialized type
UnsignedInt: Unsigned integer (major type 0)
NegativeInt: Negative integer (major type 1)
Float: Floating-point number (major type 7, simple value 25/26/27)
Bytes: Byte string (major type 2)
Text: Text string (major type 3)
ArrayStart: Start of definite-length array (major type 4)
MapStart: Start of definite-length map (major type 5)
Tag: Semantic tag (major type 6)
Bool: Boolean value (major type 7, simple value 20/21)
Null: Null value (major type 7, simple value 22)
Undefined: Undefined value (major type 7, simple value 23)
Break: Break stop code for indefinite-length items (major type 7, simple value 31)
IndefBytes: Start of indefinite-length byte string (major type 2)
IndefStr: Start of indefinite-length text string (major type 3)
IndefArray: Start of indefinite-length array (major type 4)
IndefMap: Start of indefinite-length map (major type 5)
r � � � � � � � � � �
� � �
� � � N)�__name__�
__module__�__qualname__�__doc__ZUnknownZUnsignedIntZNegativeIntZFloatZBytes�TextZ
ArrayStartZMapStartZTagZBool�Null� Undefined�Break�
IndefBytes�IndefStr�
IndefArray�IndefMap� r$ r$ �1/usr/lib64/python3.9/site-packages/awscrt/cbor.pyr s$ r c s e Zd ZdZ� fdd�Zed�dd�Zdd� Zed �d
d�Z e
d �dd
�Zed �dd�Ze
d �dd�Zed�dd�Zed�dd�Zed�dd�Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd$d%� Zd&d'� Zed �d(d)�Ze
d �d*d+�Zed �d,d-�Zed �d.d/�Ze d0�d1d2�Z!� Z"S )3�AwsCborEncoderaM CBOR encoder for converting Python objects to CBOR binary format.
This class provides methods to encode various Python data types into CBOR (Concise Binary Object
Representation) format as defined in RFC 8949. The encoder builds CBOR data incrementally by
calling write_* methods in sequence.
Thread Safety:
This class is NOT thread-safe. Each encoder instance should only be used from a single thread.
Create separate encoder instances for concurrent encoding operations.
Memory Management:
The encoder automatically manages internal memory and integrates with AWS CRT memory management.
Call reset() to clear internal buffers for reuse, or let the encoder be garbage collected.
Typical Usage:
```python
encoder = AwsCborEncoder()
encoder.write_int(42)
encoder.write_text("hello")
encoder.write_array_start(2)
encoder.write_bool(True)
encoder.write_null()
cbor_data = encoder.get_encoded_data()
```
For complex data structures, use write_data_item() which automatically handles nested objects:
```python
encoder = AwsCborEncoder()
data = {"numbers": [1, 2, 3], "text": "example", "flag": True}
encoder.write_data_item(data)
cbor_data = encoder.get_encoded_data()
```
c s t � �� t�� | _d S �N)�super�__init__�_awscrtZcbor_encoder_new�_binding��self�� __class__r$ r% r) [ s
zAwsCborEncoder.__init__��returnc C s t �| j�S )zqReturn the current encoded data as bytes
Returns:
bytes: The encoded data currently
)r* Zcbor_encoder_get_encoded_datar+ r, r$ r$ r% �get_encoded_data_ s zAwsCborEncoder.get_encoded_datac C s t �| j�S )a� Clear the encoder's internal buffer and reset to initial state.
After calling this method, the encoder is ready to encode new data from scratch.
Any previously encoded data is discarded and cannot be recovered.
This is useful for reusing the same encoder instance to encode multiple
independent CBOR documents without creating new encoder objects.
Note:
This operation does not raise exceptions and always succeeds.
)r* Zcbor_encoder_resetr+ r, r$ r$ r% �resetg s zAwsCborEncoder.reset)�valc C s0 |dkrt �| j|�S d| }t �| j|�S dS )a� Write an int as cbor formatted,
val less than -2^64 will be encoded as Negative bignum for CBOR
val between -2^64 to -1, inclusive, will be encode as negative integer for CBOR
val between 0 to 2^64 - 1, inclusive, will be encoded as unsigned integer for CBOR
val greater than 2^64 - 1 will be encoded as Unsigned bignum for CBOR (Not implemented yet)
Args:
val (int): value to be encoded and written to the encoded data.
r ���N)r* Zcbor_encoder_write_uintr+ Zcbor_encoder_write_negint)r- r4 Z
val_to_encoder$ r$ r% � write_intu s
zAwsCborEncoder.write_intc C s t �| j|�S )z�Write a double as cbor formatted
Encodes as the most compact CBOR representation without loss of precision.
Args:
val (float): value to be encoded and written to the encoded data.
)r* �cbor_encoder_write_floatr+ �r- r4 r$ r$ r% �write_float� s zAwsCborEncoder.write_floatc C s t �| j|�S )z�Write bytes as cbor formatted
Args:
val (bytes): value to be encoded and written to the encoded data.
)r* Zcbor_encoder_write_bytesr+ r8 r$ r$ r% �write_bytes� s zAwsCborEncoder.write_bytesc C s t �| j|�S )z�Write text as cbor formatted
Args:
val (str): value to be encoded and written to the encoded data.
)r* Zcbor_encoder_write_textr+ r8 r$ r$ r% �
write_text� s zAwsCborEncoder.write_text)�number_entriesc C s, |dk s|dkrt |� d���t�| j|�S )a< Add a start of array element.
for a number of the cbor data items to be included in the array.
`number_entries` should 0 to 2^64 inclusive.
Otherwise, ValueError will be raised.
Args:
number_entries (int): number of entries in the array to be written
r � � must be between 0 and 2^64)�
ValueErrorr* Zcbor_encoder_write_array_startr+ �r- r<