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