Skip to content

Confusing methods in WebSocket #3816

@ogrammer

Description

@ogrammer

Hi, I found these methods in WebSocket to be confusing

/**
* Send a text message to client.
*
* @param message Text Message.
* @return This websocket.
*/
default WebSocket send(@NonNull byte[] message) {
return send(message, WriteCallback.NOOP);
}
/**
* Send a text message to client.
*
* @param message Text Message.
* @param callback Write callback.
* @return This websocket.
*/
default WebSocket send(byte[] message, @NonNull WriteCallback callback) {
return send(ByteBuffer.wrap(message), callback);
}
/**
* Send a text message to client.
*
* @param message Text message.
* @return This instance.
*/
default WebSocket send(@NonNull ByteBuffer message) {
return send(message, WriteCallback.NOOP);
}
/**
* Send a text message to client.
*
* @param message Text message.
* @param callback Write callback.
* @return This instance.
*/
WebSocket send(@NonNull ByteBuffer message, @NonNull WriteCallback callback);

I don't see the point of having methods which convert binary parameter to string value and send a text message. if i have binary, why would i send text websocket message? at least i would convert it myself in that case, and specify my own way of converting. for example the javadoc does not say what type of conversion it uses (it decodes bytes to string using utf-8). i think these methods only confuse first time users, maybe they should be deprecated so that users notice sendBinary earlier. sure, the javadoc is clear that it sends text but i still consider it a bit odd that these methods exist at all, i have not seen this kind of methods in any other websocket library

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions