Mistake on this page?
Report an issue in GitHub or email us
Mime.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_MIME_H_
19 #define NFC_COMMON_MIME_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 
28 namespace mbed {
29 namespace nfc {
30 namespace ndef {
31 namespace common {
32 
33 /**
34  * @addtogroup nfc
35  * @{
36  */
37 
38 /**
39  * Represent a mime object.
40  */
41 class Mime {
42 public:
43  /**
44  * Construct an empty Mime object.
45  */
46  Mime();
47 
48  /**
49  * Construct a mime object from its type and content
50  *
51  * @param mime_type The mime type of the object.
52  * @param content The content of the object.
53  *
54  * @note To remove the NULL terminator of the C-string of the mime_type
55  * parameter, you can use the utility function span_from_cstr.
56  */
57  Mime(
58  const Span<const uint8_t> &mime_type,
59  const Span<const uint8_t> &content
60  );
61 
62  /**
63  * Copy construct a Mime object.
64  * @param other The Mime object copied.
65  */
66  Mime(const Mime &other);
67 
68  /**
69  * Destroy a Mime object.
70  */
71  ~Mime();
72 
73  /**
74  * Copy assign a Mime object.
75  *
76  * @param other The Mime object to copy.
77  *
78  * @return a reference to this object
79  */
80  Mime &operator=(const Mime &other);
81 
82  /**
83  * Set all attributes of a mime object.
84  *
85  * @param mime_type Type of the mime object.
86  * @param content Content of the mime object.
87  *
88  * @note To remove the NULL terminator of the C-string of the mime_type
89  * parameter, you can use the utility function span_from_cstr.
90  */
91  void set_mime(
92  const Span<const uint8_t> &mime_type,
93  const Span<const uint8_t> &content
94  );
95 
96  /**
97  * Return the mime type.
98  * @return The mime type.
99  */
101 
102  /**
103  * Return the content of the mime object.
104  * @return the content of the mime object.
105  */
107 
108  /**
109  * Append into a message builder
110  */
111  bool append_as_record(
112  MessageBuilder &message_builder,
113  bool is_last_record = false
114  ) const;
115 
116  /**
117  * Compute the size of this Mime object in a ndef record.
118  *
119  * @return The size of the ndef record required to store this object.
120  */
121  size_t get_record_size() const;
122 
123 private:
124  friend class MimeParser;
125 
126  void move_data(
127  uint8_t *mime_record,
128  size_t mime_type_size,
129  size_t mime_content_size
130  );
131 
132  size_t mime_size() const;
133 
134  uint8_t *_mime;
135  size_t _type_size;
136  size_t _content_size;
137 };
138 
139 /**
140  * Parse a Mime payload.
141  */
142 class MimeParser : public GenericRecordParser<MimeParser, Mime> {
143 public:
144  bool do_parse(const Record &record, Mime &mime);
145 };
146 
147 /**
148  * @}
149  */
150 
151 } // namespace common
152 } // namespace ndef
153 } // namespace nfc
154 } // namespace mbed
155 
156 #endif /* NFC_COMMON_MIME_H_ */
Construct a NDEF Message.
Span< const uint8_t > get_mime_content() const
Return the content of the mime object.
Span< const uint8_t > get_mime_type() const
Return the mime type.
size_t get_record_size() const
Compute the size of this Mime object in a ndef record.
bool append_as_record(MessageBuilder &message_builder, bool is_last_record=false) const
Append into a message builder.
Represent a mime object.
Definition: Mime.h:41
Represent a record.
Definition: Record.h:149
~Mime()
Destroy a Mime object.
Mime & operator=(const Mime &other)
Copy assign a Mime object.
Parse a Mime payload.
Definition: Mime.h:142
Mime()
Construct an empty Mime object.
Definition: ATHandler.h:46
void set_mime(const Span< const uint8_t > &mime_type, const Span< const uint8_t > &content)
Set all attributes of a mime object.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.