Skip to content

Commit 12d89ef

Browse files
committed
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 - cpp test now uses tinycbor lib - 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.
1 parent aa692b7 commit 12d89ef

31 files changed

+1207
-569
lines changed

Makefile

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ prefix = /usr/local
33
exec_prefix = $(prefix)
44
bindir = $(exec_prefix)/bin
55
libdir = $(exec_prefix)/lib
6-
includedir = $(prefix)/include
6+
includedir = $(prefix)/src
77
pkgconfigdir = $(libdir)/pkgconfig
88

99
CFLAGS = -Wall -Wextra
@@ -20,16 +20,22 @@ RMDIR = rmdir
2020
SED = sed
2121

2222
# Our sources
23-
TINYCBOR_HEADERS = src/cbor.h src/cborjson.h
23+
TINYCBOR_HEADERS = \
24+
src/cbor.h \
25+
src/cborjson.h \
26+
src/cbor_enocoder_writer.h \
27+
src/cbor_decoder_reader.h \
28+
src/cbor_defs.h
2429
TINYCBOR_SOURCES = \
2530
src/cborerrorstrings.c \
2631
src/cborencoder.c \
27-
src/cborencoder_close_container_checked.c \
2832
src/cborparser.c \
2933
src/cborparser_dup_string.c \
3034
src/cborpretty.c \
3135
src/cbortojson.c \
3236
src/cborvalidation.c \
37+
src/cbor_buf_reader.c \
38+
src/cbor_buf_writer.c
3339
#
3440
CBORDUMP_SOURCES = tools/cbordump/cbordump.c
3541

@@ -43,7 +49,7 @@ INSTALL_TARGETS += $(libdir)/libtinycbor.so.0
4349
INSTALL_TARGETS += $(libdir)/libtinycbor.so.$(VERSION)
4450
endif
4551
INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
46-
INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)
52+
INSTALL_TARGETS += $(TINYCBOR_HEADERS:./%=$(includedir)/%)
4753

4854
# setup VPATH
4955
MAKEFILE := $(lastword $(MAKEFILE_LIST))
@@ -156,7 +162,7 @@ $(DESTDIR)$(bindir)/%: bin/%
156162
$(DESTDIR)$(pkgconfigdir)/%: %
157163
$(INSTALL) -d $(@D)
158164
$(INSTALL_DATA) $< $@
159-
$(DESTDIR)$(includedir)/tinycbor/%: src/%
165+
$(DESTDIR)$(includedir)/%: src/%
160166
$(INSTALL) -d $(@D)
161167
$(INSTALL_DATA) $< $@
162168

@@ -200,7 +206,7 @@ tag: distcheck
200206
.PHONY: docs dist distcheck release
201207
.SECONDARY:
202208

203-
cflags := $(CPPFLAGS) -I$(SRCDIR)src
209+
cflags := $(CPPFLAGS) -I$(SRCDIR)/src
204210
cflags += -DTINYCBOR_VERSION_SUFFIX=\"$(DIRTYSRC)\"
205211
cflags += -std=c99 $(CFLAGS)
206212
%.o: %.c

Makefile.nmake

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
CFLAGS = -W3
22

3-
TINYCBOR_HEADERS = src\cbor.h src\cborjson.h
3+
TINYCBOR_HEADERS = src
44
TINYCBOR_SOURCES = \
55
src\cborerrorstrings.c \
66
src\cborencoder.c \
7-
src\cborencoder_close_container_checked.c \
87
src\cborparser.c \
98
src\cborparser_dup_string.c \
109
src\cborpretty.c \
11-
src\cborvalidation.c
10+
src\cborvalidation.c \
11+
src\cbor_buf_reader.c \
12+
src\cbor_buf_writer.c
1213
TINYCBOR_OBJS = \
1314
src\cborerrorstrings.obj \
1415
src\cborencoder.obj \
15-
src\cborencoder_close_container_checked.obj \
1616
src\cborparser.obj \
1717
src\cborparser_dup_string.obj \
1818
src\cborpretty.obj \
19-
src\cborvalidation.obj
19+
src\cborvalidation.obj \
20+
src\cbor_buf_writer.obj \
21+
src\cbor_buf_reader.obj
2022

2123
all: lib\tinycbor.lib
2224
check: tests\Makefile lib\tinycbor.lib
@@ -41,5 +43,5 @@ tag:
4143
@perl maketag.pl
4244

4345
{src\}.c{src\}.obj:
44-
$(CC) -nologo $(CFLAGS) -Isrc -DTINYCBOR_VERSION_SUFFIX="" -c -Fo$@ $<
46+
$(CC) -nologo $(CFLAGS) -I$(TINYCBOR_HEADERS) -DTINYCBOR_VERSION_SUFFIX="" -c -Fo$@ $<
4547

0 commit comments

Comments
 (0)