mruby-pack: document BER format ('w') template directive

- add 'w' directive to supported template table
- provide BER encoding/decoding usage example
- describe as variable length encoding (no endianness concept)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-08-12 18:36:48 +09:00
parent 57d37fdfc1
commit 32ad871f5d
+8
View File
@@ -53,6 +53,13 @@ arr2 = binary_data2.unpack("C3") # Unpacks three 8-bit unsigned integers
binary_data3 = "Hello\x00World"
arr3 = binary_data3.unpack("Z*Z*") # Unpacks two null-terminated strings
# arr3 will be ["Hello", "World"]
# BER (Basic Encoding Rules) example
arr4 = [127, 128, 16383]
binary_data4 = arr4.pack("w*") # BER-encodes integers of varying sizes
# binary_data4 will contain BER-compressed data
arr4_unpacked = binary_data4.unpack("w*") # Decodes BER data back to integers
# arr4_unpacked will be [127, 128, 16383]
```
## Supported Template Directives
@@ -93,6 +100,7 @@ Here is a list of supported template characters and their meanings:
| `U` | UTF-8 character |
| `V` | 32-bit unsigned integer, VAX (little-endian) byte order |
| `v` | 16-bit unsigned integer, VAX (little-endian) byte order |
| `w` | BER-compressed integer (variable length encoding) |
| `x` | Null byte (skip forward one byte) |
| `X` | Back up one byte |
| `Z` | Null-terminated string (when unpacking, reads until NULL; when packing, appends a NULL if count is `*`) |