Simple interface for Mbed Cloud Client
Embed:
(wiki syntax)
Show/hide line numbers
m2mtlvserializer.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 class M2MResourceBase; 00022 00023 /** 00024 * @brief M2MTLVSerializer 00025 * TLV Serialiser constructs the binary representation of object instances, 00026 * resources and resource instances (see OMA-LWM2M specification, chapter 6.1 00027 * for resource model) as OMA-TLV according described in chapter 6.3.3. 00028 * 00029 */ 00030 class M2MTLVSerializer { 00031 00032 public: 00033 00034 /** 00035 * Serialises given objects instances that contain resources or multiple 00036 * resources. Object instance IDs are also encoded. This method must be 00037 * used when an operation targets an object with (potential) multiple 00038 * instances like "GET /1". In that case the generated TLV will contain the 00039 * following data: 00040 * <ul> 00041 * <li> ./0 00042 * <li> ./0/0 00043 * <li> ./0/1 00044 * <li> ... 00045 * <li> ./1 00046 * <li> ./1/0 00047 * <li> ./1/1 00048 * <li> ... 00049 * </ul> 00050 * 00051 * @param objects List of object instances. 00052 * @return Object instances encoded binary as OMA-TLV 00053 * @see #serializeObjectInstances(List) 00054 */ 00055 static uint8_t* serialize(const M2MObjectInstanceList &object_instance_list, uint32_t &size); 00056 00057 /** 00058 * Serialises given resources with no information about the parent object 00059 * instance. This method must be used when an operation targets an object 00060 * instance like "GET /1/0" or a single-instance object like "GET /3//". 00061 * Resources may have single or multiple instances. The generated TLV will 00062 * contain the following data as response to "GET /3//": 00063 * <ul> 00064 * <li> ./0 00065 * <li> ./1 00066 * <li> ./2 00067 * <li> ./6/0 (1st instance of a multiple resource) 00068 * <li> ./6/1 (2nd instance of a multiple resource) 00069 * <li> ... 00070 * </ul> 00071 * @param resources Array of resources and resource instances. 00072 * @return Resources encoded binary as OMA-TLV 00073 * @see #serializeResources(List) 00074 */ 00075 static uint8_t* serialize(const M2MResourceList &resource_list, uint32_t &size); 00076 00077 static uint8_t* serialize(const M2MResource *resource, uint32_t &size); 00078 00079 private : 00080 00081 static uint8_t* serialize_object_instances(const M2MObjectInstanceList &object_instance_list, uint32_t &size); 00082 00083 static uint8_t* serialize_resources(const M2MResourceList &resource_list, uint32_t &size, bool &valid); 00084 00085 static bool serialize(uint16_t id, const M2MObjectInstance *object_instance, uint8_t *&data, uint32_t &size); 00086 00087 static bool serialize(const M2MResource *resource, uint8_t *&data, uint32_t &size); 00088 00089 static bool serialize_resource(const M2MResource *resource, uint8_t *&data, uint32_t &size); 00090 00091 static bool serialize_multiple_resource(const M2MResource *resource, uint8_t *&data, uint32_t &size); 00092 00093 static bool serialize_resource_instance(uint16_t id, const M2MResourceInstance *resource, uint8_t *&data, uint32_t &size); 00094 00095 static bool serialize_TILV (uint8_t type, uint16_t id, uint8_t *value, uint32_t value_length, uint8_t *&data, uint32_t &size); 00096 00097 static void serialize_id(uint16_t id, uint32_t &size, uint8_t *id_ptr); 00098 00099 static void serialize_length(uint32_t length, uint32_t &size, uint8_t *length_ptr); 00100 00101 static bool serialize_TLV_binary_int(const M2MResourceBase *resource, uint8_t type, uint16_t id, uint8_t *&data, uint32_t &size); 00102 };
Generated on Tue Jul 12 2022 19:01:35 by 1.7.2