-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring tinycbor up to date with mynewt tinycbor
- Removing cborencoder_close_container_checked.c since cborencoder_close_container() checks the number of elements now. - Add container_size for the container - cbor_encoder_close_container(): look at isMap flag to determine container_size for comparison - iterate_string_chunks(): fixing NULL compare at the end of string and moving it out of the iterate_string_chunks(). This is to avoid buffer specific parser calls in the function - cbor_value_get_next_byte() is removed in mynewt version of tinycbor, so, we track offsets of the buffer which can be used for comparison in the parser tests instead of calculating the offset - Move cbor_encoder_get_extra_bytes_needed() and cbor_encoder_get_buffer_size() to be part of cbor_buf_writer APIs - Add bytes_needed field to the buf writer - Adding encoder writer and parser reader as part of the encoder and parser structure. This is to make the encoder and parser use new function of encoder_writer and decoder_reader without breaking backwards compatibility. - Making the old API use flat buffers by default - Adding APIs for initializing encoder and parser with custom writer and reader - Make the default writer and reader conditional based on NO_DFLT_READER/WRITER define. This is because we want a default reader/writer to avoid API changes. - Move enums to cbor_defs.h - Use it->offset instead of it->ptr to track buffer offsets - Update resolve_indicator() static api paramaters to use cbor value and access offsets instead of taking pointers as input parameters - In validate_container() do a byte by byte comparison instead of memcmp since we no longer have access to teh buffer directly Also, use offets instead of pointers to validate sorted maps - Added a new dfine for conditionally compiling in float support (NO_FLOAT_SUPPORT). This is because we want the float support to be compiled in by default. - Use static_assert macro instead of Static_assert. Changed to avoid build failures. - Add api to get string chunk, this is a callback which can be used by buffer implementations to grab a string that is divided in chunks which spans across multiple chained buffers
- Loading branch information
Showing
28 changed files
with
889 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2016 Intel Corporation | ||
** | ||
** Permission is hereby granted, free of charge, to any person obtaining a copy | ||
** of this software and associated documentation files (the "Software"), to deal | ||
** in the Software without restriction, including without limitation the rights | ||
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
** copies of the Software, and to permit persons to whom the Software is | ||
** furnished to do so, subject to the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be included in | ||
** all copies or substantial portions of the Software. | ||
** | ||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
** THE SOFTWARE. | ||
** | ||
****************************************************************************/ | ||
|
||
#include "cbor_buf_reader.h" | ||
#include "compilersupport_p.h" | ||
|
||
/** | ||
* \addtogroup CborParsing | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* Gets 16 bit unsigned value from the passed in ptr location, it also | ||
* converts it to host byte order | ||
*/ | ||
CBOR_INLINE_API uint16_t get16(const uint8_t *ptr) | ||
{ | ||
uint16_t result; | ||
memcpy(&result, ptr, sizeof(result)); | ||
return cbor_ntohs(result); | ||
} | ||
|
||
/** | ||
* Gets 32 bit unsigned value from the passed in ptr location, it also | ||
* converts it to host byte order | ||
*/ | ||
CBOR_INLINE_API uint32_t get32(const uint8_t *ptr) | ||
{ | ||
uint32_t result; | ||
memcpy(&result, ptr, sizeof(result)); | ||
return cbor_ntohl(result); | ||
} | ||
|
||
/** | ||
* Gets 64 bit unsigned value from the passed in ptr location, it also | ||
* converts it to host byte order | ||
*/ | ||
CBOR_INLINE_API uint64_t get64(const uint8_t *ptr) | ||
{ | ||
uint64_t result; | ||
memcpy(&result, ptr, sizeof(result)); | ||
return cbor_ntohll(result); | ||
} | ||
|
||
/** | ||
* Gets a string chunk from the passed in ptr location | ||
*/ | ||
CBOR_INLINE_API uintptr_t get_string_chunk(const uint8_t *ptr) | ||
{ | ||
return (uintptr_t)ptr; | ||
} | ||
|
||
/** | ||
* Gets 8 bit unsigned value using the buffer pointed to by the | ||
* decoder reader from passed in offset | ||
*/ | ||
static uint8_t | ||
cbuf_buf_reader_get8(struct cbor_decoder_reader *d, int offset) | ||
{ | ||
struct cbor_buf_reader *cb = (struct cbor_buf_reader *) d; | ||
return cb->buffer[offset]; | ||
} | ||
|
||
/** | ||
* Gets 16 bit unsigned value using the buffer pointed to by the | ||
* decoder reader from passed in offset | ||
*/ | ||
static uint16_t | ||
cbuf_buf_reader_get16(struct cbor_decoder_reader *d, int offset) | ||
{ | ||
struct cbor_buf_reader *cb = (struct cbor_buf_reader *) d; | ||
return get16(cb->buffer + offset); | ||
} | ||
|
||
/** | ||
* Gets 32 bit unsigned value using the buffer pointed to by the | ||
* decoder reader from passed in offset | ||
*/ | ||
static uint32_t | ||
cbuf_buf_reader_get32(struct cbor_decoder_reader *d, int offset) | ||
{ | ||
uint32_t val; | ||
struct cbor_buf_reader *cb = (struct cbor_buf_reader *) d; | ||
val = get32(cb->buffer + offset); | ||
return val; | ||
} | ||
|
||
/** | ||
* Gets 64 bit unsigned value using the buffer pointed to by the | ||
* decoder reader from passed in offset | ||
*/ | ||
static uint64_t | ||
cbuf_buf_reader_get64(struct cbor_decoder_reader *d, int offset) | ||
{ | ||
struct cbor_buf_reader *cb = (struct cbor_buf_reader *) d; | ||
return get64(cb->buffer + offset); | ||
} | ||
|
||
static uintptr_t | ||
cbor_buf_reader_get_string_chunk(struct cbor_decoder_reader *d, | ||
int offset, size_t *len) | ||
{ | ||
struct cbor_buf_reader *cb = (struct cbor_buf_reader *)d; | ||
|
||
(void)*len; | ||
|
||
return get_string_chunk(cb->buffer + offset); | ||
} | ||
|
||
static uintptr_t | ||
cbor_buf_reader_cmp(struct cbor_decoder_reader *d, char *dst, int src_offset, | ||
size_t len) | ||
{ | ||
struct cbor_buf_reader *cb = (struct cbor_buf_reader *) d; | ||
|
||
return !memcmp(dst, cb->buffer + src_offset, len); | ||
} | ||
|
||
static uintptr_t | ||
cbor_buf_reader_cpy(struct cbor_decoder_reader *d, char *dst, int src_offset, | ||
size_t len) | ||
{ | ||
struct cbor_buf_reader *cb = (struct cbor_buf_reader *) d; | ||
return (uintptr_t) memcpy(dst, cb->buffer + src_offset, len); | ||
} | ||
|
||
void | ||
cbor_buf_reader_init(struct cbor_buf_reader *cb, const uint8_t *buffer, | ||
size_t data) | ||
{ | ||
cb->buffer = buffer; | ||
cb->r.get8 = &cbuf_buf_reader_get8; | ||
cb->r.get16 = &cbuf_buf_reader_get16; | ||
cb->r.get32 = &cbuf_buf_reader_get32; | ||
cb->r.get64 = &cbuf_buf_reader_get64; | ||
cb->r.cmp = &cbor_buf_reader_cmp; | ||
cb->r.cpy = &cbor_buf_reader_cpy; | ||
cb->r.get_string_chunk = &cbor_buf_reader_get_string_chunk; | ||
cb->r.message_size = data; | ||
} | ||
|
||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2016 Intel Corporation | ||
** | ||
** Permission is hereby granted, free of charge, to any person obtaining a copy | ||
** of this software and associated documentation files (the "Software"), to deal | ||
** in the Software without restriction, including without limitation the rights | ||
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
** copies of the Software, and to permit persons to whom the Software is | ||
** furnished to do so, subject to the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be included in | ||
** all copies or substantial portions of the Software. | ||
** | ||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
** THE SOFTWARE. | ||
** | ||
****************************************************************************/ | ||
|
||
#ifndef CBOR_BUF_READER_H | ||
#define CBOR_BUF_READER_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "cbor_decoder_reader.h" | ||
|
||
struct cbor_buf_reader { | ||
struct cbor_decoder_reader r; | ||
const uint8_t *buffer; | ||
}; | ||
|
||
void cbor_buf_reader_init(struct cbor_buf_reader *cb, const uint8_t *buffer, | ||
size_t data); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* CBOR_BUF_READER_H */ | ||
|
Oops, something went wrong.