FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

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