PCRE2_SERIALIZE_DECODE(3)
Hi bestie π you're on the PCRE2_SERIALIZE_DECODE(3) page from the Library Functions Manual, and we're about to make serialized regex data make sense. No cap.
β¨ NAME β¨
PCRE2 - Perl-compatible regular expressions (revised API). π¦
β¨ SYNOPSIS β¨
#include <pcre2.h>
int32_t pcre2_serialize_decode(pcre2_code **codes,
int32_t number_of_codes, const uint8_t *bytes,
pcre2_general_context *gcontext);
π DESCRIPTION π
Okay so this function takes a serialized set of compiled patterns and decodes it back into a list of individual patterns. It's giving "unpack the regex besties." β¨ But plot twist: this is possible only on a host that is running the same version of PCRE2, with the same code unit width, and the host must also have the same endianness, pointer width and PCRE2_SIZE type. Highkey a matching-host situation, periodt.
The arguments for pcre2_serialize_decode() are:
codesβ pointer to a vector where the list gets builtnumber_of_codesβ number of slots in that vectorbytesβ the serialized byte streamgcontextβ pointer to a general context orNULL
The bytes argument must point to a block of data that was originally created by pcre2_serialize_encode(), though it may have been saved on disc or elsewhere in the meantime. If there are more codes in the serialized data than slots in the list, only those compiled patterns that will fit are decoded. π«Ά
The yield of the function is the number of decoded patterns, or one of the following negative error codes:
PCRE2_ERROR_BADDATAβnumber_of_codesis zero or lessPCRE2_ERROR_BADMAGICβ mismatch of id bytes inbytesPCRE2_ERROR_BADMODEβ mismatch of variable unit size or PCRE versionPCRE2_ERROR_NOMEMORYβ memory allocation failedPCRE2_ERROR_NULLβcodesorbytesisNULL
PCRE2_ERROR_BADMAGIC may mean that the data is corrupt, or that it was compiled on a system with different endianness. π So lowkey vibe-check your endianness before you panic.
There is a complete description of the PCRE2 native API in the pcre2api page and a description of the serialization functions in the pcre2serialize page. Go read those if you want the full lore. π
π Cute little sign-off: this page is from PCRE2 10.47, dated 22 April 2022. Stay iconic, bestie! π
π¦ where this page comes from
- fedora 43: pcre2-devel 10.47-1.fc43 Β· BSD-3-Clause AND FSFULLR AND X11 AND GPL-2.0-or-later AND FSFAP AND FSFUL AND GPL-3.0-or-later
- fedora 43: pcre2-devel 10.47-1.fc43 Β· BSD-3-Clause AND FSFULLR AND X11 AND GPL-2.0-or-later AND FSFAP AND FSFUL AND GPL-3.0-or-later
- fedora 44: pcre2-devel 10.47-1.fc44.1 Β· BSD-3-Clause AND FSFULLR AND X11 AND GPL-2.0-or-later AND FSFAP AND FSFUL AND GPL-3.0-or-later
- fedora 44: pcre2-devel 10.47-1.fc44.1 Β· BSD-3-Clause AND FSFULLR AND X11 AND GPL-2.0-or-later AND FSFAP AND FSFUL AND GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms