iobridge/v0.1.md
2024-02-13 12:04:05 +00:00

82 lines
3.7 KiB
Markdown

```
Numbers: Big Endian.
Input strings not null terminated unless explicitly stated.
Outgoing API:
0x00 - reserved
0x01 - read line from stdin; returns a 0x01 packet.
0x02 [len: u32, data: u8[]] - write to stdout
0x03 [len: u32, data: u8[]] - write to stderr
0x04 - read a byte from stdin; returns a 0x04 packet.
0x05 [byte: u8] - write a byte to stdout
0x06 [byte: u8] - write a byte to stderr
0x07 [len: u32] - read from stdin. returns a 0x07 packet.
0x08 [len: u32] - allocate a buffer of len bytes. returns a 0x08 packet.
0x09 [ptr: u32] - free a buffer allocated at ptr.
0x0A [ptr: u32, off: u32, len: u32] - read len bytes from ptr + off. returns a 0x0A packet.
0x0B [ptr: u32, off: u32, len: u32, data: u8[]] - write len bytes to ptr + off.
0x0C [ptr: u32] - query the size of the buffer allocated at ptr. returns a 0x0C packet.
0x0D [ptr: u32, new_len: u32] - resize the buffer allocated at ptr to new_len bytes.
Expect null-terminated data:
* 0x0E [len: u32, mode: u32, data: u8[]] - open a file (fopen). returns a 0x0E packet.
0x0F [ptr: u32] - close a file (fclose).
0x10 [ptr: u32, len: u32] - read len bytes from file. returns a 0x10 packet.
0x11 [ptr: u32, len: u32] - write len bytes to file.
0x12 [ptr: u32] - query the size of the file. returns a 0x12 packet.
0x13 [ptr: u32, off: u32, whence: u8]: seek to off bytes from whence
(0-backwards,1-forwards,2-from beginning,3-from end).
Expect null-terminated data:
* 0x14 [len: u32, len2: u32, data1: u8[], data2: u8[]] - rename.
* 0x15 [len: u32, data: u8[]] - unlink.
* 0x16 [len: u32, data: u8[]] - mkdir.
* 0x17 [len: u32, data: u8[]] - rmdir.
* 0x18 [len: u32, data: u8[]] - chdir.
0x19 - getcwd, returns a 0x19 packet.
0x1A - UNIX time, returns a 0x1A packet.
0x1B - local time, returns a 0x1B packet.
0x1C - GMT, returns a 0x1C packet.
0x1D [time: u32] - sleep for n ms.
0x1E - put terminal in raw mode (if platform supports that).
0x1F - put terminal in cooked mode (if platform supports that).
0x20 - get terminal size, returns a 0x20 packet.
0x21 [ptr: u32] - flush file.
0x22 - flush stdout.
0x23 - get errno state. returns a 0x23 packet.
Expect null-terminated data:
* 0x24 [len: u32, data: u8[]] - file exists? returns a 0x24 packet.
* 0x25 [len: u32, data: u8[]] - list directory entries. returns a 0x25 packet.
0x26 - API version. returns a 0x26 packet.
0x27 - Host environment. returns a 0x27 packet.
Incoming API:
0x01 [len: u32] [data: u8[]] - line read from stdin.
0x04 [byte: u16] - byte read from stdin.
0x07 [len: u32] [data: u8[]] - data read from stdin.
0x08 [ptr: u32] - buffer allocated at ptr (ptr = 0 if unable to allocate).
0x0A [len: u32] [data: u8[]] - data read from ptr + off.
0x0C [len: u32] - size of the buffer allocated at ptr.
0x0E [ptr: u32] - file opened at ptr (ptr = 0 if unable to open).
0x10 [len: u32] [data: u8[]] - data read from file.
0x12 [len: u32] - size of the file.
0x19 [len: u32] [data: u8[]] - current working directory (len = 0 if unable to determine).
0x1A [time: u64] - UNIX time.
0x1B [year: u32, month: u8, day: u8, hour: u8, minute: u8, second: u8] - local time.
0x1C [year: u32, month: u8, day: u8, hour: u8, minute: u8, second: u8] - GMT.
0x20 [width: u16, height: u16] - terminal size (or 0 if unknown).
0x23 [error: u8] - error state.
0x24 [exists: u8] - exists?
0x25 [no: u32, (len: u32, path: u8[], size: u32, type: u8)[]] - list directory entries.
0x26 [major: u8, minor: u8] - API version (0, 1).
0x27 [len: u32, data: u8[]] - Host environment.
```