Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/mbed-client/source/include/m2mtlvserializer.h@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | /* |
leothedragon | 0:8f0bb79ddd48 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
leothedragon | 0:8f0bb79ddd48 | 3 | * SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
leothedragon | 0:8f0bb79ddd48 | 5 | * not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 6 | * You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 7 | * |
leothedragon | 0:8f0bb79ddd48 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 9 | * |
leothedragon | 0:8f0bb79ddd48 | 10 | * Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
leothedragon | 0:8f0bb79ddd48 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 13 | * See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 14 | * limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 15 | */ |
leothedragon | 0:8f0bb79ddd48 | 16 | #include "mbed-client/m2mvector.h" |
leothedragon | 0:8f0bb79ddd48 | 17 | #include "mbed-client/m2mobject.h" |
leothedragon | 0:8f0bb79ddd48 | 18 | #include "mbed-client/m2mobjectinstance.h" |
leothedragon | 0:8f0bb79ddd48 | 19 | #include "mbed-client/m2mresource.h" |
leothedragon | 0:8f0bb79ddd48 | 20 | |
leothedragon | 0:8f0bb79ddd48 | 21 | class M2MResourceBase; |
leothedragon | 0:8f0bb79ddd48 | 22 | |
leothedragon | 0:8f0bb79ddd48 | 23 | /** |
leothedragon | 0:8f0bb79ddd48 | 24 | * @brief M2MTLVSerializer |
leothedragon | 0:8f0bb79ddd48 | 25 | * TLV Serialiser constructs the binary representation of object instances, |
leothedragon | 0:8f0bb79ddd48 | 26 | * resources and resource instances (see OMA-LWM2M specification, chapter 6.1 |
leothedragon | 0:8f0bb79ddd48 | 27 | * for resource model) as OMA-TLV according described in chapter 6.3.3. |
leothedragon | 0:8f0bb79ddd48 | 28 | * |
leothedragon | 0:8f0bb79ddd48 | 29 | */ |
leothedragon | 0:8f0bb79ddd48 | 30 | class M2MTLVSerializer { |
leothedragon | 0:8f0bb79ddd48 | 31 | |
leothedragon | 0:8f0bb79ddd48 | 32 | public: |
leothedragon | 0:8f0bb79ddd48 | 33 | |
leothedragon | 0:8f0bb79ddd48 | 34 | /** |
leothedragon | 0:8f0bb79ddd48 | 35 | * Serialises given objects instances that contain resources or multiple |
leothedragon | 0:8f0bb79ddd48 | 36 | * resources. Object instance IDs are also encoded. This method must be |
leothedragon | 0:8f0bb79ddd48 | 37 | * used when an operation targets an object with (potential) multiple |
leothedragon | 0:8f0bb79ddd48 | 38 | * instances like "GET /1". In that case the generated TLV will contain the |
leothedragon | 0:8f0bb79ddd48 | 39 | * following data: |
leothedragon | 0:8f0bb79ddd48 | 40 | * <ul> |
leothedragon | 0:8f0bb79ddd48 | 41 | * <li> ./0 |
leothedragon | 0:8f0bb79ddd48 | 42 | * <li> ./0/0 |
leothedragon | 0:8f0bb79ddd48 | 43 | * <li> ./0/1 |
leothedragon | 0:8f0bb79ddd48 | 44 | * <li> ... |
leothedragon | 0:8f0bb79ddd48 | 45 | * <li> ./1 |
leothedragon | 0:8f0bb79ddd48 | 46 | * <li> ./1/0 |
leothedragon | 0:8f0bb79ddd48 | 47 | * <li> ./1/1 |
leothedragon | 0:8f0bb79ddd48 | 48 | * <li> ... |
leothedragon | 0:8f0bb79ddd48 | 49 | * </ul> |
leothedragon | 0:8f0bb79ddd48 | 50 | * |
leothedragon | 0:8f0bb79ddd48 | 51 | * @param objects List of object instances. |
leothedragon | 0:8f0bb79ddd48 | 52 | * @return Object instances encoded binary as OMA-TLV |
leothedragon | 0:8f0bb79ddd48 | 53 | * @see #serializeObjectInstances(List) |
leothedragon | 0:8f0bb79ddd48 | 54 | */ |
leothedragon | 0:8f0bb79ddd48 | 55 | static uint8_t* serialize(const M2MObjectInstanceList &object_instance_list, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 56 | |
leothedragon | 0:8f0bb79ddd48 | 57 | /** |
leothedragon | 0:8f0bb79ddd48 | 58 | * Serialises given resources with no information about the parent object |
leothedragon | 0:8f0bb79ddd48 | 59 | * instance. This method must be used when an operation targets an object |
leothedragon | 0:8f0bb79ddd48 | 60 | * instance like "GET /1/0" or a single-instance object like "GET /3//". |
leothedragon | 0:8f0bb79ddd48 | 61 | * Resources may have single or multiple instances. The generated TLV will |
leothedragon | 0:8f0bb79ddd48 | 62 | * contain the following data as response to "GET /3//": |
leothedragon | 0:8f0bb79ddd48 | 63 | * <ul> |
leothedragon | 0:8f0bb79ddd48 | 64 | * <li> ./0 |
leothedragon | 0:8f0bb79ddd48 | 65 | * <li> ./1 |
leothedragon | 0:8f0bb79ddd48 | 66 | * <li> ./2 |
leothedragon | 0:8f0bb79ddd48 | 67 | * <li> ./6/0 (1st instance of a multiple resource) |
leothedragon | 0:8f0bb79ddd48 | 68 | * <li> ./6/1 (2nd instance of a multiple resource) |
leothedragon | 0:8f0bb79ddd48 | 69 | * <li> ... |
leothedragon | 0:8f0bb79ddd48 | 70 | * </ul> |
leothedragon | 0:8f0bb79ddd48 | 71 | * @param resources Array of resources and resource instances. |
leothedragon | 0:8f0bb79ddd48 | 72 | * @return Resources encoded binary as OMA-TLV |
leothedragon | 0:8f0bb79ddd48 | 73 | * @see #serializeResources(List) |
leothedragon | 0:8f0bb79ddd48 | 74 | */ |
leothedragon | 0:8f0bb79ddd48 | 75 | static uint8_t* serialize(const M2MResourceList &resource_list, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 76 | |
leothedragon | 0:8f0bb79ddd48 | 77 | static uint8_t* serialize(const M2MResource *resource, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 78 | |
leothedragon | 0:8f0bb79ddd48 | 79 | private : |
leothedragon | 0:8f0bb79ddd48 | 80 | |
leothedragon | 0:8f0bb79ddd48 | 81 | static uint8_t* serialize_object_instances(const M2MObjectInstanceList &object_instance_list, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 82 | |
leothedragon | 0:8f0bb79ddd48 | 83 | static uint8_t* serialize_resources(const M2MResourceList &resource_list, uint32_t &size, bool &valid); |
leothedragon | 0:8f0bb79ddd48 | 84 | |
leothedragon | 0:8f0bb79ddd48 | 85 | static bool serialize(uint16_t id, const M2MObjectInstance *object_instance, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 86 | |
leothedragon | 0:8f0bb79ddd48 | 87 | static bool serialize(const M2MResource *resource, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 88 | |
leothedragon | 0:8f0bb79ddd48 | 89 | static bool serialize_resource(const M2MResource *resource, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 90 | |
leothedragon | 0:8f0bb79ddd48 | 91 | static bool serialize_multiple_resource(const M2MResource *resource, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 92 | |
leothedragon | 0:8f0bb79ddd48 | 93 | static bool serialize_resource_instance(uint16_t id, const M2MResourceInstance *resource, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 94 | |
leothedragon | 0:8f0bb79ddd48 | 95 | static bool serialize_TILV (uint8_t type, uint16_t id, uint8_t *value, uint32_t value_length, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 96 | |
leothedragon | 0:8f0bb79ddd48 | 97 | static void serialize_id(uint16_t id, uint32_t &size, uint8_t *id_ptr); |
leothedragon | 0:8f0bb79ddd48 | 98 | |
leothedragon | 0:8f0bb79ddd48 | 99 | static void serialize_length(uint32_t length, uint32_t &size, uint8_t *length_ptr); |
leothedragon | 0:8f0bb79ddd48 | 100 | |
leothedragon | 0:8f0bb79ddd48 | 101 | static bool serialize_TLV_binary_int(const M2MResourceBase *resource, uint8_t type, uint16_t id, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 102 | |
leothedragon | 0:8f0bb79ddd48 | 103 | static bool serialize_TLV_binary_float(const M2MResourceBase *resource, uint8_t type, uint16_t id, uint8_t *&data, uint32_t &size); |
leothedragon | 0:8f0bb79ddd48 | 104 | }; |