Line data Source code
1 : /*
2 : * Package : mqtt_client
3 : * Author : S. Hamblett <steve.hamblett@linux.com>
4 : * Date : 31/05/2017
5 : * Copyright : S.Hamblett
6 : */
7 :
8 : part of mqtt_client;
9 :
10 : /// Converts string data to and from the MQTT wire format
11 : class AsciiPayloadConverter implements PayloadConverter<String> {
12 : /// Processes received data and returns it as a string.
13 : String convertFromBytes(typed.Uint8Buffer messageData) {
14 1 : final Utf8Decoder decoder = new Utf8Decoder();
15 2 : return decoder.convert(messageData.toList());
16 : }
17 :
18 : /// Converts sent data from a string to a byte array.
19 : typed.Uint8Buffer convertToBytes(String data) {
20 1 : final Utf8Encoder encoder = new Utf8Encoder();
21 1 : final typed.Uint8Buffer buff = new typed.Uint8Buffer();
22 2 : buff.addAll(encoder.convert(data));
23 : return buff;
24 : }
25 : }
|