Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
m2mtlvdeserializer.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "mbed-client/m2mvector.h" 00017 #include "mbed-client/m2mobject.h" 00018 #include "mbed-client/m2mobjectinstance.h" 00019 #include "mbed-client/m2mresource.h" 00020 00021 /** 00022 * @brief M2MTLVDeserializer 00023 * TLV Deserialiser get the object instances and resources as binary data and 00024 * builds the <code>lwm2m</code> representation from it. See OMA-LWM2M 00025 * specification, chapter 6.1 for the resource model and chapter 6.3.3 for 00026 * the OMA-TLV specification. 00027 */ 00028 class M2MTLVDeserializer { 00029 00030 public : 00031 00032 typedef enum { 00033 None, 00034 NotFound, 00035 NotAllowed, 00036 NotValid, 00037 OutOfMemory 00038 } Error; 00039 00040 typedef enum { 00041 Put, 00042 Post 00043 } Operation; 00044 00045 00046 /** 00047 * This method checks whether the given binary encodes an object instance 00048 * or something else. It returns <code>true</code> if bits 7-6 of the first 00049 * byte is "00". 00050 * @param tlv Binary to be checked as LWM2M object instance 00051 * @return <code>true</code> or <code>false</code>. 00052 */ 00053 static bool is_object_instance(const uint8_t *tlv); 00054 00055 /** 00056 * This method checks whether the given binary encodes a resource or 00057 * something else. It returns <code>true</code> if bits 7-6 of the first 00058 * byte is "11". 00059 * @param tlv Binary to be checked as LWM2M resource. 00060 * @return <code>true</code> or <code>false</code>. 00061 */ 00062 static bool is_resource(const uint8_t *tlv); 00063 00064 /** 00065 * This method checks whether the given binary encodes a multiple resource 00066 * or something else. It returns <code>true</code> if bits 7-6 of the first 00067 * byte is "10". 00068 * @param tlv Binary to be checked as LWM2M multiple resource. 00069 * @return <code>true</code> or <code>false</code>. 00070 */ 00071 static bool is_multiple_resource(const uint8_t *tlv); 00072 00073 /** 00074 * This method checks whether the given binary encodes a resource instance 00075 * or something else. It returns <code>true</code> if bits 7-6 of the first 00076 * byte is "01". 00077 * @param tlv Binary to be checked as LWM2M resource instance. 00078 * @return <code>true</code> or <code>false</code>. 00079 */ 00080 static bool is_resource_instance(const uint8_t *tlv); 00081 00082 /** 00083 * Deserialises the given binary that must encode object instances. Binary 00084 * array can be checked before invoking this method with 00085 */ 00086 static M2MTLVDeserializer::Error deserialise_object_instances(const uint8_t* tlv, 00087 uint32_t tlv_size, 00088 M2MObject &object, 00089 M2MTLVDeserializer::Operation operation); 00090 00091 /** 00092 * Deserialises the given binary that must encode resources. Binary array 00093 * can be checked before invoking this method. 00094 */ 00095 static M2MTLVDeserializer::Error deserialize_resources(const uint8_t *tlv, 00096 uint32_t tlv_size, 00097 M2MObjectInstance &object_instance, 00098 M2MTLVDeserializer::Operation operation); 00099 00100 /** 00101 * Deserialises the given binary that must encode resource instances. Binary array 00102 * can be checked before invoking this method. 00103 */ 00104 static M2MTLVDeserializer::Error deserialize_resource_instances(const uint8_t *tlv, 00105 uint32_t tlv_size, 00106 M2MResource &resource, 00107 M2MTLVDeserializer::Operation operation); 00108 /** 00109 * This method return object instance id or resource id. 00110 * @param tlv Binary to be checked 00111 * @return Object instance id or resource id. 00112 */ 00113 static uint16_t instance_id(const uint8_t *tlv); 00114 00115 private: 00116 00117 static M2MTLVDeserializer::Error deserialize_object_instances(const uint8_t *tlv, 00118 uint32_t tlv_size, 00119 uint32_t offset, 00120 M2MObject &object, 00121 M2MTLVDeserializer::Operation operation, 00122 bool update_value); 00123 00124 static M2MTLVDeserializer::Error deserialize_resources(const uint8_t *tlv, 00125 uint32_t tlv_size, 00126 uint32_t offset, 00127 M2MObjectInstance &object_instance, 00128 M2MTLVDeserializer::Operation operation, 00129 bool update_value); 00130 00131 static M2MTLVDeserializer::Error deserialize_resource_instances(const uint8_t *tlv, 00132 uint32_t tlv_size, 00133 uint32_t offset, 00134 M2MResource &resource, 00135 M2MObjectInstance &object_instance, 00136 M2MTLVDeserializer::Operation operation, 00137 bool update_value); 00138 00139 static M2MTLVDeserializer::Error deserialize_resource_instances(const uint8_t *tlv, 00140 uint32_t tlv_size, 00141 uint32_t offset, 00142 M2MResource &resource, 00143 M2MTLVDeserializer::Operation operation, 00144 bool update_value); 00145 00146 static bool is_object_instance(const uint8_t *tlv, uint32_t offset); 00147 00148 static bool is_resource(const uint8_t *tlv, uint32_t offset); 00149 00150 static bool is_multiple_resource(const uint8_t *tlv, uint32_t offset); 00151 00152 static bool is_resource_instance(const uint8_t *tlv, uint32_t offset); 00153 00154 static bool set_resource_instance_value(M2MResourceBase *res, const uint8_t *tlv, const uint32_t size); 00155 00156 static void remove_resources(const uint8_t *tlv, 00157 uint32_t tlv_size, 00158 M2MObjectInstance &object_instance, 00159 uint32_t offset_size); 00160 00161 static void remove_resource_instances(const uint8_t *tlv, 00162 uint32_t tlv_size, 00163 M2MResource &resource, 00164 uint32_t offset_size); 00165 }; 00166 00167 class TypeIdLength { 00168 00169 public: 00170 TypeIdLength(const uint8_t *tlv, uint32_t offset); 00171 00172 void deserialize(); 00173 00174 void deserialiseID(uint32_t idLength); 00175 00176 void deserialiseLength(uint32_t lengthType); 00177 00178 const uint8_t *_tlv; 00179 uint32_t _offset; 00180 uint32_t _type; 00181 uint16_t _id; 00182 uint32_t _length; 00183 00184 friend class Test_M2MTLVDeserializer; 00185 };
Generated on Tue Jul 12 2022 19:01:35 by 1.7.2