-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPL: fix the process of reading data from the server. #421
Conversation
As you point out, the data format should be well-defined. We have defined the length section, but there is a confusion between instructions and data. Here is a format, I just came up with.
|
Perhaps we should put the instruction section at the beginning, because some instructions, like
And the instruction can be represented directly in bytes, without the need for a format like enum Inst {
Print = 0x01,
Load = 0x02,
// ...
} |
That looks better :) |
Maybe I can finish today.
在 2023年4月23日星期日,Shunsuke Shibayama ***@***.***> 写道:
… That looks better :)
—
Reply to this email directly, view it on GitHub
<#421 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACILBG7JJLBSHAXXY2XB57LXCP6IJANCNFSM6AAAAAAXH3XU5M>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
A simple test for socket read and write. import itertools
import random
import string
with open("./src/scripts/repl_server.py") as f:
code = f.readlines()
code.insert(0, "__PORT__ = 9000\n")
code = itertools.takewhile(lambda l: not l.startswith("# DummyVM"), code)
exec("".join(code))
class MockSocket:
def __init__(self):
self.data = bytearray()
self.cursor = 0
def send(self, data):
self.data.extend(data)
def recv(self, _bufsize):
if self.cursor >= len(self.data):
raise Exception()
# return one byte everytime
data = bytes(self.data[self.cursor : self.cursor + 1])
self.cursor += 1
return data
corr_data = "".join(random.choices(string.ascii_uppercase + string.digits, k=2048))
s = MessageStream(MockSocket())
s.send_msg(INST.PRINT, corr_data)
inst, recv_data = s.recv_msg()
assert inst == INST.PRINT
assert recv_data == corr_data |
I'll make a few edits and add this one to the test suite, ok? |
Sure, no problem. Thank you for your review and edits. |
Thank you so much! |
Fixes the bug introduced by #420
This is a brief description.
Changes proposed in this PR:
@mtshiba