Skip to content

Commit

Permalink
Bring tinycbor up to date with mynewt tinycbor
Browse files Browse the repository at this point in the history
- 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
vrahane committed Jan 3, 2018
1 parent f39dcb8 commit 423f94b
Show file tree
Hide file tree
Showing 30 changed files with 1,122 additions and 547 deletions.
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
includedir = $(prefix)/include
includedir = $(prefix)/src
pkgconfigdir = $(libdir)/pkgconfig

CFLAGS = -Wall -Wextra
Expand All @@ -20,17 +20,23 @@ RMDIR = rmdir
SED = sed

# Our sources
TINYCBOR_HEADERS = src/cbor.h src/cborjson.h
TINYCBOR_HEADERS = \
src/cbor.h \
src/cborjson.h \
src/cbor_enocoder_writer.h \
src/cbor_decoder_reader.h \
src/cbor_defs.h
TINYCBOR_SOURCES = \
src/cborerrorstrings.c \
src/cborencoder.c \
src/cborencoder_close_container_checked.c \
src/cborparser.c \
src/cborparser_dup_string.c \
src/cborpretty.c \
src/cborpretty_stdio.c \
src/cbortojson.c \
src/cborvalidation.c \
src/cbor_buf_reader.c \
src/cbor_buf_writer.c
#
CBORDUMP_SOURCES = tools/cbordump/cbordump.c

Expand All @@ -55,7 +61,7 @@ BINLIBRARY=lib/libtinycbor.a
INSTALL_TARGETS += $(libdir)/libtinycbor.a
endif
INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)
INSTALL_TARGETS += $(TINYCBOR_HEADERS:./%=$(includedir)/%)

# setup VPATH
MAKEFILE := $(lastword $(MAKEFILE_LIST))
Expand Down Expand Up @@ -170,7 +176,7 @@ $(DESTDIR)$(bindir)/%: bin/%
$(DESTDIR)$(pkgconfigdir)/%: %
$(INSTALL) -d $(@D)
$(INSTALL_DATA) $< $@
$(DESTDIR)$(includedir)/tinycbor/%: src/%
$(DESTDIR)$(includedir)/%: src/%
$(INSTALL) -d $(@D)
$(INSTALL_DATA) $< $@

Expand Down Expand Up @@ -215,7 +221,7 @@ tag: distcheck
.PHONY: docs dist distcheck release
.SECONDARY:

cflags := $(CPPFLAGS) -I$(SRCDIR)src
cflags := $(CPPFLAGS) -I$(SRCDIR)/src
cflags += -DTINYCBOR_VERSION_SUFFIX=\"$(DIRTYSRC)\"
cflags += -std=c99 $(CFLAGS)
%.o: %.c
Expand Down
14 changes: 8 additions & 6 deletions Makefile.nmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
CFLAGS = -W3

TINYCBOR_HEADERS = src\cbor.h src\cborjson.h
TINYCBOR_HEADERS = src
TINYCBOR_SOURCES = \
src\cborerrorstrings.c \
src\cborencoder.c \
src\cborencoder_close_container_checked.c \
src\cborparser.c \
src\cborparser_dup_string.c \
src\cborpretty.c \
src\cborpretty_stdio.c \
src\cborvalidation.c
src\cborvalidation.c \
src\cbor_buf_reader.c \
src\cbor_buf_writer.c
TINYCBOR_OBJS = \
src\cborerrorstrings.obj \
src\cborencoder.obj \
src\cborencoder_close_container_checked.obj \
src\cborparser.obj \
src\cborparser_dup_string.obj \
src\cborpretty.obj \
src\cborpretty_stdio.obj \
src\cborvalidation.obj
src\cborvalidation.obj \
src\cbor_buf_writer.obj \
src\cbor_buf_reader.obj

all: lib\tinycbor.lib
check: tests\Makefile lib\tinycbor.lib
Expand All @@ -43,5 +45,5 @@ tag:
@perl maketag.pl

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

Loading

0 comments on commit 423f94b

Please sign in to comment.