Sebastián Pastor / EtheriosCloudConnector
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rci_binary_buffer.h Source File

rci_binary_buffer.h

00001 /*
00002  * Copyright (c) 2013 Digi International Inc.,
00003  * All rights not expressly granted are reserved.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
00007  * You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
00010  * =======================================================================
00011  */
00012 
00013 static void rci_set_buffer(rci_buffer_t * const dst, rci_service_buffer_t const * const src)
00014 {
00015     uint8_t * const start = src->data;
00016 
00017     dst->start = start;
00018     dst->end = start + src->bytes;
00019     dst->current = start;
00020 }
00021 
00022 static size_t rci_buffer_remaining(rci_buffer_t const * const buffer)
00023 {
00024     size_t const remaining_length = (size_t)(buffer->end - buffer->current);
00025     return remaining_length;
00026 }
00027 
00028 static size_t rci_buffer_used(rci_buffer_t const * const buffer)
00029 {
00030     size_t const used_length = (size_t)(buffer->current - buffer->start);
00031     return used_length;
00032 }
00033 
00034 static uint8_t * rci_buffer_position(rci_buffer_t const * const buffer)
00035 {
00036     return buffer->current;
00037 }
00038 
00039 static void rci_buffer_advance(rci_buffer_t * const buffer, size_t const amount)
00040 {
00041     ASSERT((buffer->current + amount) <= buffer->end);
00042     buffer->current += amount;
00043 }
00044 
00045 static uint8_t rci_buffer_read(rci_buffer_t const * const buffer)
00046 {
00047     ASSERT(rci_buffer_remaining(buffer) != 0);
00048 
00049     return *(buffer->current);
00050 }
00051 
00052 static connector_bool_t ptr_in_range(void const * const pointer, void const * const start, void const * const end)
00053 {
00054     return connector_bool((pointer >= start) && (pointer <= end));
00055 }
00056 
00057 static connector_bool_t ptr_in_buffer(uint8_t const * const pointer, rci_buffer_t const * const buffer)
00058 {
00059     return ptr_in_range(pointer, buffer->start, buffer->end);
00060 }
00061 
00062