Class bin.basebuf
This module implements common write buffer operations.
basebuf supports {u,}int{8,16,32,64}{be,le,}
methods.
All of them accepts single argument n and pushes it with corresponding casting
Functions
buf:double(n) | Pushes n as double (8 bytes) into buffer |
buf:doublele(n) | Pushes n as double (8 bytes) casting to LE into buffer |
buf:doublebe(n) | Pushes n as double (8 bytes) casting to BE into buffer |
buf:float(n) | Pushes n as float (4 bytes) into buffer |
buf:floatle(n) | Pushes n as float (4 bytes) casting to LE into buffer |
buf:floatbe(n) | Pushes n as float (4 bytes) casting to BE into buffer |
buf:ber(n) | Pushes number performing variable length encoding |
buf:char(x) | Pushes first byte of the string |
Control methods
buf:copy(src[, len=#src]) | Copies data from given string or pointer |
buf:clear([n=0]) | Rollbacks cursor to given position |
buf:dump() | Returns hexdump of the buffer |
buf:hex() | Returns hex representation (analog of string.tohex) |
buf:reader() | Creates new unsafe bin.rbuf from the buffer |
Functions
Methods- buf:double(n)
-
Pushes
n
as double (8 bytes) into bufferParameters:
- n number
- buf:doublele(n)
-
Pushes
n
as double (8 bytes) casting to LE into bufferParameters:
- n number
- buf:doublebe(n)
-
Pushes
n
as double (8 bytes) casting to BE into bufferParameters:
- n number
- buf:float(n)
-
Pushes
n
as float (4 bytes) into bufferParameters:
- n number
- buf:floatle(n)
-
Pushes
n
as float (4 bytes) casting to LE into bufferParameters:
- n number
- buf:floatbe(n)
-
Pushes
n
as float (4 bytes) casting to BE into bufferParameters:
- n number
- buf:ber(n)
-
Pushes number performing variable length encoding wikipedia
Parameters:
- n number
- buf:char(x)
-
Pushes first byte of the string
Parameters:
- x string
Control methods
- buf:copy(src[, len=#src])
-
Copies data from given string or pointer
Parameters:
- src string or pointer
- len bytes of src to copy (default #src)
- buf:clear([n=0])
-
Rollbacks cursor to given position
Parameters:
- n number (default 0)
- buf:dump()
-
Returns hexdump of the buffer
Returns:
-
string
hexdump
See also:
- buf:hex()
-
Returns hex representation (analog of string.tohex)
Returns:
-
string
hex
See also:
- buf:reader()
-
Creates new unsafe bin.rbuf from the buffer
Returns:
-
rbuf