Skip to content

Commit 9904164

Browse files
chore: adjust api
1 parent 0603733 commit 9904164

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

src/websocket/client.mbt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ pub async fn Client::send_binary(self : Client, data : Bytes) -> Unit {
112112
113113
///|
114114
/// Send a ping frame
115-
pub async fn Client::ping(self : Client, data? : Bytes = Bytes::new(0)) -> Unit {
115+
///
116+
/// TODO : it should be able to return a boolean
117+
/// indicating if a pong was received within a timeout
118+
async fn Client::_ping(self : Client, data? : Bytes = Bytes::new(0)) -> Unit {
116119
if self.closed is Some(code) {
117120
raise ConnectionClosed(code)
118121
}
@@ -121,7 +124,9 @@ pub async fn Client::ping(self : Client, data? : Bytes = Bytes::new(0)) -> Unit
121124
122125
///|
123126
/// Send a pong frame
124-
pub async fn Client::pong(self : Client, data? : Bytes = Bytes::new(0)) -> Unit {
127+
///
128+
/// This is done automatically, so it is not exposed in the public API
129+
async fn Client::pong(self : Client, data? : Bytes = Bytes::new(0)) -> Unit {
125130
if self.closed is Some(code) {
126131
raise ConnectionClosed(code)
127132
}

src/websocket/frame.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async fn[W : @io.Writer] write_frame(
8080
writer : W,
8181
fin : Bool,
8282
opcode : OpCode,
83-
payload : Bytes,
83+
payload : BytesView,
8484
masked : Bool,
8585
) -> Unit {
8686
let payload_len = payload.length().to_int64()
@@ -127,7 +127,7 @@ async fn[W : @io.Writer] write_frame(
127127
}
128128
let payload_arr = payload.to_fixedarray()
129129
mask_payload(payload_arr, mask)
130-
payload_arr.unsafe_reinterpret_as_bytes()
130+
payload_arr.unsafe_reinterpret_as_bytes()[:]
131131
} else {
132132
payload
133133
}

src/websocket/pkg.generated.mbti

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ impl Show for WebSocketError
2020
type Client
2121
fn Client::close(Self) -> Unit
2222
async fn Client::connect(String, String, port? : Int, headers? : Map[String, String]) -> Self
23-
async fn Client::ping(Self, data? : Bytes) -> Unit
24-
async fn Client::pong(Self, data? : Bytes) -> Unit
2523
async fn Client::receive(Self) -> Message
2624
async fn Client::send_binary(Self, Bytes) -> Unit
2725
async fn Client::send_text(Self, String) -> Unit
@@ -31,6 +29,7 @@ pub(all) enum CloseCode {
3129
GoingAway
3230
ProtocolError
3331
UnsupportedData
32+
Abnormal
3433
InvalidFramePayload
3534
PolicyViolation
3635
MessageTooBig
@@ -47,12 +46,10 @@ impl Show for Message
4746

4847
type ServerConnection
4948
fn ServerConnection::close(Self) -> Unit
50-
async fn ServerConnection::ping(Self, data? : Bytes) -> Unit
51-
async fn ServerConnection::pong(Self, data? : Bytes) -> Unit
5249
async fn ServerConnection::receive(Self) -> Message
53-
async fn ServerConnection::send_binary(Self, Bytes) -> Unit
54-
async fn ServerConnection::send_close(Self, code? : CloseCode, reason? : String) -> Unit
55-
async fn ServerConnection::send_text(Self, String) -> Unit
50+
async fn ServerConnection::send_binary(Self, BytesView) -> Unit
51+
async fn ServerConnection::send_close(Self, code? : CloseCode, reason? : BytesView) -> Unit
52+
async fn ServerConnection::send_text(Self, StringView) -> Unit
5653

5754
// Type aliases
5855

src/websocket/server.mbt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn ServerConnection::close(self : ServerConnection) -> Unit {
110110
/// Send a text message
111111
pub async fn ServerConnection::send_text(
112112
self : ServerConnection,
113-
text : String,
113+
text : StringView,
114114
) -> Unit {
115115
if self.closed is Some(code) {
116116
raise ConnectionClosed(code)
@@ -123,7 +123,7 @@ pub async fn ServerConnection::send_text(
123123
/// Send a binary message
124124
pub async fn ServerConnection::send_binary(
125125
self : ServerConnection,
126-
data : Bytes,
126+
data : BytesView,
127127
) -> Unit {
128128
if self.closed is Some(code) {
129129
raise ConnectionClosed(code)
@@ -133,7 +133,10 @@ pub async fn ServerConnection::send_binary(
133133

134134
///|
135135
/// Send a ping frame
136-
pub async fn ServerConnection::ping(
136+
///
137+
/// TODO : it should be able to return a boolean
138+
/// indicating if a pong was received within a timeout
139+
async fn ServerConnection::_ping(
137140
self : ServerConnection,
138141
data? : Bytes = Bytes::new(0),
139142
) -> Unit {
@@ -145,7 +148,9 @@ pub async fn ServerConnection::ping(
145148

146149
///|
147150
/// Send a pong frame
148-
pub async fn ServerConnection::pong(
151+
///
152+
/// It is done automatically, so it is not exposed in the public API
153+
async fn ServerConnection::pong(
149154
self : ServerConnection,
150155
data? : Bytes = Bytes::new(0),
151156
) -> Unit {

0 commit comments

Comments
 (0)