gd_alter_encoding(3)
π gd_alter_encoding β bestie, let's talk binary encodings π
okay so real quick, this is a page from the GETDATA manual set, section 3, and it's all about gd_alter_encoding(3) β the function that changes up the binary encoding of your data in a Dirfile. stick with me, it's actually so good π¦
β¨ SYNOPSIS β¨
#include <getdata.h>
int gd_alter_encoding(DIRFILE *dirfile, unsigned int encoding, int
fragment_index, int recode);
πΈ DESCRIPTION πΈ
so gd_alter_encoding() sets the binary encoding of the format specification fragment that you point at with fragment_index β and it sets it to whatever encoding you pass in, inside the dirfile(5) database that you handed over as dirfile. π
what does "binary encoding of a fragment" even mean tho? it's the encoding of the data living in the binary files that belong to the RAW fields defined in that fragment. and lowkey important: if a fragment has no RAW fields in it, its binary encoding is justβ¦ ignored. nothing to encode, nothing to care about π«Ά
the encoding argument should be one of these symbols, periodt:
GD_UNENCODEDGD_BZIP2_ENCODEDGD_FLAC_ENCODEDGD_GZIP_ENCODEDGD_LZMA_ENCODEDGD_SLIM_ENCODEDGD_SIE_ENCODEDGD_TEXT_ENCODED
and if you wanna know what all those actually mean, go read gd_open(3) and dirfile-encoding(5) β they break down every supported encoding scheme for you. no cap. β¨
now, fragment_index doesn't have to just be a normal valid fragment index. it can also be the special value GD_ALL_FRAGMENTS, which is giving "do the thing to literally every fragment in the database" energy π β it changes the encoding of all of them.
and then there's recode. this one's the main character:
- if
recodeis non-zero, this call will actually recode the binary data of the affectedRAWfields so everything matches up with the new binary encoding. π but heads up: if the fragment's encoding is encoding insensitive, or if the data type is only one byte in size, no change is made. and the I/O pointer of all affectedRAWfields gets reset to the beginning-of-frame. - if
recodeis zero, the affected binary files are left completely untouched. hands off. π
π RETURN VALUE π
when everything goes right, gd_alter_encoding() returns zero. slay. π
when it goes wrong, it returns a negative-valued error code. and here's the full roster of possible error codes, bestie:
GD_E_ACCMODEβ the dirfile you gave was opened read-only. can't change what you can't write, sorry πGD_E_ALLOCβ the library could not allocate memory. it tried, it really did.GD_E_BAD_DIRFILEβ the supplied dirfile was invalid.GD_E_BAD_INDEXβ the supplied index was out of range.GD_E_IOβ an I/O error happened while trying to recode a binary file.GD_E_PROTECTEDβ either the metadata of the given format specification fragment was protected from change, or the binary data of the fragment was protected from change and you asked for binary file recoding. protected is protected πGD_E_UNCLEAN_DBβ an error occurred while moving the recoded file into place. as a result, the database may be in an unclean state. see the NOTES section below for recovery instructions. in this case the dirfile gets flagged as invalid, to stop any further database corruption, and it should be immediately closed. like, immediately. π¨GD_E_UNKNOWN_ENCODINGβ the encoding scheme of the fragment is unknown.GD_E_UNSUPPORTEDβ the encoding scheme of the fragment does not support binary file recoding.
also! the error code gets stored in the DIRFILE object too, so you can grab it after this function returns by calling gd_error(3). and if you want a descriptive error string for whatever went down, call gd_error_string(3). π«Ά
π§ NOTES π§
a binary file recoding happens out-of-place. so because of that, you need enough space on the filesystem for the binary files of all RAW fields in the fragment, both before and after the translation. double the storage, double the vibe check. if all fragments get updated by specifying GD_ALL_FRAGMENTS, the recoding happens one fragment at a time. β¨
an error code ofGD_E_UNCLEAN_DBmeans a system error occurred while moving the re-encoded binary data into place, or while deleting the old data. if that happens, the database may be left in an unclean state. the caller should check the filesystem directly to figure out the state of the dirfile data before continuing. for recovery instructions, see the file/usr/share/doc/getdata/unclean_database_recovery.txt. πΈ
π HISTORY π
- the function
dirfile_alter_encoding()appeared inGetData-0.5.0. og era. - in
GetData-0.7.0, this function was renamed togd_alter_encoding(). glow-up. - in
GetData-0.10.0, the error return from this function changed from-1to a negative-valued error code. more info, more better.
π¦ SEE ALSO π¦
gd_error(3), gd_error_string(3), gd_encoding(3), gd_open(3), dirfile(5), dirfile-format(5)
and that's the whole page, bestie π₯° this one's from Version 0.10.0, dated 25 December 2016 β go forth and recode responsibly, mwah πβ¨π
π¦ where this page comes from
- debian bookworm: libgetdata-doc 0.11.0-6
- debian trixie: libgetdata-doc 0.11.0-15
- fedora 43: getdata-devel 0.11.0-13.fc43 Β· GPL-2.0-or-later
- fedora 43: getdata-devel 0.11.0-13.fc43 Β· GPL-2.0-or-later
- fedora 44: getdata-devel 0.11.0-14.fc44 Β· GPL-2.0-or-later
- fedora 44: getdata-devel 0.11.0-14.fc44 Β· GPL-2.0-or-later
- ubuntu jammy: libgetdata-doc 0.11.0-3ubuntu1
- ubuntu noble: libgetdata-doc 0.11.0-13
- ubuntu questing: libgetdata-doc 0.11.0-15
- ubuntu resolute: libgetdata-doc 0.11.0-17build1
- ubuntu stonking: libgetdata-doc 0.11.0-17build2
- Copyright (C) 2016 D. V. Wiebe
- Copyright (C) 2008, 2009, 2010, 2014, 2016 D. V. Wiebe
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms