// //------------------ DOK FILE -------------------------------------------------- +Header bytesLib =pkg bios =title Bytes array =short mutable arrays of bytes =desc // // //------------------ PROTO ----------------------------------------------------- Bytes +Proto Bytes =type Bytes =mode type =pkg bios =impl native =link =desc [[Bytes]] is the Minimacy type for mutable arrays of bytes. Once created it is not possible to change the size of such arrays. // // //------------------ PROTO ----------------------------------------------------- bytesClear +Proto bytesClear =type fun Bytes Int -> Bytes =mode function =pkg bios =impl native =link =desc This function clears the src with the byte value. // +arg src =type Bytes =desc An array of bytes // +arg value =type Int =desc An integer more likely between 0 and 255 // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesCopy +Proto bytesCopy =type fun Bytes Int Str Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function copies a substring of src starting at srcOffset into dst starting at position dstOffset. length is the number of bytes to copy. nil means 'everything'. When dstOffset and srcOffset are negative they are counted from the end of dst or src. The function returns nil if the copy is not possible, when the position in dst or in src is outside. // +arg dst =type Bytes =desc An array of bytes // +arg dstOffset =type Int =desc A position in dst // +arg src =type Str =desc A string // +arg srcOffset =type Int =desc A position in src // +arg length =type Int =desc The number of bytes to copy, or nil to copy until the end // +arg result =type Bytes =desc The array dst or nil // // //------------------ PROTO ----------------------------------------------------- bytesCreate +Proto bytesCreate =type fun Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function creates an array of bytes, by specifying its length and the initial value for all its bytes. // +arg length =type Int =desc A positive integer // +arg value =type Int =desc A byte value // +arg result =type Bytes =desc A new array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesSlice +Proto bytesSlice =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function extracts a substring from the array of bytes src, and returns it as an array of bytes. When the offset is negative it is counted from the end of src. See [[strSlice]]. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc An integer // +arg len =type Int =desc Another integer // +arg result =type Bytes =desc An array of bytes copied from src // // //------------------ PROTO ----------------------------------------------------- bytesSliceOfStr +Proto bytesSliceOfStr =type fun Bytes Int Int -> Str =mode function =pkg bios =impl native =link =desc This function extracts a substring from the array of bytes src. When the offset is negative it is counted from the end of src. See [[strSlice]]. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc An integer // +arg len =type Int =desc Another integer // +arg result =type Str =desc A string copied from src // // //------------------ PROTO ----------------------------------------------------- bytesGet +Proto bytesGet =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the value at position index in the array of bytes src. It returns nil when index is outside src. // +arg src =type Bytes =desc An array of bytes // +arg index =type Int =desc A position in the array of bytes // +arg result =type Int =desc A byte or nil // // //------------------ PROTO ----------------------------------------------------- bytesInit +Proto bytesInit =type fun Int (fun Int -> Int) -> Bytes =mode function =pkg bios =impl mcy =link =desc This function returns a new array of bytes of the specified length, where each value is computed by the fInit function. // +arg length =type Int =desc An integer // +arg fInit =type fun Int -> Int =desc A function which provides a value for each index between 0 and length-1 // +arg result =type Bytes =desc An array of length bytes initialized with the values provided by the fInit function // // //------------------ PROTO ----------------------------------------------------- bytesLSL1 +Proto bytesLSL1 =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function performs a logical shift left of 1 bit in the array of bytes, considered as MSB. The carry is added to the last byte of src, and the function returns the carry out of the first byte. // +arg src =type Bytes =desc An array of bytes // +arg B =type Int =desc A carry (should be 0 or 1) // +arg result =type Int =desc The resulting carry // // //------------------ PROTO ----------------------------------------------------- bytesLength +Proto bytesLength =type fun Bytes -> Int =mode function =pkg bios =impl native =link =desc This function returns the length of the array of bytes. // +arg src =type Bytes =desc An array of bytes // +arg result =type Int =desc An integer // // //------------------ PROTO ----------------------------------------------------- bytesRand +Proto bytesRand =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function fills a portion of src with random data, based on the hardware random generator. When offset is negative it is counted from the end. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg length =type Int =desc A length // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesRead16Lsb +Proto bytesRead16Lsb =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a 16 bits integer from position offset in src in LSB. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A 16 bits value // // //------------------ PROTO ----------------------------------------------------- bytesRead16Msb +Proto bytesRead16Msb =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a 16 bits integer from position offset in src in MSB. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A 16 bits value // // //------------------ PROTO ----------------------------------------------------- bytesRead24Lsb +Proto bytesRead24Lsb =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a 24 bits integer from position offset in src in LSB. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A 24 bits value // // //------------------ PROTO ----------------------------------------------------- bytesRead24Msb +Proto bytesRead24Msb =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a 24 bits integer from position offset in src in MSB. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A 24 bits value // // //------------------ PROTO ----------------------------------------------------- bytesRead32Lsb +Proto bytesRead32Lsb =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a 32 bits integer from position offset in src in LSB. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A 32 bits value // // //------------------ PROTO ----------------------------------------------------- bytesRead32Msb +Proto bytesRead32Msb =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a 32 bits integer from position offset in src in MSB. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A 32 bits value // // //------------------ PROTO ----------------------------------------------------- bytesRead8 +Proto bytesRead8 =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function reads one byte at position offset in src. It is the same function as [[bytesGet]]. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A 8 bits value // // //------------------ PROTO ----------------------------------------------------- bytesReadVarInt +Proto bytesReadVarInt =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a variable-length signed integer from position offset in src. See [[strReadVarInt]] for information about this encoding. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc An integer // // //------------------ PROTO ----------------------------------------------------- bytesReadVarUInt +Proto bytesReadVarUInt =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function decodes a variable-length unsigned integer from position offset in src. See [[strReadVarUInt]] for information about this encoding. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc A positive integer // // //------------------ PROTO ----------------------------------------------------- bytesSet +Proto bytesSet =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function sets the value at position offset in src. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A byte value // +arg result =type Bytes =desc The array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesSwapStr +Proto bytesSwapStr =type fun Str -> Bytes =mode function =pkg bios =impl native =link =desc This function is the same as [[strSwap]], except that the result is an array of bytes instead of a string. // +arg A =type Str =desc A string // +arg result =type Bytes =desc An array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesVarIntNext +Proto bytesVarIntNext =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function assume that a variable-length signed value is encoded at position offset in the src. The function returns the offset of the byte just after the variable-length signed value encoding. This function is the same as [[strVarIntNext]] for strings. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc The next offset // // //------------------ PROTO ----------------------------------------------------- bytesVarUIntNext +Proto bytesVarUIntNext =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function assume that a variable-length unsigned value is encoded at position offset in the src. The function returns the offset of the byte just after the variable-length unsigned value encoding. This function is the same as [[strVarUIntNext]] for strings. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg result =type Int =desc The next offset // // //------------------ PROTO ----------------------------------------------------- bytesWrite16Lsb +Proto bytesWrite16Lsb =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function writes a 16 bits integer from position offset in src in LSB. It does nothing if the offset is out of range. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A 16 bits value // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWrite16Msb +Proto bytesWrite16Msb =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function writes a 16 bits integer from position offset in src in MSB. It does nothing if the offset is out of range. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A 16 bits value // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWrite24Lsb +Proto bytesWrite24Lsb =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function writes a 24 bits integer from position offset in src in LSB. It does nothing if the offset is out of range. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A 24 bits value // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWrite24Msb +Proto bytesWrite24Msb =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function writes a 24 bits integer from position offset in src in MSB. It does nothing if the offset is out of range. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A 24 bits value // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWrite32Lsb +Proto bytesWrite32Lsb =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function writes a 32 bits integer from position offset in src in LSB. It does nothing if the offset is out of range. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A 32 bits value // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWrite32Msb +Proto bytesWrite32Msb =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function writes a 32 bits integer from position offset in src in MSB. It does nothing if the offset is out of range. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A 32 bits value // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWrite8 +Proto bytesWrite8 =type fun Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function writes a byte at position offset in src in LSB. It does nothing if the offset is out of range. This function is the same as [[bytesSet]]. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A 8 bits value // +arg result =type Bytes =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWriteVarInt +Proto bytesWriteVarInt =type fun Bytes Int Int -> Int =mode function =pkg bios =impl native =link =desc This function writes a variable-length signed integer from position offset in src. It does nothing if the offset is out of range. See [[strReadVarInt]] for information about this format. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc An integer // +arg result =type Int =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesWriteVarUInt +Proto bytesWriteVarUInt =type fun Bytes Int Int -> Int =mode function =pkg bios =impl native =link =desc This function writes a variable-length unsigned integer from position offset in src. It does nothing if the offset is out of range. See [[strReadVarUInt]] for information about this format. // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A position in the array of bytes // +arg value =type Int =desc A positive integer // +arg result =type Int =desc The same array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesXorBytes +Proto bytesXorBytes =type fun Bytes Int Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function is the same as [[bytesXor]] except the source src is an array of bytes. // +arg dst =type Bytes =desc An array of bytes // +arg dstOffset =type Int =desc A position in dst // +arg src =type Bytes =desc An array of bytes // +arg srcOffset =type Int =desc A position in src // +arg length =type Int =desc The number of bytes to copy, or nil to copy until the end // +arg result =type Bytes =desc The array dst or nil // // //------------------ PROTO ----------------------------------------------------- bytesXor +Proto bytesXor =type fun Bytes Int Str Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function performs a XOR operation of a substring of src starting at srcOffset on dst starting at position dstOffset. length is the number of bytes to process. nil means 'everything'. When dstOffset and srcOffset are negative they are counted from the end of dst or src. The function returns nil if the operation is not possible, when the position in dst or in src is outside. // +arg dst =type Bytes =desc An array of bytes // +arg dstOffset =type Int =desc A position in dst // +arg src =type Str =desc A string // +arg srcOffset =type Int =desc A position in src // +arg length =type Int =desc The number of bytes to copy, or nil to copy until the end // +arg result =type Bytes =desc The array dst or nil // // //------------------ PROTO ----------------------------------------------------- bytesBuild +Proto bytesBuild =type fun a1 -> Bytes =mode function =pkg bios =impl native =link =desc This function creates a new string representation from any data. It is similar to [[strBuild]] except it returns an array of bytes. // +arg data =type a1 =desc Any data // +arg result =type Bytes =desc A array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesLeft +Proto bytesLeft =type fun Bytes Int -> Bytes =mode function =pkg bios =impl native =link =desc This function is similar to [[strLeft]], except it works on an array of bytes and returns an array of bytes. // +arg src =type Bytes =desc An array of bytes // +arg length =type Int =desc An integer // +arg result =type Bytes =desc The prefix // // //------------------ PROTO ----------------------------------------------------- bytesRight +Proto bytesRight =type fun Bytes Int -> Bytes =mode function =pkg bios =impl native =link =desc This function is similar to [[strRight]], except it works on an array of bytes and returns an array of bytes. // +arg src =type Bytes =desc An array of bytes // +arg length =type Int =desc An integer // +arg result =type Bytes =desc The suffix // // //------------------ PROTO ----------------------------------------------------- bytesFromStr +Proto bytesFromStr =type fun Str -> Bytes =mode function =pkg bios =impl native =link =desc This function creates a new array of bytes with the same content as the string. // +arg src =type Str =desc Any string // +arg result =type Bytes =desc An array of bytes // // //------------------ PROTO ----------------------------------------------------- bytesCopyBytes +Proto bytesCopyBytes =type fun Bytes Int Bytes Int Int -> Bytes =mode function =pkg bios =impl native =link =desc This function copies a substring of src starting at srcOffset into dst starting at position dstOffset. length is the number of bytes to copy. nil means 'everything'. When dstOffset and srcOffset are negative they are counted from the end of dst or src. The function returns nil if the copy is not possible, when the position in dst or in src is outside. // +arg dst =type Bytes =desc An array of bytes // +arg dstOffset =type Int =desc A position in dst // +arg src =type Bytes =desc An array of bytes // +arg srcOffset =type Int =desc A position in src // +arg length =type Int =desc The number of bytes to copy, or nil to copy until the end // +arg result =type Bytes =desc The array dst or nil // // //------------------ PROTO ----------------------------------------------------- bytesCmp +Proto bytesCmp =type fun Bytes Bytes -> Int =mode Function =pkg bios =impl native =link =desc This function returns the result of the comparison between two array of bytes: - 0: p and q are equals - -1: p is before q in ascii order - 1: p is after q in ascii order This is the equivalent of [[strCmp]] for array of bytes. // +arg p =type Bytes =desc An array of bytes // +arg q =type Bytes =desc Another array of bytes // +arg result =type Int =desc 0, 1, or -1