Mbed OS Reference
Loading...
Searching...
No Matches
Text.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2018 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NFC_COMMON_TEXT_H_
19#define NFC_COMMON_TEXT_H_
20
21#include <stdint.h>
22
23#include "platform/Span.h"
24
25#include "nfc/ndef/RecordParser.h"
26#include "nfc/ndef/MessageBuilder.h"
27
28namespace mbed {
29namespace nfc {
30namespace ndef {
31namespace common {
32
33/**
34 * @addtogroup nfc
35 * @{
36 */
37
38/**
39 * Represent the well known type text.
40 */
41class Text {
42public:
43 /**
44 * Encoding of the text.
45 */
47 UTF8 = 0,//!< UTF8
48 UTF16 = 1//!< UTF16
49 };
50
51 /**
52 * Construct an empty text element.
53 */
55
56 /**
57 * Construct a text element from a data buffer and an encoding.
58 *
59 * @param text_encoding The encoding of the text.
60 * @param language_code The string of the language code.
61 * @param text The text buffer.
62 *
63 * @note To remove the NULL terminator of the C-string of the language_code
64 * and text parameters, you can use the utility function span_from_cstr.
65 */
67 encoding_t text_encoding,
68 const Span<const uint8_t> &language_code,
69 const Span<const uint8_t> &text
70 );
71
72 /**
73 * Copy construct a text element.
74 * @param to_copy
75 */
76 Text(const Text &to_copy);
77
78 /**
79 * Destroy a text element.
80 */
82
83 /**
84 * Copy assignment of another text element.
85 * @param to_copy The Text instance to copy
86 * @return a reference to this object.
87 */
88 Text &operator=(const Text &to_copy);
89
90 /**
91 * Copy a text from an external buffer.
92 *
93 * @param text_encoding The encoding of the text.
94 * @param language_code The language code of the text.
95 * @param text The text to copy.
96 *
97 * @note To remove the NULL terminator of the C-string of the language_code
98 * and text parameters, you can use the utility function span_from_cstr.
99 */
101 encoding_t text_encoding,
102 const Span<const uint8_t> &language_code,
103 const Span<const uint8_t> &text
104 );
105
106 /**
107 * Get the encoding of the text.
108 * @return The encoding of the text.
109 */
111
112 /**
113 * Return the language code.
114 * @return The language code.
115 */
117
118 /**
119 * Return the text contained in this object.
120 * @return The text contained in this object.
121 */
123
124 /**
125 * Append into a message builder
126 */
128 MessageBuilder &message_builder,
129 bool is_last_record = false
130 ) const;
131
132 /**
133 * Compute the size of this object in a ndef record.
134 *
135 * @return The size of the ndef record required to store this object.
136 */
137 size_t get_record_size() const;
138
139private:
140 friend class TextParser;
141
142 void move_data(uint8_t *text, size_t size);
143
144 uint8_t *_text_record;
145 size_t _text_record_size;
146};
147
148/**
149 * Parse a Text.
150 */
151class TextParser : public GenericRecordParser<TextParser, Text> {
152public:
153 virtual bool do_parse(const Record &record, Text &text);
154};
155
156/**
157 * @}
158 */
159
160} // namespace common
161} // namespace ndef
162} // namespace nfc
163} // namespace mbed
164
165
166#endif /* NFC_COMMON_TEXT_H_ */
Construct a NDEF Message.
Represent the well known type text.
Definition: Text.h:41
Text(const Text &to_copy)
Copy construct a text element.
encoding_t
Encoding of the text.
Definition: Text.h:46
Text(encoding_t text_encoding, const Span< const uint8_t > &language_code, const Span< const uint8_t > &text)
Construct a text element from a data buffer and an encoding.
Span< const uint8_t > get_text() const
Return the text contained in this object.
void set_text(encoding_t text_encoding, const Span< const uint8_t > &language_code, const Span< const uint8_t > &text)
Copy a text from an external buffer.
Text & operator=(const Text &to_copy)
Copy assignment of another text element.
~Text()
Destroy a text element.
Text()
Construct an empty text element.
encoding_t get_encoding() const
Get the encoding of the text.
size_t get_record_size() const
Compute the size of this object in a ndef record.
Span< const uint8_t > get_language_code() const
Return the language code.
bool append_as_record(MessageBuilder &message_builder, bool is_last_record=false) const
Append into a message builder.
Nonowning view to a sequence of contiguous elements.
Definition: Span.h:215
Represent a record.
Definition: Record.h:149