Codec¶
codec ¶
decode_decfloat ¶
Decode a DECFLOAT16 (8B) or DECFLOAT34 (16B) wire value.
Source: tests/golden/serialization/decfloat_response.bin. Never float —
that cannot hold a base-10 decimal exactly, which is the whole reason this
type exists.
Source code in src/saprfclib/codec.py
encode_decfloat ¶
Encode a value as DECFLOAT16 (width 8) or DECFLOAT34 (width 16).
Round-trips the golden fixture byte-for-byte in both directions.
Source code in src/saprfclib/codec.py
decode ¶
Decode wire bytes into a Python value for the given RFCTYPE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rfctype
|
int
|
The RFCTYPE constant identifying the ABAP data type (RFCTYPE_CHAR, RFCTYPE_INT, etc.). See saprfclib.types for the full set of constants. |
required |
data
|
bytes | bytearray | memoryview
|
Raw wire bytes to decode. All three buffer types are accepted without copying (CODEC-06). |
required |
field
|
FieldDesc
|
Descriptor carrying unicode_mode, nuc_offset/ nuc_length, uc_offset/uc_length, decimals, and type_desc. Used for STRUCTURE/TABLE layout and BCD precision. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Python-native type corresponding to the RFCTYPE — str for |
Any
|
CHAR/NUM/DATE/TIME/STRING, bytes for BYTE/XSTRING, int for |
Any
|
INT1/INT2/INT4/INT8 and all temporal extension types, float for FLOAT, |
Any
|
decimal.Decimal for BCD, dict for STRUCTURE, list[dict] for TABLE. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If rfctype is out-of-scope or unknown. |
NotImplementedError
|
For deferred types. |
Source code in src/saprfclib/codec.py
encode ¶
Encode a Python value into wire bytes for the given RFCTYPE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rfctype
|
int
|
The RFCTYPE constant identifying the ABAP data type. |
required |
value
|
Any
|
Python-native value to encode. Type must match the RFCTYPE: str for character types, int for integer types, decimal.Decimal for BCD, bytes for BYTE/XSTRING, dict for STRUCTURE, list[dict] for TABLE. |
required |
field
|
FieldDesc
|
Descriptor carrying layout, precision, and type_desc. Same as decode(). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The wire representation of value for this RFCTYPE and field |
bytes
|
descriptor. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For out-of-scope or unknown rfctype. |
NotImplementedError
|
For deferred types. |
ValueError
|
For a DECFLOAT value that does not fit the target width. |
TypeError
|
If value is the wrong Python type for the rfctype. |