Skip to content

Commit 6148e89

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 - 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
1 parent f39dcb8 commit 6148e89

32 files changed

+1130
-547
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,17 +20,23 @@ 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/cborpretty_stdio.c \
3236
src/cbortojson.c \
3337
src/cborvalidation.c \
38+
src/cbor_buf_reader.c \
39+
src/cbor_buf_writer.c
3440
#
3541
CBORDUMP_SOURCES = tools/cbordump/cbordump.c
3642

@@ -55,7 +61,7 @@ BINLIBRARY=lib/libtinycbor.a
5561
INSTALL_TARGETS += $(libdir)/libtinycbor.a
5662
endif
5763
INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
58-
INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)
64+
INSTALL_TARGETS += $(TINYCBOR_HEADERS:./%=$(includedir)/%)
5965

6066
# setup VPATH
6167
MAKEFILE := $(lastword $(MAKEFILE_LIST))
@@ -170,7 +176,7 @@ $(DESTDIR)$(bindir)/%: bin/%
170176
$(DESTDIR)$(pkgconfigdir)/%: %
171177
$(INSTALL) -d $(@D)
172178
$(INSTALL_DATA) $< $@
173-
$(DESTDIR)$(includedir)/tinycbor/%: src/%
179+
$(DESTDIR)$(includedir)/%: src/%
174180
$(INSTALL) -d $(@D)
175181
$(INSTALL_DATA) $< $@
176182

@@ -215,7 +221,7 @@ tag: distcheck
215221
.PHONY: docs dist distcheck release
216222
.SECONDARY:
217223

218-
cflags := $(CPPFLAGS) -I$(SRCDIR)src
224+
cflags := $(CPPFLAGS) -I$(SRCDIR)/src
219225
cflags += -DTINYCBOR_VERSION_SUFFIX=\"$(DIRTYSRC)\"
220226
cflags += -std=c99 $(CFLAGS)
221227
%.o: %.c

Makefile.nmake

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
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 \
1110
src\cborpretty_stdio.c \
12-
src\cborvalidation.c
11+
src\cborvalidation.c \
12+
src\cbor_buf_reader.c \
13+
src\cbor_buf_writer.c
1314
TINYCBOR_OBJS = \
1415
src\cborerrorstrings.obj \
1516
src\cborencoder.obj \
16-
src\cborencoder_close_container_checked.obj \
1717
src\cborparser.obj \
1818
src\cborparser_dup_string.obj \
1919
src\cborpretty.obj \
2020
src\cborpretty_stdio.obj \
21-
src\cborvalidation.obj
21+
src\cborvalidation.obj \
22+
src\cbor_buf_writer.obj \
23+
src\cbor_buf_reader.obj
2224

2325
all: lib\tinycbor.lib
2426
check: tests\Makefile lib\tinycbor.lib
@@ -43,5 +45,5 @@ tag:
4345
@perl maketag.pl
4446

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

0 commit comments

Comments
 (0)