pax_global_header00006660000000000000000000000064141145002710014505gustar00rootroot0000000000000052 comment=d393c16f3eb30d0c47e6f9d92db62272f0ec4dc7 tinycbor-0.6.0/000077500000000000000000000000001411450027100133415ustar00rootroot00000000000000tinycbor-0.6.0/.appveyor.yml000066400000000000000000000015461411450027100160150ustar00rootroot00000000000000version: 0.6-build-{build} pull_requests: do_not_increment_build_number: true image: - Visual Studio 2017 - Visual Studio 2019 install: - cmd: >- if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86) & (set QTDIR=C:\Qt\5.13\msvc2017) if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" (call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64) & (set QTDIR=C:\Qt\6.1\msvc2019_64) set path=%PATH%;%QTDIR%\bin build_script: - cmd: >- nmake -f Makefile.nmake -nologo CFLAGS="-W3 -Os -MDd" cd tests qmake CONFIG-=release CONFIG+=debug nmake -nologo -s test_script: - cmd: >- nmake -s -nologo TESTARGS=-silent check artifacts: - path: lib\tinycbor.lib deploy: off tinycbor-0.6.0/.tag000066400000000000000000000000511411450027100141110ustar00rootroot00000000000000d393c16f3eb30d0c47e6f9d92db62272f0ec4dc7 tinycbor-0.6.0/.travis.yml000066400000000000000000000050441411450027100154550ustar00rootroot00000000000000env: - BUILD_DOCS=false jobs: include: - # only build docs on main if: branch = main env: BUILD_DOCS=true language: cpp matrix: include: - os: linux dist: xenial addons: apt: sources: - sourceline: 'ppa:beineri/opt-qt-5.12.1-xenial' packages: - qt512base valgrind - doxygen env: - QMAKESPEC=linux-g++ - EVAL="CC=gcc && CXX=g++" - CFLAGS="-Os" - LDFLAGS="-Wl,--no-undefined -lm" - QMAKEFLAGS="-config release" - QT_NO_CPU_FEATURE=rdrnd - os: linux dist: xenial addons: apt: sources: - sourceline: 'ppa:beineri/opt-qt-5.12.1-xenial' packages: - qt512base env: - QMAKESPEC=linux-clang - EVAL="CC=clang && CXX=clang++" - CFLAGS="-Oz" - LDFLAGS="-Wl,--no-undefined -lm" - QMAKEFLAGS="-config release" - MAKEFLAGS=-s - TESTARGS=-silent - os: linux dist: xenial env: - QMAKESPEC=linux-gcc-freestanding - EVAL="CXX=false" - CFLAGS="-ffreestanding -Os" - LDFLAGS="-Wl,--no-undefined -lm" - os: linux dist: xenial env: - QMAKESPEC=linux-gcc-no-math - EVAL="CXX=false && touch src/math.h src/float.h" - CFLAGS="-ffreestanding -DCBOR_NO_FLOATING_POINT -Os" - LDFLAGS="-Wl,--no-undefined" - LDLIBS="" - os: osx env: - QMAKESPEC=macx-clang - CFLAGS="-Oz" - QMAKEFLAGS="-config debug" - MAKEFLAGS=-s - TESTARGS=-silent - PATH=/usr/local/opt/qt5/bin:$PATH install: - if [ "${TRAVIS_OS_NAME}" != "linux" ]; then brew update; brew install qt5; fi script: - PATH=`echo /opt/qt*/bin`:$PATH - eval "$EVAL" - make -s -f Makefile.configure configure | tee .config - make -k CFLAGS="$CFLAGS -march=native -g1 -Wall -Wextra -Werror" CPPFLAGS="-DNDEBUG -DCBOR_ENCODER_WRITER_CONTROL=-1 -DCBOR_PARSER_READER_CONTROL=-1" lib/libtinycbor.a - size lib/libtinycbor.a | tee sizes - make -s clean - make -k CFLAGS="$CFLAGS -O0 -g" LDFLAGS="$LDFLAGS" ${LDLIBS+LDLIBS="$LDLIBS"} - grep -q freestanding-pass .config || make QMAKEFLAGS="$QMAKEFLAGS QMAKE_CXX=$CXX" tests/Makefile - grep -q freestanding-pass .config || (cd tests && make TESTARGS=-silent check -k TESTRUNNER=`which valgrind 2>/dev/null`) - make -s clean - ! [ $BUILD_DOCS ] || ./scripts/update-docs.sh tinycbor-0.6.0/Doxyfile000066400000000000000000000027411411450027100150530ustar00rootroot00000000000000PROJECT_NAME = "TinyCBOR $(VERSION) API" OUTPUT_DIRECTORY = ../doc ABBREVIATE_BRIEF = SHORT_NAMES = YES JAVADOC_AUTOBRIEF = YES QT_AUTOBRIEF = YES TAB_SIZE = 8 ALIASES = "value=\arg \c" OPTIMIZE_OUTPUT_FOR_C = YES EXTRACT_STATIC = YES EXTRACT_LOCAL_CLASSES = NO HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_CLASSES = YES GENERATE_TODOLIST = NO GENERATE_TESTLIST = NO GENERATE_BUGLIST = NO GENERATE_DEPRECATEDLIST= NO SHOW_USED_FILES = NO WARN_IF_UNDOCUMENTED = NO WARN_LOGFILE = doxygen.log INPUT = . FILE_PATTERNS = *.h \ *.c \ *.dox EXCLUDE_PATTERNS = *_p.h STRIP_CODE_COMMENTS = NO REFERENCED_BY_RELATION = YES IGNORE_PREFIX = cbor_ \ Cbor HTML_TIMESTAMP = NO GENERATE_HTMLHELP = YES GENERATE_CHI = YES BINARY_TOC = YES TOC_EXPAND = YES MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest SEARCHENGINE = NO GENERATE_LATEX = NO COMPACT_LATEX = YES MACRO_EXPANSION = YES PREDEFINED = DOXYGEN \ CBOR_INLINE_API= CLASS_DIAGRAMS = NO CLASS_GRAPH = NO COLLABORATION_GRAPH = NO GROUP_GRAPHS = NO INCLUDE_GRAPH = NO INCLUDED_BY_GRAPH = NO GRAPHICAL_HIERARCHY = NO DIRECTORY_GRAPH = NO tinycbor-0.6.0/LICENSE000066400000000000000000000020621411450027100143460ustar00rootroot00000000000000MIT License Copyright (c) 2017 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. tinycbor-0.6.0/Makefile000066400000000000000000000162601411450027100150060ustar00rootroot00000000000000# Variables: prefix = /usr/local exec_prefix = $(prefix) bindir = $(exec_prefix)/bin libdir = $(exec_prefix)/lib includedir = $(prefix)/include pkgconfigdir = $(libdir)/pkgconfig CFLAGS = -Wall -Wextra LDFLAGS_GCSECTIONS = -Wl,--gc-sections LDFLAGS += $(if $(gc_sections-pass),$(LDFLAGS_GCSECTIONS)) LDLIBS = -lm GIT_ARCHIVE = git archive --prefix="$(PACKAGE)/" -9 INSTALL = install INSTALL_DATA = $(INSTALL) -m 644 INSTALL_PROGRAM = $(INSTALL) -m 755 QMAKE = qmake MKDIR = mkdir -p RMDIR = rmdir SED = sed # Our sources TINYCBOR_HEADERS = src/cbor.h src/cborjson.h src/tinycbor-version.h TINYCBOR_FREESTANDING_SOURCES = \ src/cborerrorstrings.c \ src/cborencoder.c \ src/cborencoder_close_container_checked.c \ src/cborencoder_float.c \ src/cborparser.c \ src/cborparser_float.c \ src/cborpretty.c \ # CBORDUMP_SOURCES = tools/cbordump/cbordump.c BUILD_SHARED = $(shell file -L /bin/sh 2>/dev/null | grep -q ELF && echo 1) BUILD_STATIC = 1 ifneq ($(BUILD_STATIC),1) ifneq ($(BUILD_SHARED),1) $(error error: BUILD_STATIC and BUILD_SHARED can not be both disabled) endif endif INSTALL_TARGETS += $(bindir)/cbordump ifeq ($(BUILD_SHARED),1) BINLIBRARY=lib/libtinycbor.so INSTALL_TARGETS += $(libdir)/libtinycbor.so.$(VERSION) endif ifeq ($(BUILD_STATIC),1) BINLIBRARY=lib/libtinycbor.a INSTALL_TARGETS += $(libdir)/libtinycbor.a endif INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%) # setup VPATH MAKEFILE := $(lastword $(MAKEFILE_LIST)) SRCDIR := $(dir $(MAKEFILE)) VPATH = $(SRCDIR):$(SRCDIR)/src # Our version GIT_DIR := $(strip $(shell git -C $(SRCDIR). rev-parse --git-dir 2> /dev/null)) VERSION = $(shell cat $(SRCDIR)VERSION) SOVERSION = $(shell cut -f1-2 -d. $(SRCDIR)VERSION) PACKAGE = tinycbor-$(VERSION) # Check that QMAKE is Qt 5 ifeq ($(origin QMAKE),file) check_qmake = $(strip $(shell $(1) -query QT_VERSION 2>/dev/null | cut -b1)) ifneq ($(call check_qmake,$(QMAKE)),5) QMAKE := qmake -qt5 ifneq ($(call check_qmake,$(QMAKE)),5) QMAKE := qmake-qt5 ifneq ($(call check_qmake,$(QMAKE)),5) QMAKE := @echo >&2 $(MAKEFILE): Cannot find a Qt 5 qmake; false endif endif endif endif -include .config ifeq ($(wildcard .config),) $(info .config file not yet created) endif ifeq ($(freestanding-pass),1) TINYCBOR_SOURCES = $(TINYCBOR_FREESTANDING_SOURCES) else TINYCBOR_SOURCES = \ $(TINYCBOR_FREESTANDING_SOURCES) \ src/cborparser_dup_string.c \ src/cborpretty_stdio.c \ src/cbortojson.c \ src/cborvalidation.c \ # # if open_memstream is unavailable on the system, try to implement our own # version using funopen or fopencookie ifeq ($(open_memstream-pass),) ifeq ($(funopen-pass)$(fopencookie-pass),) CFLAGS += -DWITHOUT_OPEN_MEMSTREAM ifeq ($(wildcard .config),.config) $(warning warning: funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!) endif else TINYCBOR_SOURCES += src/open_memstream.c endif endif endif # json2cbor depends on an external library (cjson) ifneq ($(cjson-pass)$(system-cjson-pass),) JSON2CBOR_SOURCES = tools/json2cbor/json2cbor.c INSTALL_TARGETS += $(bindir)/json2cbor ifeq ($(system-cjson-pass),1) LDFLAGS_CJSON = -lcjson else JSON2CBOR_SOURCES += src/cjson/cJSON.c json2cbor_CCFLAGS = -I$(SRCDIR)src/cjson endif endif # Rules all: .config \ $(if $(subst 0,,$(BUILD_STATIC)),lib/libtinycbor.a) \ $(if $(subst 0,,$(BUILD_SHARED)),lib/libtinycbor.so) \ $(if $(freestanding-pass),,bin/cbordump) \ tinycbor.pc all: $(if $(JSON2CBOR_SOURCES),bin/json2cbor) check: tests/Makefile | $(BINLIBRARY) $(MAKE) -C tests check silentcheck: | $(BINLIBRARY) TESTARGS=-silent $(MAKE) -f $(MAKEFILE) -s check configure: .config .config: Makefile.configure $(MAKE) -f $(SRCDIR)Makefile.configure OUT='>&9' configure 9> $@ lib/libtinycbor-freestanding.a: $(TINYCBOR_FREESTANDING_SOURCES:.c=.o) @$(MKDIR) -p lib $(AR) cqs $@ $^ lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o) @$(MKDIR) -p lib $(AR) cqs $@ $^ lib/libtinycbor.so: $(TINYCBOR_SOURCES:.c=.pic.o) @$(MKDIR) -p lib $(CC) -shared -Wl,-soname,libtinycbor.so.$(SOVERSION) -o lib/libtinycbor.so.$(VERSION) $(LDFLAGS) $^ $(LDLIBS) cd lib ; ln -sf libtinycbor.so.$(VERSION) libtinycbor.so ; ln -sf libtinycbor.so.$(VERSION) libtinycbor.so.$(SOVERSION) bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) $(BINLIBRARY) @$(MKDIR) -p bin $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) $(BINLIBRARY) @$(MKDIR) -p bin $(CC) -o $@ $(LDFLAGS) $^ $(LDFLAGS_CJSON) $(LDLIBS) tinycbor.pc: tinycbor.pc.in $(SED) > $@ < $< \ -e 's,@prefix@,$(prefix),' \ -e 's,@exec_prefix@,$(exec_prefix),' \ -e 's,@libdir@,$(libdir),' \ -e 's,@includedir@,$(includedir),' \ -e 's,@version@,$(VERSION),' tests/Makefile: tests/tests.pro $(QMAKE) $(QMAKEFLAGS) -o $@ $< $(PACKAGE).tar.gz: | .git GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=tar.gz -o "$(PACKAGE).tar.gz" HEAD $(PACKAGE).zip: | .git GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=zip -o "$(PACKAGE).zip" HEAD $(DESTDIR)$(libdir)/%: lib/% $(INSTALL) -d $(@D) $(INSTALL_DATA) $< $@ $(DESTDIR)$(bindir)/%: bin/% $(INSTALL) -d $(@D) $(INSTALL_PROGRAM) $< $@ $(DESTDIR)$(pkgconfigdir)/%: % $(INSTALL) -d $(@D) $(INSTALL_DATA) $< $@ $(DESTDIR)$(includedir)/tinycbor/%: src/% $(INSTALL) -d $(@D) $(INSTALL_DATA) $< $@ install-strip: $(MAKE) -f $(MAKEFILE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install install: $(INSTALL_TARGETS:%=$(DESTDIR)%) ifeq ($(BUILD_SHARED),1) ln -sf libtinycbor.so.$(VERSION) $(DESTDIR)$(libdir)/libtinycbor.so ln -sf libtinycbor.so.$(VERSION) $(DESTDIR)$(libdir)/libtinycbor.so.$(SOVERSION) endif uninstall: $(RM) $(INSTALL_TARGETS:%=$(DESTDIR)%) $(RM) $(DESTDIR)$(libdir)/libtinycbor.so $(RM) $(DESTDIR)$(libdir)/libtinycbor.so.$(SOVERSION) mostlyclean: $(RM) $(TINYCBOR_SOURCES:.c=.o) $(RM) $(TINYCBOR_SOURCES:.c=.pic.o) $(RM) $(CBORDUMP_SOURCES:.c=.o) clean: mostlyclean $(RM) bin/cbordump $(RM) bin/json2cbor $(RM) lib/libtinycbor.a $(RM) lib/libtinycbor-freestanding.a $(RM) tinycbor.pc $(RM) lib/libtinycbor.so* test -e tests/Makefile && $(MAKE) -C tests clean || : distclean: clean test -e tests/Makefile && $(MAKE) -C tests distclean || : docs: cd $(SRCDIR)src && VERSION=$(VERSION) doxygen $(SRCDIR)/../Doxyfile dist: $(PACKAGE).tar.gz $(PACKAGE).zip distcheck: .git -$(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck GIT_DIR=$(SRCDIR).git git archive --prefix=tinycbor-distcheck/ --format=tar HEAD | tar -xf - -C $${TMPDIR-/tmp} cd $${TMPDIR-/tmp}/tinycbor-distcheck && $(MAKE) silentcheck $(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck tag: distcheck @cd $(SRCDIR). && perl scripts/maketag.pl .PHONY: all check silentcheck configure install uninstall .PHONY: mostlyclean clean distclean .PHONY: docs dist distcheck release .SECONDARY: cflags := $(CPPFLAGS) -I$(SRCDIR)src cflags += -std=gnu99 $(CFLAGS) \ -Werror=incompatible-pointer-types \ -Werror=implicit-function-declaration \ -Werror=int-conversion %.o: %.c @test -d $(@D) || $(MKDIR) $(@D) $(CC) $(cflags) $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $< %.pic.o: %.c @test -d $(@D) || $(MKDIR) $(@D) $(CC) $(cflags) -fPIC $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $< -include src/*.d tinycbor-0.6.0/Makefile.configure000066400000000000000000000025011411450027100167570ustar00rootroot00000000000000ALLTESTS = open_memstream funopen fopencookie gc_sections \ system-cjson cjson freestanding MAKEFILE := $(lastword $(MAKEFILE_LIST)) OUT := PROGRAM-open_memstream = extern int open_memstream(); int main() { return open_memstream(); } PROGRAM-funopen = extern int funopen(); int main() { return funopen(); } PROGRAM-fopencookie = extern int fopencookie(); int main() { return fopencookie(); } PROGRAM-gc_sections = int main() {} CCFLAGS-gc_sections = -Wl,--gc-sections PROGRAM-freestanding = \#if !defined(__STDC_HOSTED__) || __STDC_HOSTED__-0 == 1\n PROGRAM-freestanding += \#error Hosted implementation\n PROGRAM-freestanding += \#endif\n PROGRAM-freestanding += int main() {} CCFLAGS-freestanding = $(CFLAGS) PROGRAM-cjson = \#include \n PROGRAM-cjson += \#include \n PROGRAM-cjson += int main() { return cJSON_False; } CCFLAGS-cjson = -I$(dir $(MAKEFILE))src PROGRAM-system-cjson = $(PROGRAM-cjson) CCFLAGS-system-cjson = -lcjson sink: @echo >&2 Please run from the top-level Makefile. configure: $(foreach it,$(ALLTESTS),check-$(it)) check-%: @echo $(subst check-,,$@)-tested := 1 $(OUT) $(if $(V),,@)if printf "$($(subst check-,PROGRAM-,$@))" | \ $(CC) -xc $($(subst check-,CCFLAGS-,$@)) -o /dev/null - $(if $(V),,>/dev/null 2>&1); \ then \ echo $(subst check-,,$@)-pass := 1 $(OUT); \ fi tinycbor-0.6.0/Makefile.nmake000066400000000000000000000023171411450027100160760ustar00rootroot00000000000000CFLAGS = -W3 TINYCBOR_HEADERS = src\cbor.h src\cborjson.h TINYCBOR_SOURCES = \ src\cborerrorstrings.c \ src\cborencoder.c \ src\cborencoder_close_container_checked.c \ src\cborencoder_float.c \ src\cborparser.c \ src\cborparser_dup_string.c \ src\cborparser_float.c \ src\cborpretty.c \ src\cborpretty_stdio.c \ src\cborvalidation.c TINYCBOR_OBJS = \ src\cborerrorstrings.obj \ src\cborencoder.obj \ src\cborencoder_close_container_checked.obj \ src\cborencoder_float.obj \ src\cborparser.obj \ src\cborparser_dup_string.obj \ src\cborparser_float.obj \ src\cborpretty.obj \ src\cborpretty_stdio.obj \ src\cborvalidation.obj all: lib\tinycbor.lib check: tests\Makefile lib\tinycbor.lib cd tests & $(MAKE) check silentcheck: cd tests & set TESTARGS=-silent & $(MAKE) -s check tests\Makefile: tests\tests.pro qmake -o $@ $** lib\tinycbor.lib: $(TINYCBOR_OBJS) -if not exist lib\NUL md lib lib -nologo /out:$@ $** mostlyclean: -del $(TINYCBOR_OBJS) clean: mostlyclean -del lib\tinycbor.lib if exist tests\Makefile (cd tests & $(MAKE) clean) distclean: clean if exist tests\Makefile (cd tests & $(MAKE) distclean) tag: @perl maketag.pl {src\}.c{src\}.obj: $(CC) -nologo $(CFLAGS) -Isrc -c -Fo$@ $< tinycbor-0.6.0/README000066400000000000000000000004631411450027100142240ustar00rootroot00000000000000Concise Binary Object Representation (CBOR) Library --------------------------------------------------- To build TinyCBOR: make If you want to change the compiler or pass extra compiler flags: make CC=clang CFLAGS="-m32 -Oz" LDFLAGS="-m32" Documentation: https://intel.github.io/tinycbor/current/ tinycbor-0.6.0/TODO000066400000000000000000000015131411450027100140310ustar00rootroot00000000000000==== To Do list for libcbor ==== === General === * API review * Benchmark * Write examples ** Simple decoder ** Decoder to JSON ** Windowed encoding/decoding (limited memory) === Encoder === * Write API docs * Add API for creating indeterminate-length arrays and maps * Add API for creating indeterminate-length strings * Add API for relaxing doubles to floats and to integers * Add length-checking of the sub-containers (#ifndef CBOR_ENCODER_NO_USER_CHECK) * Decide how to indicate number of bytes needed ** Suggestion: return negative number from the functions === Decoder === * Write functions not yet implemented * Add API for stream-decoding strings * Add API for checking known tags and simple types * (unlikely) Add API for checking the pairing of a tag and the tagged type * Write tests for error conditions * Fuzzy-test the decoder tinycbor-0.6.0/VERSION000066400000000000000000000000061411450027100144050ustar00rootroot000000000000000.6.0 tinycbor-0.6.0/examples/000077500000000000000000000000001411450027100151575ustar00rootroot00000000000000tinycbor-0.6.0/examples/examples.pro000066400000000000000000000000561411450027100175200ustar00rootroot00000000000000TEMPLATE = subdirs SUBDIRS = simplereader.pro tinycbor-0.6.0/examples/simplereader.c000066400000000000000000000110171411450027100177770ustar00rootroot00000000000000#include "../src/cbor.h" #include #include #include #include #include static uint8_t *readfile(const char *fname, size_t *size) { struct stat st; FILE *f = fopen(fname, "rb"); if (!f) return NULL; if (fstat(fileno(f), &st) == -1) return NULL; uint8_t *buf = malloc(st.st_size); if (buf == NULL) return NULL; *size = fread(buf, st.st_size, 1, f) == 1 ? st.st_size : 0; fclose(f); return buf; } static void indent(int nestingLevel) { while (nestingLevel--) printf(" "); } static void dumpbytes(const uint8_t *buf, size_t len) { printf("\""); while (len--) printf("\\x%02X", *buf++); printf("\""); } static CborError dumprecursive(CborValue *it, int nestingLevel) { while (!cbor_value_at_end(it)) { CborError err; CborType type = cbor_value_get_type(it); indent(nestingLevel); switch (type) { case CborArrayType: case CborMapType: { // recursive type CborValue recursed; assert(cbor_value_is_container(it)); puts(type == CborArrayType ? "Array[" : "Map["); err = cbor_value_enter_container(it, &recursed); if (err) return err; // parse error err = dumprecursive(&recursed, nestingLevel + 1); if (err) return err; // parse error err = cbor_value_leave_container(it, &recursed); if (err) return err; // parse error indent(nestingLevel); puts("]"); continue; } case CborIntegerType: { int64_t val; cbor_value_get_int64(it, &val); // can't fail printf("%lld\n", (long long)val); break; } case CborByteStringType: { uint8_t *buf; size_t n; err = cbor_value_dup_byte_string(it, &buf, &n, it); if (err) return err; // parse error dumpbytes(buf, n); puts(""); free(buf); continue; } case CborTextStringType: { char *buf; size_t n; err = cbor_value_dup_text_string(it, &buf, &n, it); if (err) return err; // parse error printf("\"%s\"\n", buf); free(buf); continue; } case CborTagType: { CborTag tag; cbor_value_get_tag(it, &tag); // can't fail printf("Tag(%lld)\n", (long long)tag); break; } case CborSimpleType: { uint8_t type; cbor_value_get_simple_type(it, &type); // can't fail printf("simple(%u)\n", type); break; } case CborNullType: puts("null"); break; case CborUndefinedType: puts("undefined"); break; case CborBooleanType: { bool val; cbor_value_get_boolean(it, &val); // can't fail puts(val ? "true" : "false"); break; } case CborDoubleType: { double val; if (false) { float f; case CborFloatType: cbor_value_get_float(it, &f); val = f; } else { cbor_value_get_double(it, &val); } printf("%g\n", val); break; } case CborHalfFloatType: { uint16_t val; cbor_value_get_half_float(it, &val); printf("__f16(%04x)\n", val); break; } case CborInvalidType: assert(false); // can't happen break; } err = cbor_value_advance_fixed(it); if (err) return err; } return CborNoError; } int main(int argc, char **argv) { if (argc != 2) { puts("simplereader "); return 1; } size_t length; uint8_t *buf = readfile(argv[1], &length); if (!buf) { perror("readfile"); return 1; } CborParser parser; CborValue it; CborError err = cbor_parser_init(buf, length, 0, &parser, &it); if (!err) err = dumprecursive(&it, 0); free(buf); if (err) { fprintf(stderr, "CBOR parsing failure at offset %ld: %s\n", it.ptr - buf, cbor_error_string(err)); return 1; } return 0; } tinycbor-0.6.0/examples/simplereader.pro000066400000000000000000000000761411450027100203600ustar00rootroot00000000000000CONFIG -= qt SOURCES = simplereader.c include(../src/src.pri) tinycbor-0.6.0/scripts/000077500000000000000000000000001411450027100150305ustar00rootroot00000000000000tinycbor-0.6.0/scripts/maketag.pl000066400000000000000000000046361411450027100170070ustar00rootroot00000000000000#!perl use strict; sub run(@) { open PROC, "-|", @_ or die("Cannot run $_[0]: $!"); my @out; while () { chomp; push @out, $_; } close PROC; return @out; } my @tags = run("git", "tag"); my @v = run("git", "show", "HEAD:VERSION"); my $v = $v[0]; my $tagfile = ".git/TAG_EDITMSG"; open TAGFILE, ">", $tagfile or die("Cannot create file for editing tag message: $!"); select TAGFILE; print "TinyCBOR release $v\n"; print "\n"; print "# Write something nice about this release here\n"; # Do we have a commit template? my @result = run("git", "config", "--get", "commit.template"); if (scalar @result) { open TEMPLATE, "<", $result[0]; map { print $_; }