README: document message types; taro-ctl: fix 0-length message sending; taro-ls: fix 0-length message reading and list length off-by-1 error

This commit is contained in:
Iris Lightshard 2023-03-20 23:32:49 -06:00
parent 4521ea05a1
commit 91dd545b3d
Signed by: nilix
GPG key ID: 3B7FBC22144E6398
3 changed files with 26 additions and 10 deletions

View file

@ -4,11 +4,20 @@
## messages ## messages
Messages are in the format `[1][2:3][...]`:
- byte 1 is the message type
- bytes 2 and 3 are the length of the message, in bytes
- bytes 4 and beyond are the message itself (payload) - won't be present if the length is 0
Even messages go from `taro-ctl` to the `uxn` windows. Even messages go from `taro-ctl` to the `uxn` windows.
- `0`: mailbox list - `0`: mailbox list
- `2`: list mail in mailbox - `2`: list mail in current mailbox
Odd messages go from the `uxn` windows to `taro-ctl`. Odd messages go from the `uxn` windows to `taro-ctl`.
- `1`: change/refresh mailbox - `1`: change/refresh mailbox; payload is the mailbox to read
- `3`: mark all as read in current mailbox; no payload
- `5`: search mail; payload is the regex
- `7`: refile mail; payload is a mblaze msg number/range, a space, and then the mailbox name
- `9`: trash mail; payload is a mblaze msg number/range

View file

@ -74,19 +74,13 @@ module Taro
def write_msg(msgtype : UInt8, data : Slice) def write_msg(msgtype : UInt8, data : Slice)
msgsz = UInt16.new(data.size > 16384 ? 16384 : data.size) msgsz = UInt16.new(data.size > 16384 ? 16384 : data.size)
msgtype.to_io(@stdin_w, IO::ByteFormat::BigEndian) msgtype.to_io(@stdin_w, IO::ByteFormat::BigEndian)
if msgsz != 0 msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian)
msgsz.to_io(@stdin_w, IO::ByteFormat::BigEndian)
else
8_u16.to_io(@stdin_w, IO::ByteFormat::BigEndian)
end
if msgsz == 16384 if msgsz == 16384
@stdin_w.write(data[0..msgsz - 2]) @stdin_w.write(data[0..msgsz - 2])
10_u8.to_io(@stdin_w, IO::ByteFormat::BigEndian) 10_u8.to_io(@stdin_w, IO::ByteFormat::BigEndian)
elsif msgsz != 0 elsif msgsz != 0
@stdin_w.write(data[0..msgsz - 1]) @stdin_w.write(data[0..msgsz - 1])
else
@stdin_w.write("nothing\n".to_slice)
end end
end end

View file

@ -145,6 +145,19 @@ BRK
&count_2 &count_2
.Console/read DEI .decoding/count INC STZ .Console/read DEI .decoding/count INC STZ
#00 .decoding/counting STZ #00 .decoding/counting STZ
.decoding/count LDZ2 #0000 NEQ2 ,&has_data JCN
.decoding/msg_type LDZ
DUP MBOX_LIST NEQ ,&no_mbox_empty JCN
POP #0000 .mboxes/bytes STZ2 decode_is_done POP
,&done JMP
&no_mbox_empty
DUP MAIL_LIST NEQ ,&no_mail_empty JCN
POP
#0000 .list/bytes STZ2 decode_is_done POP
,&done JMP
&no_mail_empty
POP
&has_data
BRK BRK
@ -611,7 +624,7 @@ JMP2r
&continue INC2 ,&while JMP &continue INC2 ,&while JMP
&end &end
STHkr LB_OFFSET LDZ2 #0001 SUB2 STHr LB_LEN STZ2 POP2 POP2 STHkr LB_OFFSET LDZ2 STHr LB_LEN STZ2 POP2 POP2
JMP2r JMP2r