Теперь запакуем строку.
В этом случае следует передавать тип данных bytes.
>>> struct.pack('=s', b'a')
b'a'
Для записи слова следует указывать количество символов.
>>> struct.pack('=5s', b'hello')
b'hello'
Кстати, запакованный вид соответствует исходному тексту. Всё верно, символ есть в таблице ASCII, то есть его код попадает в диапазон 0-127, он может быть записан одним байтом и имеет визуальное представление. А вот что будет если добавить символ вне ASCII
>>> struct.pack(f'=s', b'ё')
SyntaxError: bytes can only contain ASCII literal characters.
Ошибка возникла еще на этапе создания объекта bytes, который не может содержать такой символ. Поэтому надо кодировать эти байты из строки.
>>> enc = 'ёжик'.encode('utf-8')
>>> struct.pack(f'={len(enc)}s', enc)
b'\xd1\x91\xd0\xb6\xd0\xb8\xd0\xba'
Заметьте, длина такой строки в байтах отличается от исходной длины, так как символы вне ASCII записываются двумя байтами и более. Поэтому здесь формат создаём на лету, используя получившуюся длину как каунтер токена.
#libs#basic
crDroid - Unofficial | Android 16 | Nothing Phone (2)
📝 Details:
- Version: v12.3
- Device: #Pong
- Released: 15/11/25
⬇️ Downloads: ROM and Recovery Image
⚙️ Flashing Instructions: Here
📖 Changelogs: Here
🏷 Tags: #LOS#ROM#crDroid#Unofficial
✍️Notes:
- GAPPS and Vanilla builds available
- Dolby and initial Nothing camera support available
- WFD broken
- SukiSU Ultra with SUSFS out of the box
- OTA updates are supported
- Signed with release-keys
- Use latest NOS 3 firmware
- If face any bugs report with logs
🏆Credits:
- Ghost and Chandu for DT
- Fabian & HELLBOY for Glyph
- HELLBOY for Meteoric Kernel
👤 Maintainer: @deadlylxrd
💬 Chat: @NothingPhone2
🔔 Updates: @NothingPhone2Updates
OrionOS Project - OFFICIAL | A14 | Nothing Phone (2)
Based on LineageOS & crDroidAndroid
📔 Details:
- Version: Cosmic
- Codename: #Pong
- Released: 04/08/2024
🔽 Download (Recovery) : Vanilla | Gapps
⚙️ Installation: Here
📸 Screenshots: Here
🆘 Support: Telegram
🔖 Tags : #ROM#LOS#Official#QPR3#U#NothingPhone2
✍️ Note:
- Kernel is prepatched with KSU (Download Manager)
- Clean flashing is mandatory
- Both Vanilla & Gapps Build Available
- Powershare (Wireless Reverse Charging)
- Auto brightness in Glyph
- X-Reality Engine in Colors
- MicroG should pass Integrity (Not tested)
- Game Space
- Battery Backup was pretty decent during testing.. Wait for a charging cycle to complete..
‼️ Known Bugs:
- Lock Screen Carrier Text is a bit right.. Would be fixed with next OTA of August SP
🏆 Credits
- Chandu for base device tree & Kernel
- OC'D, Miki, Unluck & Ghost for all help
- Fabian & Hellboy for PA Glyph
- Testers
😎 Maintainers: @AgBKartikey
🔔 Updates: @NothingPhone2Updates
💬 Chat: @NothingPhone2