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  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NFC_COMMON_MIME_H_
18 #define NFC_COMMON_MIME_H_
19 
20 #include <stdint.h>
21 
22 #include "platform/Span.h"
23 
24 #include "nfc/ndef/RecordParser.h"
25 #include "nfc/ndef/MessageBuilder.h"
26 
27 namespace mbed {
28 namespace nfc {
29 namespace ndef {
30 namespace common {
31 
32 /**
33  * @addtogroup nfc
34  * @{
35  */
36 
37 /**
38  * Represent a mime object.
39  */
40 class Mime {
41 public:
42  /**
43  * Construct an empty Mime object.
44  */
45  Mime();
46 
47  /**
48  * Construct a mime object from its type and content
49  *
50  * @param mime_type The mime type of the object.
51  * @param content The content of the object.
52  *
53  * @note To remove the NULL terminator of the C-string of the mime_type
54  * parameter, you can use the utility function span_from_cstr.
55  */
56  Mime(
57  const Span<const uint8_t> &mime_type,
58  const Span<const uint8_t> &content
59  );
60 
61  /**
62  * Copy construct a Mime object.
63  * @param other The Mime object copied.
64  */
65  Mime(const Mime &other);
66 
67  /**
68  * Destroy a Mime object.
69  */
70  ~Mime();
71 
72  /**
73  * Copy assign a Mime object.
74  *
75  * @param other The Mime object to copy.
76  *
77  * @return a reference to this object
78  */
79  Mime &operator=(const Mime &other);
80 
81  /**
82  * Set all attributes of a mime object.
83  *
84  * @param mime_type Type of the mime object.
85  * @param content Content of the mime object.
86  *
87  * @note To remove the NULL terminator of the C-string of the mime_type
88  * parameter, you can use the utility function span_from_cstr.
89  */
90  void set_mime(
91  const Span<const uint8_t> &mime_type,
92  const Span<const uint8_t> &content
93  );
94 
95  /**
96  * Return the mime type.
97  * @return The mime type.
98  */
100 
101  /**
102  * Return the content of the mime object.
103  * @return the content of the mime object.
104  */
106 
107  /**
108  * Append into a message builder
109  */
110  bool append_as_record(
111  MessageBuilder &message_builder,
112  bool is_last_record = false
113  ) const;
114 
115  /**
116  * Compute the size of this Mime object in a ndef record.
117  *
118  * @return The size of the ndef record required to store this object.
119  */
120  size_t get_record_size() const;
121 
122 private:
123  friend class MimeParser;
124 
125  void move_data(
126  uint8_t *mime_record,
127  size_t mime_type_size,
128  size_t mime_content_size
129  );
130 
131  size_t mime_size() const;
132 
133  uint8_t *_mime;
134  size_t _type_size;
135  size_t _content_size;
136 };
137 
138 /**
139  * Parse a Mime payload.
140  */
141 class MimeParser : public GenericRecordParser<MimeParser, Mime> {
142 public:
143  bool do_parse(const Record &record, Mime &mime);
144 };
145 
146 /**
147  * @}
148  */
149 
150 } // namespace common
151 } // namespace ndef
152 } // namespace nfc
153 } // namespace mbed
154 
155 #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:40
Represent a record.
Definition: Record.h:148
~Mime()
Destroy a Mime object.
Mime & operator=(const Mime &other)
Copy assign a Mime object.
Parse a Mime payload.
Definition: Mime.h:141
Mime()
Construct an empty Mime object.
Definition: AnalogIn.h:28
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.