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