From c71698bda8cbb26c737a973e361fc2fc68544133 Mon Sep 17 00:00:00 2001 From: Laurent Pelecq Date: Sun, 27 Mar 2022 20:02:24 +0200 Subject: [PATCH] Implement history_get_client_id --- src/client.rs | 10 +++++++++- tests/fifo_sync_tests.rs | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index e91765f..1ce21ee 100644 --- a/src/client.rs +++ b/src/client.rs @@ -299,7 +299,7 @@ impl Client { Request::Begin => send_one_line!(self, "BLOCK BEGIN"), Request::End => send_one_line!(self, "BLOCK END"), Request::HistoryGetClients => send_one_line!(self, "HISTORY GET CLIENT_LIST"), - Request::HistoryGetClientId => panic!("not implemented"), + Request::HistoryGetClientId => send_one_line!(self, "HISTORY GET CLIENT_ID"), Request::HistoryGetClientMsgs(_scope, _start, _number) => panic!("not implemented"), Request::HistoryGetLastMsgId => panic!("not implemented"), Request::HistoryGetMsg(_id) => panic!("not implemented"), @@ -734,6 +734,14 @@ impl Client { }) } + /// Receive client id + pub fn receive_client_id(&mut self) -> ClientResult { + self.receive_string(OK_CLIENT_ID_SENT).and_then(|s| { + s.parse() + .map_err(|_| ClientError::invalid_data("invalid client id")) + }) + } + /// Receive a list of synthesis voices pub fn receive_synthesis_voices(&mut self) -> ClientResult> { self.receive_lines(OK_VOICES_LIST_SENT) diff --git a/tests/fifo_sync_tests.rs b/tests/fifo_sync_tests.rs index 0aab359..c0bf8f9 100644 --- a/tests/fifo_sync_tests.rs +++ b/tests/fifo_sync_tests.rs @@ -422,3 +422,12 @@ fn history_clients_list() -> ClientResult<()> { }, ) } + +test_getter!( + history_get_client_id, + receive_client_id, + (), + "HISTORY GET CLIENT_ID\r\n", + "245-123\r\n245 OK CLIENT ID SENT\r\n", + 123 +);