Low level Bytes library object for manipulating bytes data 


Can be created using allocation, BytesData or from string:

Lib.Sys.IO.Bytes.alloc(length)

create Bytes by allocation length number of bytes

length - Bytes size

Lib.Sys.IO.Bytes.ofData(b)

Returns the Bytes representation of the given BytesData.

b - BytesData object

Lib.Sys.IO.Bytes.ofString(string)

create Bytes from string

string - text to convert to Bytes object


Examples:


bytes1 = Lib.Sys.IO.Bytes.alloc(10)

bytes2 = Lib.Sys.IO.Bytes.ofString("test")


Created Bytes object has methods and read-only length property:

length

Bytes size


toString()

return string from Bytes


toHex()

return hex string


getData()

returns table of bytes object, BytesData.


getString(pos, len)

return string starting from requested position pos and limited by len size

pos - string position in Bytes object

len - string size to return

fill(pos, len, byte_value)

fill Bytes with byte_value starting from pos and len size

pos - start position for fill method

len - how many integer values to fill

byte_value - byte fill value

sub(pos, len)

copy len bytes from position pos into new Bytes object

pos - start position

len - how many bytes to copy

blit(pos, srcBytes, srcPos, len)

blit len bytes from srcBytes object starting from srcPos to pos position

pos - position blit to

srcBytes - source Bytes object

srcPos - position blit from

len - blit size

get(pos)

get byte value from selected position pos

pos - byte position

set(pos, byte_value)

set byte_value to position pos

pos - byte position

byte_value - byte set value

compare(other)

Returns 0 if the bytes of this instance and the bytes of other are identical.

Returns a negative value if the length of this instance is less than the length of other, or a positive value if the length of this instance is greater than the length of other.

In case of equal lengths, returns a negative value if the first different value in other is greater than the corresponding value in this instance; otherwise returns a positive value.

other - other bytes to compare


Examples:


local bytes = Lib.Sys.IO.Bytes.alloc(5)

print(bytes.length) -- 5


bytes.fill(0,2,65)

bytes.fill(2,3,67)


print(bytes.toString()) -- AACCC

print(bytes.toHex()) -- 4141434343


print(bytes.getString(2, 3)) -- CCC


local bytes2 = bytes.sub(0, 2)

print(bytes2.toString()) -- AA


bytes.set(0,69)

print(bytes.get(0)) -- 69


bytes.blit(2, bytes2, 0, 2)

print(bytes.toString()) -- EAAAC


Created with the Personal Edition of HelpNDoc: Full-featured Documentation generator