Skip to content

Commit 46f3442

Browse files
authored
Merge pull request #51 from gilmaimon/change-to-stl-strings-only
Change to stl strings only
2 parents 8c391ce + 61ca151 commit 46f3442

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ void loop() {
176176
```
177177
***Note:** for ESP32 you only need to change to code that connects to WiFi (replace `#include <ESP8266WiFi.h>` with `#include <WiFi.h>`), everything else stays the same.*
178178

179+
## Binary Data
180+
181+
For binary data it is recommended to use `msg.rawData()` which returns a `std::string`, or `msg.c_str()` which returns a `const char*`.
182+
The reason is that `msg.data()` returns an Arduino `String`, which is great for Serial printing and very basic memory handling but bad for most binary usages.
183+
184+
See [issue #32](https://github.com/gilmaimon/ArduinoWebsockets/issues/32) for further information.
185+
179186
## SSL and WSS Support
180187

181188
No matter what board you are using, in order to use WSS (websockets over SSL) you need to use
@@ -285,4 +292,5 @@ Thanks for everyone who reported a bug, suggested a feature and contributed to t
285292
- **10/08/2019 (v0.4.10)** - Patch - Bugfix. Fixed a bug (and general in-stability) caused from unchecked and unsafe read operations on sockets. Also improved memory usage and management. Thank you [Jonty](https://github.com/Jonty) for openning and helping with the [issue](https://github.com/gilmaimon/ArduinoWebsockets/issues/26)!
286293
- **14/09/2019 (v0.4.11)** - Bugfixes - masking settings used to not get copied when using assignment between `WebsocketClient` instances. Also handshake validation is now case insensitive. Thank you [logdog2709](https://github.com/logdog2709) for pointing out the [issue](https://github.com/gilmaimon/ArduinoWebsockets/issues/34).
287294
- **12/10/2019 (v0.4.12)** - Patch - Messages are now sent as a single TCP buffer instead of separate messages. Thank you [elC0mpa](https://github.com/elC0mpa) for posting the [issue](https://github.com/gilmaimon/ArduinoWebsockets/issues/44).
288-
- **19/10/2019 (v0.4.13)** - Patch - added `yield` calls in order to prevent software-watchdog resets on esp8266 (on long messages). Thank you [elC0mpa](https://github.com/elC0mpa) for documenting and helping with the [issue](https://github.com/gilmaimon/ArduinoWebsockets/issues/43).
295+
- **19/10/2019 (v0.4.13)** - Patch - added `yield` calls in order to prevent software-watchdog resets on esp8266 (on long messages). Thank you [elC0mpa](https://github.com/elC0mpa) for documenting and helping with the [issue](https://github.com/gilmaimon/ArduinoWebsockets/issues/43).
296+
- **22/11/2019 (v0.4.14)** - Added `rawData` and `c_str` as acccessors in `WebsocketsMessage` so now the raw data can be acccessed which should solve issue #32 and not break any existing sketch.

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ isLast KEYWORD2
4545
WebsocketsMessage KEYWORD1
4646
data KEYWORD2
4747
type KEYWORD2
48+
rawData KEYWORD2
49+
c_str KEYWORD2
4850

4951
WebsocketsEvent KEYWORD1
5052
ConnectionOpened LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ArduinoWebsockets
2-
version=0.4.13
2+
version=0.4.14
33
author=Gil Maimon <[email protected]>
44
maintainer=Gil Maimon <[email protected]>
55
sentence=A library for writing modern Websockets applications with Arduino.

src/tiny_websockets/message.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace websockets {
1919
// The class the user will interact with as a message
2020
// This message can be partial (so practically this is a Frame and not a message)
2121
struct WebsocketsMessage {
22-
WebsocketsMessage(MessageType msgType, WSString msgData, MessageRole msgRole = MessageRole::Complete) : _type(msgType), _length(msgData.size()), _data(internals::fromInternalString(msgData)), _role(msgRole) {}
22+
WebsocketsMessage(MessageType msgType, const WSString& msgData, MessageRole msgRole = MessageRole::Complete) : _type(msgType), _length(msgData.size()), _data(msgData), _role(msgRole) {}
2323
WebsocketsMessage() : WebsocketsMessage(MessageType::Empty, "", MessageRole::Complete) {}
2424

2525
static WebsocketsMessage CreateFromFrame(internals::WebsocketsFrame frame, MessageType overrideType = MessageType::Empty) {
@@ -68,7 +68,10 @@ namespace websockets {
6868
bool isLast() const { return this->_role == MessageRole::Last; }
6969

7070

71-
WSInterfaceString data() const { return this->_data; }
71+
WSInterfaceString data() const { return internals::fromInternalString(this->_data); }
72+
const WSString& rawData() const { return this->_data; }
73+
const char* c_str() const { return this->_data.c_str(); }
74+
7275
uint32_t length() const { return this->_length; }
7376

7477
class StreamBuilder {
@@ -177,7 +180,7 @@ namespace websockets {
177180
private:
178181
const MessageType _type;
179182
const uint32_t _length;
180-
const WSInterfaceString _data;
183+
const WSString _data;
181184
const MessageRole _role;
182185
};
183186
}

0 commit comments

Comments
 (0)