├── .clang_complete ├── .codecov.yml ├── .gdbinit ├── .gitignore ├── .travis.sh ├── .travis.yml ├── CHANGELOG ├── LICENSE ├── MIGRATION ├── Makefile.am ├── README.md ├── autogen.sh ├── configure.ac ├── docs ├── design-rationale.md ├── getting-started.md ├── guide │ ├── allocators.md │ ├── buffers-and-journals.md │ ├── error-handling.md │ ├── messages.md │ ├── miscellaneous.md │ ├── repeated-fields.md │ ├── runtimes.md │ └── scalar-types.md ├── index.md └── similar-projects.md ├── examples ├── Makefile.am ├── decoding │ ├── Makefile.am │ ├── example.c │ └── person.proto ├── encoding │ ├── Makefile.am │ ├── example.c │ └── person.proto └── messages │ ├── Makefile.am │ ├── example.c │ └── person.proto ├── include ├── Makefile.am ├── protobluff.h └── protobluff │ ├── core.h │ ├── core │ ├── allocator.h │ ├── buffer.h │ ├── common.h │ ├── decoder.h │ ├── descriptor.h │ ├── encoder.h │ └── string.h │ ├── descriptor.h │ ├── message.h │ ├── message │ ├── buffer.h │ ├── common.h │ ├── cursor.h │ ├── field.h │ ├── journal.h │ ├── message.h │ ├── nested.h │ ├── oneof.h │ └── part.h │ ├── util.h │ └── util │ ├── chunk_allocator.h │ ├── descriptor.h │ └── validator.h ├── mkdocs.yml ├── src ├── Makefile.am ├── core │ ├── Makefile.am │ ├── allocator.c │ ├── allocator.h │ ├── buffer.c │ ├── buffer.h │ ├── common.h │ ├── decoder.c │ ├── decoder.h │ ├── descriptor.c │ ├── descriptor.h │ ├── encoder.c │ ├── encoder.h │ ├── stream.c │ ├── stream.h │ ├── varint.c │ └── varint.h ├── generator │ ├── Makefile.am │ ├── enum.cc │ ├── enum.hh │ ├── enum_value.cc │ ├── enum_value.hh │ ├── extension.cc │ ├── extension.hh │ ├── field.cc │ ├── field.hh │ ├── file.cc │ ├── file.hh │ ├── generator.cc │ ├── generator.hh │ ├── message.cc │ ├── message.hh │ ├── oneof.cc │ ├── oneof.hh │ ├── protoc-gen-protobluff.cc │ ├── strutil.cc │ └── strutil.hh ├── message │ ├── Makefile.am │ ├── buffer.c │ ├── buffer.h │ ├── common.c │ ├── common.h │ ├── cursor.c │ ├── cursor.h │ ├── field.c │ ├── field.h │ ├── journal.c │ ├── journal.h │ ├── message.c │ ├── message.h │ ├── nested.c │ ├── nested.h │ ├── oneof.c │ ├── oneof.h │ ├── part.c │ └── part.h ├── protobluff-lite.pc.in ├── protobluff.pc.in └── util │ ├── Makefile.am │ ├── chunk_allocator.c │ ├── chunk_allocator.h │ ├── descriptor.c │ ├── descriptor.h │ ├── validator.c │ └── validator.h ├── tests ├── Makefile.am ├── core │ ├── Makefile.am │ ├── buffer │ │ ├── Makefile.am │ │ └── test.c │ ├── decoder │ │ ├── Makefile.am │ │ └── test.c │ ├── descriptor │ │ ├── Makefile.am │ │ └── test.c │ ├── encoder │ │ ├── Makefile.am │ │ └── test.c │ ├── stream │ │ ├── Makefile.am │ │ └── test.c │ └── varint │ │ ├── Makefile.am │ │ └── test.c ├── coverage.css ├── message │ ├── Makefile.am │ ├── buffer │ │ ├── Makefile.am │ │ └── test.c │ ├── cursor │ │ ├── Makefile.am │ │ └── test.c │ ├── field │ │ ├── Makefile.am │ │ └── test.c │ ├── journal │ │ ├── Makefile.am │ │ └── test.c │ ├── message │ │ ├── Makefile.am │ │ └── test.c │ ├── nested │ │ ├── Makefile.am │ │ └── test.c │ ├── oneof │ │ ├── Makefile.am │ │ └── test.c │ └── part │ │ ├── Makefile.am │ │ └── test.c └── util │ ├── Makefile.am │ ├── chunk_allocator │ ├── Makefile.am │ └── test.c │ ├── descriptor │ ├── Makefile.am │ └── test.c │ └── validator │ ├── Makefile.am │ └── test.c └── valgrind.supp /.clang_complete: -------------------------------------------------------------------------------- 1 | -Isrc 2 | -Iinclude 3 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | coverage: 22 | 23 | # Coverage status 24 | status: 25 | 26 | # Overall project status 27 | project: 28 | default: 29 | enabled: yes 30 | target: auto 31 | threshold: 1% 32 | if_no_uploads: error 33 | if_not_found: success 34 | if_ci_failed: error 35 | 36 | # Pull request coverage diff 37 | patch: 38 | default: 39 | enabled: yes 40 | target: 95% 41 | threshold: 1% 42 | if_no_uploads: error 43 | if_not_found: success 44 | if_ci_failed: error 45 | 46 | # Unexpected changes 47 | changes: 48 | default: 49 | enabled: yes 50 | if_no_uploads: error 51 | if_not_found: success 52 | if_ci_failed: error 53 | 54 | # Comments inside pull requests 55 | comment: 56 | layout: header, tree, changes, files 57 | behavior: default 58 | paths: 59 | - src 60 | - tests 61 | -------------------------------------------------------------------------------- /.gdbinit: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # Set debugger flags 22 | set breakpoint pending on 23 | set pagination off 24 | set print array on 25 | set print pretty on 26 | 27 | # Add custom breakpoints here 28 | # break main 29 | 30 | # Instantly run application 31 | run 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # Files generated by autoconf 22 | aclocal.m4 23 | autom4te.cache/ 24 | autoscan.log 25 | compile 26 | config.* 27 | configure 28 | configure.scan 29 | depcomp 30 | install-sh 31 | libtool 32 | ltmain.sh 33 | missing 34 | m4 35 | stamp-h1 36 | test-driver 37 | *.pc 38 | Makefile 39 | Makefile.in 40 | 41 | # Files generated by automake 42 | .deps/ 43 | .dirstamp 44 | .libs/ 45 | 46 | # Files generated by dsymutil 47 | *.dSYM 48 | 49 | # Files generated by protobluff 50 | *.pb.c 51 | *.pb.h 52 | 53 | # Files generated by the build process 54 | *.la 55 | *.lo 56 | *.a 57 | *.o 58 | 59 | # Executables 60 | examples/**/example 61 | src/generator/protoc-gen-protobluff 62 | tests/**/test 63 | 64 | # Files generated by check 65 | tests/**/*.trs 66 | tests/**/*.log 67 | tests/*.log 68 | 69 | # Files generated by lcov and genhtml 70 | tests/coverage.info 71 | tests/coverage 72 | *.gcno 73 | *.gcda 74 | 75 | # Mac OS X internals 76 | .DS_Store 77 | 78 | # IDEs 79 | .vscode -------------------------------------------------------------------------------- /.travis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2013-2020 Martin Donath 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to 7 | # deal in the Software without restriction, including without limitation the 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | # sell copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | # IN THE SOFTWARE. 22 | 23 | # Exit, if one command fails 24 | set -e 25 | 26 | # Update coverage report 27 | codecov -X gcov 28 | 29 | # Deploy documentation to GitHub pages 30 | if [ "$TRAVIS_BRANCH" == "master" -a "$TRAVIS_PULL_REQUEST" == "false" ]; then 31 | REMOTE="https://${GH_TOKEN}@github.com/squidfunk/protobluff" 32 | 33 | # Install Material for MkDocs for documentation 34 | pip install --user mkdocs-material 35 | 36 | # Set configuration for repository and deploy documentation 37 | git config --global user.name "${GH_NAME}" 38 | git config --global user.email "${GH_EMAIL}" 39 | git remote set-url origin $REMOTE 40 | mkdocs gh-deploy --force 41 | fi 42 | 43 | # Terminate if we're not on a release branch 44 | echo "$TRAVIS_BRANCH" | grep -qvE "^[0-9.]+$" && exit 0; :; 45 | 46 | # Install dependencies for release build 47 | pip install --user wheel twine 48 | 49 | # Fix SSL warnings for Python > 2.7.9 50 | # https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl-py2 51 | pip install --user urllib3[secure] 52 | 53 | # Build and install theme and Docker image 54 | python setup.py build sdist bdist_wheel --universal 55 | docker build -t $TRAVIS_REPO_SLUG . 56 | 57 | # Prepare build regression test 58 | pushd /tmp 59 | mkdocs new test && cd test 60 | 61 | # Test Docker image build 62 | docker run --rm -it -v $(pwd):/docs $TRAVIS_REPO_SLUG build --theme material 63 | 64 | # Return to original directory 65 | popd 66 | 67 | # Push release to PyPI 68 | twine upload -u $PYPI_USERNAME -p $PYPI_PASSWORD dist/* 69 | 70 | # Push image to Docker Hub 71 | docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD 72 | docker tag $TRAVIS_REPO_SLUG $TRAVIS_REPO_SLUG:$TRAVIS_BRANCH 73 | docker tag $TRAVIS_REPO_SLUG $TRAVIS_REPO_SLUG:latest 74 | docker push $TRAVIS_REPO_SLUG 75 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | language: c 22 | 23 | # Always test GCC - Clang has problems with coverage report generation 24 | compiler: 25 | - gcc 26 | 27 | # Install dependencies 28 | before_install: 29 | 30 | # Upgrade autoconf to 2.69 31 | - sudo add-apt-repository ppa:dns/gnu -y 32 | - sudo apt-get update -qq 33 | - sudo apt-get install --only-upgrade autoconf 34 | - sudo apt-get install libtool 35 | 36 | # Install check 0.9.14 37 | - wget http://downloads.sourceforge.net/check/check-0.9.14.tar.gz 38 | - tar -xvf check-0.9.14.tar.gz 39 | - cd check-0.9.14 && ./configure --prefix=/usr && make && sudo make install 40 | - cd .. 41 | 42 | # Install lcov 1.11 43 | - wget http://downloads.sourceforge.net/ltp/lcov-1.13.tar.gz 44 | - tar -xvf lcov-1.13.tar.gz 45 | - cd lcov-1.13 && sudo make install 46 | - cd .. 47 | 48 | # Install codecov integration 49 | - pip install --user codecov 50 | 51 | # Generate build environment 52 | - ./autogen.sh 53 | 54 | # Perform build and tests 55 | script: 56 | - > 57 | ./configure --enable-coverage && 58 | make --silent && 59 | make --silent test coverage 60 | 61 | # Deploy artifacts 62 | after_success: 63 | - ./.travis.sh 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2020 Martin Donath 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /MIGRATION: -------------------------------------------------------------------------------- 1 | 0.5.0 => 1.0.0 2 | 3 | Messages 4 | 5 | Raw pointer access has been removed, because unaligned access of floats 6 | and doubles may cause undefined behavior on some architectures. Now, the 7 | values should be loaded and stored with the get and put accessors. 8 | 9 | This makes it necessary to regenerate the bindings and change all accessors 10 | that write values through raw pointers. 11 | 12 | < 1.0.0: 13 | 14 | float *value = person_raw_weight(&person); 15 | 16 | = 1.0.0: 17 | 18 | float value; 19 | person_get_weight(&person, &value); 20 | person_put_weight(&person, &value); 21 | 22 | 0.4.0 => 0.5.0 23 | 24 | The bindings have to be regenerated. 25 | 26 | 0.3.x => 0.4.0 27 | 28 | Encoder 29 | 30 | In order to handle packed fields, the encoder does now take a fourth 31 | argument, namely the amount of values to be encoded. This is a prerequisite 32 | for the support of packed fields. Now, multiple values can be encoded all 33 | at once, regardless of whether a field is packed or not. This also applies 34 | for messages, which have already been implemented as nested encoders. 35 | 36 | This makes it necessary to regenerate the bindings and change all accessors 37 | that write values to repeated fields. 38 | 39 | < 0.4.0: 40 | 41 | pb_encoder_t person = person_encoder_create(...); 42 | person_encode_phone(&person, &phonenumbers[0]); 43 | person_encode_phone(&person, &phonenumbers[1]); 44 | 45 | = 0.4.0: 46 | 47 | pb_encoder_t person = person_encoder_create(...); 48 | person_encode_phone(&person, &phonenumbers, 2); 49 | 50 | 0.2.x => 0.3.0 51 | 52 | Binaries 53 | 54 | The "binary" which holds the underlying serialized data in wire format was 55 | renamed to be a "buffer". Additionally, the journaling functionality is now 56 | part of a "journal" which itself contains a buffer that is tracked. The 57 | former is necessary for encoding and decoding messages, the later for 58 | performing random access on encoded messages. 59 | 60 | < 0.3.0: 61 | 62 | pb_binary_t binary = pb_binary_create(...); 63 | pb_binary_destroy(&binary); 64 | 65 | = 0.3.0: 66 | 67 | pb_buffer_t buffer = pb_buffer_create(...); 68 | pb_buffer_destroy(&buffer); 69 | 70 | pb_journal_t journal = pb_journal_create(...); 71 | pb_journal_destroy(&journal); 72 | 73 | Validation 74 | 75 | Message validation was refactored into a separate "validator" structure, 76 | so that validation can directly take place on a buffer. This step was 77 | necessary to make validation available to the lite runtime. 78 | 79 | < 0.3.0: 80 | 81 | pb_message_t message = pb_message_create(...); 82 | pb_message_check(&message); 83 | 84 | = 0.3.0: 85 | 86 | pb_validator_t validator = pb_validator_create(...); 87 | pb_validator_check(&validator, &buffer); 88 | 89 | 0.1.x => 0.2.0 90 | 91 | Validation 92 | 93 | The function for message validation was renamed into pb_message_check() in 94 | order to remove any ambiguities with pb_message_valid() which checks if the 95 | message is still valid in terms of alignment. 96 | 97 | < 0.2.0 98 | 99 | pb_message_t message = pb_message_create(...); 100 | pb_message_validate(&message); 101 | 102 | = 0.2.0 103 | 104 | pb_message_t message = pb_message_create(...); 105 | pb_message_check(&message); 106 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Subdirectories 23 | # ----------------------------------------------------------------------------- 24 | 25 | SUBDIRS = include src tests 26 | 27 | # ----------------------------------------------------------------------------- 28 | # pkg-config configuration 29 | # ----------------------------------------------------------------------------- 30 | 31 | # Create pkg-config recipe 32 | pkgconfigdir = @libdir@/pkgconfig 33 | pkgconfig_DATA = \ 34 | src/protobluff.pc \ 35 | src/protobluff-lite.pc 36 | 37 | # ----------------------------------------------------------------------------- 38 | # Custom build rules 39 | # ----------------------------------------------------------------------------- 40 | 41 | # Alias check with test 42 | test: check 43 | 44 | # Clean profiling information 45 | clean-local: 46 | find src -name '*.gcda' -type f -delete 47 | find src -name '*.gcno' -type f -delete 48 | 49 | # Purge development files 50 | purge: clean 51 | find . -depth -name '.deps*' -exec rm -rf '{}' \; 52 | find . -depth -name '.libs*' -exec rm -rf '{}' \; 53 | find . -name 'Makefile' -type f -delete 54 | find . -name 'Makefile.in' -type f -delete 55 | find . -name '.dirstamp' -type f -delete 56 | find . -name '.DS_Store' -type f -delete 57 | find . -name '*.log' -type f -delete 58 | find . -name '*.trs' -type f -delete 59 | find . -name '*.pc' -type f -delete 60 | rm -f aclocal.m4 61 | rm -rf autom4te.cache 62 | rm -f autoscan.log 63 | rm -f compile 64 | rm -f configure 65 | rm -f configure.scan 66 | rm -f config.* 67 | rm -f depcomp 68 | rm -f install-sh 69 | rm -f libtool 70 | rm -f ltmain.sh 71 | rm -rf m4 72 | rm -f missing 73 | rm -f stamp-h1 74 | rm -f test-driver 75 | 76 | # ----------------------------------------------------------------------------- 77 | # Coverage report 78 | # ----------------------------------------------------------------------------- 79 | 80 | if HAVE_COVERAGE 81 | 82 | # Generate and display code coverage report 83 | coverage: 84 | @LCOV@ -q -c --no-external -d @top_builddir@/src -o tests/coverage.info 85 | @GENHTML@ tests/coverage.info -o tests/coverage -c tests/coverage.css 86 | 87 | endif # HAVE_COVERAGE 88 | 89 | # ----------------------------------------------------------------------------- 90 | # Leak check 91 | # ----------------------------------------------------------------------------- 92 | 93 | if HAVE_VALGRIND 94 | 95 | # Perform leak check using unit tests 96 | memcheck: check 97 | @for t in `find tests -maxdepth 3 -perm +111 -type f`; do \ 98 | @LIBTOOL@ --mode=execute @VALGRIND@ --dsymutil=yes --tool=memcheck \ 99 | --track-origins=yes --leak-check=full --show-reachable=yes \ 100 | --suppressions=valgrind.supp $$t; \ 101 | done 102 | 103 | endif # HAVE_VALGRIND 104 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2013-2020 Martin Donath 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to 7 | # deal in the Software without restriction, including without limitation the 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | # sell copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | # IN THE SOFTWARE. 22 | 23 | # Sometimes autoreconf doesn't create m4 directory, so do it explicitly 24 | mkdir m4 > /dev/null 2>&1 25 | 26 | # 1st pass: generate relevant files 27 | command -v autoreconf > /dev/null 2>&1 28 | if [ $? -ne 0 ]; then 29 | echo "autogen.sh: error: could not find autoreconf." 1>&2 30 | echo "autoconf is required to run autogen.sh." 1>&2 31 | exit 1 32 | fi 33 | 34 | # Generate Makefile.in from Makefile.am 35 | command -v automake --add-missing > /dev/null 2>&1 36 | if [ $? -ne 0 ]; then 37 | echo "autogen.sh: error: could not find automake." 1>&2 38 | echo "automake is required to run autogen.sh." 1>&2 39 | exit 1 40 | fi 41 | 42 | # Generate files to build shared libraries 43 | command -v libtoolize > /dev/null 2>&1 44 | if [ $? -ne 0 ]; then 45 | echo "autogen.sh: error: could not find libtool." 1>&2 46 | echo "libtool is required to run autogen.sh." 1>&2 47 | exit 1 48 | fi 49 | 50 | # 2nd pass: generate configure script 51 | autoreconf --install --force --verbose 52 | if [ $? -ne 0 ]; then 53 | echo "autogen.sh: error: autoreconf exited with status $?" 1>&2 54 | exit 1 55 | fi 56 | -------------------------------------------------------------------------------- /docs/design-rationale.md: -------------------------------------------------------------------------------- 1 | ## The problem with Protocol Buffers 2 | 3 | [Protocol Buffers][] is a language-neutral, platform-neutral and extensible 4 | message format developed by Google for serializing structured data. It uses 5 | schema files to describe the structure of messages, which are in turn used to 6 | generate language-specific bindings to automatically handle the decoding and 7 | encoding logic for the developer. 8 | 9 | In most language-specific bindings, a Protocol Buffers message is entirely read 10 | and decoded to a native structure (like a `struct` in C or a `class` in C++) 11 | in a transparent manner. The problem is that this may involve a **large number 12 | of allocations**, especially for deeply nested and repeated messages. This is 13 | particularly wasteful if only a few fields are needed in order to process a 14 | message, e.g. to decode the header for efficient routing or to update single 15 | fields/values within large messages. 16 | 17 | ## A different approach 18 | 19 | protobluff follows a different approach: it omits the need to decode a 20 | Protocol Buffers message entirely in order to process it – **all operations are 21 | directly carried out on the encoded message**, so only specific parts/fields of 22 | the encoded message need to be decoded. The same is true for encoding – only 23 | the value that needs to be altered must be encoded, the rest of the message 24 | remains untouched. 25 | 26 | The **technical design goals** behind protobluff are: 27 | 28 | * **Errors are handled gracefully, at all times**. protobluff anticipates 29 | errors like garbled data (regression via fuzzing tests) or out-of-memory 30 | conditions and returns an error to the caller. All invariants are checked 31 | with asserts, all runtime errors are checked during program execution. All 32 | structures contain a valid flag/state. When passing an invalid structure to 33 | a function, the program does not crash. 34 | 35 | * **Stack-allocation is used wherever possible**, so the programmer can decide 36 | on where to use dynamic and static allocation. Memory management is 37 | centralized, which significantly reduces programming errors. 38 | 39 | * **The runtime should be extensible**, i.e. it should be easy to write parsers 40 | and printers for other formats like JSON or XML or other functionality on top 41 | of the core library. 42 | 43 | Furthermore, protobluff comes with two [runtimes](/guide/runtimes/): a **lite 44 | runtime** which enables easy and efficient stream-processing of Protocol 45 | Buffers messages via a callback-based decoder and an encoder, and a **full 46 | runtime** which adds support for partial reads and writes of messages. New 47 | values can be read or written incrementally, memory management is centralized 48 | and handled by the underlying [journal](/guide/buffers-and-journals/). If no 49 | alterations that change the size of the underlying journal are expected, the 50 | journal can be used in zero-copy mode, omitting all dynamic allocations. 51 | 52 | ## Trade-offs 53 | 54 | In software development, everything is a trade-off. protobluff doesn't check 55 | the encoded messages for validity, i.e. whether all required fields are set. 56 | This should be done by the programmer using the validator explicitly, and is 57 | attributed to the fact that protobluff enables incremental reading and writing 58 | of messages, as discussed above. Moreover it is redundant when the programmer 59 | knows that a message is valid (e.g. when the messages comes from a database). 60 | 61 | The lite runtime is efficient for decoding and encoding whole messages. The 62 | full runtime should be used when only a few fields of a message need to be 63 | read or written. At the time of writing, protobluff is not very efficient when 64 | decoding an encoding entire messages with the full runtime over and over. There 65 | are other libraries for that. However, as protobluff has a modular design, this 66 | functionality could be added if needed. 67 | 68 | [Protocol Buffers]: https://developers.google.com/protocol-buffers 69 | -------------------------------------------------------------------------------- /docs/guide/allocators.md: -------------------------------------------------------------------------------- 1 | ## Interface 2 | 3 | The interface for the allocator that needs to be implemented is defined in 4 | `core/allocator.h`: 5 | 6 | ``` c 7 | typedef void * 8 | (*pb_allocator_alloc_f)( 9 | void *data, /*!< Internal allocator data */ 10 | size_t size); /*!< Bytes to be allocated */ 11 | 12 | typedef void * 13 | (*pb_allocator_realloc_f)( 14 | void *data, /*!< Internal allocator data */ 15 | void *block, /*!< Memory block to be resized */ 16 | size_t size); /*!< Bytes to be allocated */ 17 | 18 | typedef void 19 | (*pb_allocator_free_f)( 20 | void *data, /*!< Internal allocator data */ 21 | void *block); /*!< Memory block to be freed */ 22 | 23 | typedef struct pb_allocator_t { 24 | struct { 25 | pb_allocator_alloc_f alloc; /*!< Allocate a memory block */ 26 | pb_allocator_realloc_f realloc; /*!< Resize a memory block */ 27 | pb_allocator_free_f free; /*!< Free a memory block */ 28 | } proc; 29 | void *data; /*!< Internal allocator data */ 30 | } pb_allocator_t; 31 | ``` 32 | 33 | Custom allocators can be used with buffers, journals and encoders. 34 | 35 | ## Implementations 36 | 37 | ### Default allocator 38 | 39 | The default allocator is globally defined through the variable 40 | `allocator_default`. 41 | 42 | ### Chunk allocator 43 | 44 | Starting with protobluff 0.2.2, a chunk allocator implementation is included 45 | in the full runtime. Memory blocks are stored in pre-allocated chunks to 46 | account for later growth by allocating more space than is needed upfront. If 47 | the block grows inside the corresponding chunk's capacity, the same block is 48 | returned. Otherwise, the chunk is doubled in size to make room for more growth: 49 | 50 | ``` c 51 | pb_allocator_t allocator = pb_allocator_chunk_create(); 52 | pb_allocator_t allocator = pb_allocator_chunk_create_with_capacity(1024); 53 | ... 54 | pb_allocator_chunk_destroy(&allocator); 55 | ``` 56 | -------------------------------------------------------------------------------- /docs/guide/miscellaneous.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | The following document discusses some proto2 features, that don't have a huge 4 | impact on message handling. 5 | 6 | ## Oneofs 7 | 8 | protobluff is capable of handling oneofs. It is even designed to handle oneofs 9 | in some edge cases, like merged messages, where multiple instances of a oneof 10 | may occur. When setting a field that is part of a oneof, protobluff ensures 11 | that the field is not overshadowed by a later instance by traversing the cursor 12 | to the end and erasing all members of the oneof. 13 | 14 | Furthermore, for each oneof, the code generator will create a function to 15 | determine which member of a oneof is currently active. This function returns 16 | a tag number and can be used inside a `switch` statement. 17 | 18 | ## Extensions 19 | 20 | Extensions are implemented as a linked list of descriptors. They may be defined 21 | in file or message scope (the latter are known as nested extensions). The 22 | code generator will infix extensions with `_X_`, in order to avoid name clashes 23 | with existing fields. Extensions are initialized automatically upon start up 24 | of the program through constructor attributes. 25 | 26 | ## Packages 27 | 28 | If a `.proto` file defines a package, the name of the package is prefixed to 29 | all variables and functions defined inside that file. This is especially useful 30 | to avoid name clashes between packages. 31 | 32 | ## Deprecations 33 | 34 | Inside a `.proto` schema file, fields, messages, enums and enum values can be 35 | annotated with the `deprecated` option. protobluff will flag all functions that 36 | access the annotated structure with `PB_DEPRECATED`, a compiler attribute to 37 | signal deprecated access. This will trigger warnings during compilation without 38 | any runtime penalty. 39 | -------------------------------------------------------------------------------- /docs/guide/repeated-fields.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | protobluff implements the concept of a cursor to access separate instances of a 4 | repeated field within an encoded message. Cursors are capable of handling 5 | tag/value-encoded fields, as well as packed fields very well. 6 | 7 | The following explanations on handling repeated fields are based on the example 8 | message type defined in the section on 9 | [working with messages](/guide/messages/#defining-a-message-type). 10 | 11 | ## Creating a cursor 12 | 13 | A cursor over a message for a repeated field can be created as follows: 14 | 15 | ``` c 16 | pb_cursor_t cursor = person_create_phone_cursor(&person); 17 | if (!pb_cursor_valid(&cursor)) 18 | /* Error creating cursor on phone numbers */ 19 | } 20 | ``` 21 | 22 | The cursor will always either point to a valid instance of a repeated field or 23 | be invalid. If the cursor isn't valid, the cursor may either have encountered 24 | garbled data or there is no instance for the repeated field. 25 | 26 | ## Working with a cursor 27 | 28 | After checking if the cursor is valid, the current field may be read, written 29 | or erased. While scalar types may be directly read and written through the 30 | cursor, submessages must be created from the cursor in order to work with them. 31 | Erasing a field is independent of its type. 32 | 33 | ### Submessages 34 | 35 | Submessages must be created through the function `pb_message_create_from_cursor` 36 | which will return a message of type `pb_message_t`: 37 | 38 | ``` c 39 | pb_cursor_t cursor = person_create_phone_cursor(&person); 40 | if (!pb_cursor_valid(&cursor)) { 41 | do { 42 | pb_message_t phone = pb_message_create_from_cursor(&cursor); 43 | if (!pb_message_valid()) 44 | break; 45 | ... 46 | person_phonenumber_destroy(&phone); 47 | } while (pb_cursor_next(&cursor)) 48 | } 49 | ``` 50 | 51 | The fields of the message can then be normally accessed as described in the 52 | section on [working with messages](/guide/messages/). After working with the 53 | message, it must be explicitly destroyed. 54 | 55 | ### Scalar types 56 | 57 | Scalar types may be accessed through the functions `pb_cursor_get`, 58 | `pb_cursor_put` and `pb_cursor_erase`, like in the following example: 59 | 60 | ``` c 61 | pb_cursor_t cursor = ... 62 | if (!pb_cursor_valid(&cursor)) { 63 | pb_error_t error = PB_ERROR_NONE; 64 | 65 | /* Iterate instances of repeated field */ 66 | do { 67 | uint32_t value; 68 | if (error = pb_cursor_get(&cursor, &value))) 69 | break; 70 | 71 | /* Erase value if equal to 0 */ 72 | if (value == 0) { 73 | error = pb_cursor_erase(&cursor); 74 | 75 | /* Otherwise decrement value */ 76 | } else { 77 | value--; 78 | error = pb_cursor_put(&cursor, &value); 79 | } 80 | } while (!error && pb_cursor_next(&cursor)) 81 | } 82 | ``` 83 | 84 | ## Freeing a cursor 85 | 86 | Like messages, cursors should always be explicitly destroyed to be 87 | future-proof: 88 | 89 | ``` c 90 | pb_cursor_destroy(&cursor); 91 | ``` 92 | -------------------------------------------------------------------------------- /docs/guide/scalar-types.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | The Protocol Buffers specification defines a multitude of signed and unsigned 4 | integer types (each with different implications for the underlying wire 5 | representation), as well as types for the representation of floating point 6 | numbers, booleans, bytes and strings. 7 | 8 | ## Type mappings 9 | 10 | The following table shows the type mappings from C types (both native and 11 | custom types like `pb_string_t`) to Protocol Buffer schema types: 12 | 13 | | Native type | Schema type | 14 | |---------------|------------------------------| 15 | | `int32_t` | `int32`, `sint32`, `fixed32` | 16 | | `int64_t` | `int64`, `sint64`, `fixed64` | 17 | | `uint8_t` | `bool` | 18 | | `uint32_t` | `uint32`, `fixed32` | 19 | | `uint64_t` | `uint64`, `fixed64` | 20 | | `float` | `float` | 21 | | `double` | `double` | 22 | | `pb_enum_t` | `enum` | 23 | | `pb_string_t` | `bytes`, `string` | 24 | 25 | See the [Protocol Buffers specification][] for more information on types. 26 | 27 | ## Strings and byte arrays 28 | 29 | While the mappings of integer and floating point types should be quite 30 | self-explanatory, strings are worth discussing: in wire representation, strings 31 | and byte arrays are stored as a length-prefixed, unterminated list of unsigned 32 | chars. Because there's no nul-terminator, the length needs to be explicitly 33 | returned. This is what the datatype `pb_string_t` is for. The header file 34 | `core/string.h` defines a few useful functions for working with strings: 35 | 36 | ``` c 37 | /* Initialize a string with explicit length */ 38 | pb_string_t string = pb_string_init("TEST", 4); 39 | 40 | /* Initialize a string from a nul-terminated array of unsigned chars */ 41 | pb_string_t string = pb_string_init_from_chars("TEST"); 42 | 43 | /* Initialize an empty string - may be useful at times */ 44 | pb_string_t string = pb_string_init_empty(); 45 | 46 | /* Retrieve the underlying data and size of a string */ 47 | const uint8_t *data = pb_string_data(&string); 48 | const size_t size = pb_string_size(&string); 49 | ``` 50 | 51 | Strings are always allocated on the stack and do not take ownership of the 52 | provided array of unsigned chars, so there's no need for freeing them, but the 53 | caller must ensure that the array is not freed during operations. 54 | 55 | [Protocol Buffers specification]: https://developers.google.com/protocol-buffers/docs/proto?hl=en#scalar 56 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | protobluff is a modular Protocol Buffers implementation for C. 2 | -------------------------------------------------------------------------------- /docs/similar-projects.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | protobluff is not the only C implementation for Protocol Buffers in the world, 4 | but it's actually one of the more recent ones. It has a different approach for 5 | handling messages than other libraries, like already described in the 6 | [designal rationale](/design-rationale/). 7 | 8 | This document compares protobluff to other Protocol Buffers implementations 9 | for the C language, in particular [protobuf-c][], [nanopb][], [lwpb][] and 10 | [pbc][]. Compared are only libraries that are not exclusively targeted at 11 | microcontrollers, but are designed for 32- and 64-bit systems. 12 | 13 | ## Feature comparison 14 | 15 | ### proto2 16 | 17 | protobluff implements all features of the Protocol Buffers specification 18 | version 2 (known as proto2), except groups and generic services which are both 19 | deprecated. However, as Google is pushing out [gRPC][], there may be a 20 | gRPC-based service implementation in form of a plugin in the future. Below is 21 | a table showing the supported features of protobluff next to other Protocol 22 | Buffers libraries for C: 23 | 24 | | Feature / Implementation | protobluff | protobuf-c | nanopb | lwpb | pbc | 25 | |--------------------------|------------|------------|---------|------|-----| 26 | | Message types | yes | yes | yes | yes | yes | 27 | | Nested message types | yes | yes | yes | yes | yes | 28 | | Cyclic message types | yes | yes | partial | yes | yes | 29 | | Scalar types | yes | yes | yes | yes | yes | 30 | | Default values | yes | yes | yes | yes | yes | 31 | | Enumerations | yes | yes | yes | yes | yes | 32 | | Extensions | yes | - | yes | - | yes | 33 | | Oneofs | yes | yes | yes | - | - | 34 | | Packages | yes | yes | yes | yes | yes | 35 | | Packed option | yes | yes | yes | yes | yes | 36 | | Deprecations | yes | partial | - | - | - | 37 | 38 | In respect to the deprecation of generic services and groups, protobluff is the 39 | only library which is feature complete. [nanopb][] is pretty close: it only 40 | misses deprecations and is inconvenient for working with cyclic messages. 41 | Furthermore, it's targeted at microcontrollers. [protobuf-c][] doesn't support 42 | extensions and supports deprecations for fields only. [lwpb][] and [pbc][] seem 43 | inactive, as they don't support oneofs, a feature introduced in version 2.6. 44 | 45 | Both, protobuf-c and lwpb provide a custom service implementation. However, the 46 | benefit is questionable, because the way messages are handled within a service 47 | may be highly application-dependent. Therefore, the solution proposed by both 48 | libraries may or may not be a good fit for your application. This is the reason 49 | why Google deprecated generic services and open sourced gRPC to provide a 50 | standard protocol for service interaction and integration. 51 | 52 | ### proto3 53 | 54 | The newest version of the Protocol Buffers specification is 55 | [version 3][Protocol Buffers specification] (known as proto3) which is 56 | wire-compatible with proto2. protobluff is basically compatible with proto3 – 57 | it will compile with the proto3 runtime, but it is not yet optimized for the 58 | new syntax. 59 | 60 | The main features that need to be implemented for full proto3 support are 61 | maps and the **Any** type as a replacement for extensions, as well as some 62 | helper functions for working with the new set of default types and maybe the 63 | new JSON-mapping. However, the last two are of lower priority. 64 | 65 | At the time of writing, none of the aforementioned alternative implementations 66 | supports proto3 yet. 67 | 68 | [protobuf-c]: https://github.com/protobuf-c/protobuf-c 69 | [nanopb]: https://github.com/nanopb/nanopb 70 | [lwpb]: https://github.com/acg/lwpb 71 | [pbc]: https://github.com/cloudwu/pbc 72 | [gRPC]: http://grpc.io 73 | [Protocol Buffers specification]: https://developers.google.com/protocol-buffers/docs/proto3?hl=en 74 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Subdirectories 23 | # ----------------------------------------------------------------------------- 24 | 25 | SUBDIRS = decoding encoding messages -------------------------------------------------------------------------------- /examples/decoding/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Example: decoding 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build decoding example 26 | bin_PROGRAMS = example 27 | example_SOURCES = \ 28 | example.c 29 | nodist_example_SOURCES = \ 30 | person.pb.c \ 31 | person.pb.h 32 | example_CFLAGS = \ 33 | -g 34 | example_LDADD = \ 35 | @top_builddir@/src/libprotobluff.la 36 | 37 | # ----------------------------------------------------------------------------- 38 | # Custom build rules 39 | # ----------------------------------------------------------------------------- 40 | 41 | # Generate bindings before build 42 | BUILT_SOURCES = \ 43 | $(nodist_example_SOURCES) 44 | 45 | # Clean generated bindings 46 | CLEANFILES = \ 47 | $(nodist_example_SOURCES) 48 | 49 | # Don't install examples 50 | install: 51 | install-strip: 52 | 53 | # ----------------------------------------------------------------------------- 54 | # Generate Protocol Buffers bindings 55 | # ----------------------------------------------------------------------------- 56 | 57 | # Invoke protoc compiler on *.proto files 58 | %.pb.c %.pb.h: %.proto 59 | @PROTOC@ --protobluff_out=. $? 60 | -------------------------------------------------------------------------------- /examples/decoding/person.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2020 Martin Donath 2 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | message Person { 22 | message PhoneNumber { 23 | enum PhoneType { 24 | MOBILE = 0; 25 | HOME = 1; 26 | WORK = 2; 27 | } 28 | required string number = 1; 29 | optional PhoneType type = 2 [default = HOME]; 30 | } 31 | required string name = 1; 32 | required int32 id = 2; 33 | optional string email = 3; 34 | repeated PhoneNumber phone = 4; 35 | } 36 | -------------------------------------------------------------------------------- /examples/encoding/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Example: encoding 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build encoding example 26 | bin_PROGRAMS = example 27 | example_SOURCES = \ 28 | example.c 29 | nodist_example_SOURCES = \ 30 | person.pb.c \ 31 | person.pb.h 32 | example_CFLAGS = \ 33 | -g 34 | example_LDADD = \ 35 | @top_builddir@/src/libprotobluff.la 36 | 37 | # ----------------------------------------------------------------------------- 38 | # Custom build rules 39 | # ----------------------------------------------------------------------------- 40 | 41 | # Generate bindings before build 42 | BUILT_SOURCES = \ 43 | $(nodist_example_SOURCES) 44 | 45 | # Clean generated bindings 46 | CLEANFILES = \ 47 | $(nodist_example_SOURCES) 48 | 49 | # Don't install examples 50 | install: 51 | install-strip: 52 | 53 | # ----------------------------------------------------------------------------- 54 | # Generate Protocol Buffers bindings 55 | # ----------------------------------------------------------------------------- 56 | 57 | # Invoke protoc compiler on *.proto files 58 | %.pb.c %.pb.h: %.proto 59 | @PROTOC@ --protobluff_out=. $? -------------------------------------------------------------------------------- /examples/encoding/example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "person.pb.h" 28 | 29 | /* ---------------------------------------------------------------------------- 30 | * Program 31 | * ------------------------------------------------------------------------- */ 32 | 33 | /*! 34 | * Encode a person message and dump it. 35 | * 36 | * This is one of two examples (together with the messages example) showing 37 | * how to build a Protocol Buffers message with protobluff. While this approach 38 | * is significantly faster since it doesn't have to realign the message after 39 | * every update, it is not possible to update values after they were written, 40 | * which is easily done with the other approach. For optional and required 41 | * fields that are written multiple times only the last occurrence will be 42 | * reported when decoding the Protocol Buffers message, as demanded by the 43 | * Protocol Buffers specification. 44 | * 45 | * \return Exit code 46 | */ 47 | int 48 | main(void) { 49 | 50 | /* Create a person encoder */ 51 | pb_encoder_t person = person_encoder_create(); 52 | 53 | /* Define the values we want to set */ 54 | pb_string_t name = pb_string_init_from_chars("John Doe"), 55 | email = pb_string_init_from_chars("jdoe@example.com"), 56 | home = pb_string_init_from_chars("+1-541-754-3010"), 57 | mobile = pb_string_init_from_chars("+1-541-293-8228"); 58 | int32_t id = 1234; 59 | 60 | /* Encode values for person message and check return codes */ 61 | pb_error_t error = PB_ERROR_NONE; 62 | do { 63 | if ((error = person_encode_name(&person, &name)) || 64 | (error = person_encode_id(&person, &id)) || 65 | (error = person_encode_email(&person, &email))) 66 | break; 67 | 68 | /* Set home and mobile number */ 69 | pb_encoder_t phone[] = { 70 | person_phonenumber_encoder_create(), 71 | person_phonenumber_encoder_create() 72 | }; 73 | if (!(error = person_phonenumber_encode_number(&(phone[0]), &home)) && 74 | !(error = person_phonenumber_encode_type_home(&(phone[0]))) && 75 | !(error = person_phonenumber_encode_number(&(phone[1]), &mobile)) && 76 | !(error = person_phonenumber_encode_type_mobile(&(phone[1]))) && 77 | !(error = person_encode_phone(&person, phone, 2))) { 78 | 79 | /* Dump the internal buffer */ 80 | const pb_buffer_t *buffer = pb_encoder_buffer(&person); 81 | pb_buffer_dump(buffer); 82 | 83 | /* The encoded message can be accessed as follows */ 84 | // const uint8_t *data = pb_buffer_data(buffer); 85 | // const size_t size = pb_buffer_size(buffer); 86 | } 87 | person_phonenumber_encoder_destroy(&(phone[0])); 88 | person_phonenumber_encoder_destroy(&(phone[1])); 89 | } while (0); 90 | 91 | /* Print error, if any */ 92 | if (error) 93 | fprintf(stderr, "ERROR: %s\n", pb_error_string(error)); 94 | 95 | /* Free all allocated memory and return */ 96 | person_encoder_destroy(&person); 97 | return error 98 | ? EXIT_FAILURE 99 | : EXIT_SUCCESS; 100 | } -------------------------------------------------------------------------------- /examples/encoding/person.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2020 Martin Donath 2 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | message Person { 22 | message PhoneNumber { 23 | enum PhoneType { 24 | MOBILE = 0; 25 | HOME = 1; 26 | WORK = 2; 27 | } 28 | required string number = 1; 29 | optional PhoneType type = 2 [default = HOME]; 30 | } 31 | required string name = 1; 32 | required int32 id = 2; 33 | optional string email = 3; 34 | repeated PhoneNumber phone = 4; 35 | } -------------------------------------------------------------------------------- /examples/messages/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Example: messages 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build messages example 26 | bin_PROGRAMS = example 27 | example_SOURCES = \ 28 | example.c 29 | nodist_example_SOURCES = \ 30 | person.pb.c \ 31 | person.pb.h 32 | example_CFLAGS = \ 33 | -g 34 | example_LDADD = \ 35 | @top_builddir@/src/libprotobluff.la 36 | 37 | # ----------------------------------------------------------------------------- 38 | # Custom build rules 39 | # ----------------------------------------------------------------------------- 40 | 41 | # Generate bindings before build 42 | BUILT_SOURCES = \ 43 | $(nodist_example_SOURCES) 44 | 45 | # Clean generated bindings 46 | CLEANFILES = \ 47 | $(nodist_example_SOURCES) 48 | 49 | # Don't install examples 50 | install: 51 | install-strip: 52 | 53 | # ----------------------------------------------------------------------------- 54 | # Generate Protocol Buffers bindings 55 | # ----------------------------------------------------------------------------- 56 | 57 | # Invoke protoc compiler on *.proto files 58 | %.pb.c %.pb.h: %.proto 59 | @PROTOC@ --protobluff_out=. $? 60 | -------------------------------------------------------------------------------- /examples/messages/example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "person.pb.h" 28 | 29 | /* ---------------------------------------------------------------------------- 30 | * Program 31 | * ------------------------------------------------------------------------- */ 32 | 33 | /*! 34 | * Create a person message and dump it. 35 | * 36 | * This is not the fastest approach for building messages from the ground up. 37 | * When setting fields one-by-one, protobluff will determine the offset of a 38 | * field and adjust the length prefixes of the wrapping messages everytime. 39 | * If speed is a concern consider using an encoder instead. However, when 40 | * setting or retrieving single fields from a message this is by far the 41 | * fastest approach, as only the necessary parts of the message have to be 42 | * decoded, not the whole message. Additionally dynamic memory allocation 43 | * can be completley omitted. 44 | * 45 | * \return Exit code 46 | */ 47 | int 48 | main(void) { 49 | 50 | /* Create an empty journal to assemble a new person message */ 51 | pb_journal_t journal = pb_journal_create_empty(); 52 | 53 | /* Create a person message */ 54 | pb_message_t person = person_create(&journal); 55 | 56 | /* Define the values we want to set */ 57 | pb_string_t name = pb_string_init_from_chars("John Doe"), 58 | email = pb_string_init_from_chars("jdoe@example.com"), 59 | home = pb_string_init_from_chars("+1-541-754-3010"), 60 | mobile = pb_string_init_from_chars("+1-541-293-8228"); 61 | int32_t id = 1234; 62 | 63 | /* Set values on person message and check return codes */ 64 | pb_error_t error = PB_ERROR_NONE; 65 | do { 66 | if ((error = person_put_name(&person, &name)) || 67 | (error = person_put_id(&person, &id)) || 68 | (error = person_put_email(&person, &email))) 69 | break; 70 | 71 | /* Set home number */ 72 | pb_message_t phone1 = person_create_phone(&person); 73 | if (!(error = person_phonenumber_put_number(&phone1, &home)) && 74 | !(error = person_phonenumber_put_type_home(&phone1))) { 75 | 76 | /* Set mobile number */ 77 | pb_message_t phone2 = person_create_phone(&person); 78 | if (!(error = person_phonenumber_put_number(&phone2, &mobile)) && 79 | !(error = person_phonenumber_put_type_mobile(&phone2))) { 80 | 81 | /* Dump the journal */ 82 | pb_journal_dump(&journal); 83 | 84 | /* The encoded message can be accessed as follows */ 85 | // const uint8_t *data = pb_journal_data(&journal); 86 | // const size_t size = pb_journal_size(&journal); 87 | } 88 | person_phonenumber_destroy(&phone2); 89 | } 90 | person_phonenumber_destroy(&phone1); 91 | } while (0); 92 | 93 | /* Print error, if any */ 94 | if (error) 95 | fprintf(stderr, "ERROR: %s\n", pb_error_string(error)); 96 | 97 | /* Cleanup and invalidate */ 98 | person_destroy(&person); 99 | 100 | /* Free all allocated memory and return */ 101 | pb_journal_destroy(&journal); 102 | return error 103 | ? EXIT_FAILURE 104 | : EXIT_SUCCESS; 105 | } -------------------------------------------------------------------------------- /examples/messages/person.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2020 Martin Donath 2 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | message Person { 22 | message PhoneNumber { 23 | enum PhoneType { 24 | MOBILE = 0; 25 | HOME = 1; 26 | WORK = 2; 27 | } 28 | required string number = 1; 29 | optional PhoneType type = 2 [default = HOME]; 30 | } 31 | required string name = 1; 32 | required int32 id = 2; 33 | optional string email = 3; 34 | repeated PhoneNumber phone = 4; 35 | } 36 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Public header files: libprotobluff 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Don't rebase libprotobluff public header files 26 | nobase_include_HEADERS = \ 27 | protobluff/core/allocator.h \ 28 | protobluff/core/buffer.h \ 29 | protobluff/core/common.h \ 30 | protobluff/core/decoder.h \ 31 | protobluff/core/descriptor.h \ 32 | protobluff/core/encoder.h \ 33 | protobluff/core/string.h \ 34 | protobluff/core.h \ 35 | protobluff/descriptor.h \ 36 | protobluff/message/buffer.h \ 37 | protobluff/message/common.h \ 38 | protobluff/message/cursor.h \ 39 | protobluff/message/field.h \ 40 | protobluff/message/journal.h \ 41 | protobluff/message/message.h \ 42 | protobluff/message/nested.h \ 43 | protobluff/message/oneof.h \ 44 | protobluff/message/part.h \ 45 | protobluff/message.h \ 46 | protobluff/util/chunk_allocator.h \ 47 | protobluff/util/descriptor.h \ 48 | protobluff/util/validator.h \ 49 | protobluff/util.h \ 50 | protobluff.h 51 | -------------------------------------------------------------------------------- /include/protobluff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_H 24 | #define PB_INCLUDE_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #endif /* PB_INCLUDE_H */ 31 | -------------------------------------------------------------------------------- /include/protobluff/core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_CORE_H 24 | #define PB_INCLUDE_CORE_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #endif /* PB_INCLUDE_CORE_H */ 35 | -------------------------------------------------------------------------------- /include/protobluff/core/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_CORE_ALLOCATOR_H 24 | #define PB_INCLUDE_CORE_ALLOCATOR_H 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Type definitions 33 | * ------------------------------------------------------------------------- */ 34 | 35 | typedef void * 36 | (*pb_allocator_allocate_f)( 37 | void *data, /*!< Internal allocator data */ 38 | size_t size); /*!< Bytes to be allocated */ 39 | 40 | typedef void * 41 | (*pb_allocator_resize_f)( 42 | void *data, /*!< Internal allocator data */ 43 | void *block, /*!< Memory block to be resized */ 44 | size_t size); /*!< Bytes to be allocated */ 45 | 46 | typedef void 47 | (*pb_allocator_free_f)( 48 | void *data, /*!< Internal allocator data */ 49 | void *block); /*!< Memory block to be freed */ 50 | 51 | /* ------------------------------------------------------------------------- */ 52 | 53 | typedef struct pb_allocator_t { 54 | struct { 55 | pb_allocator_allocate_f allocate; /*!< Allocate a memory block */ 56 | pb_allocator_resize_f resize; /*!< Resize a memory block */ 57 | pb_allocator_free_f free; /*!< Free a memory block */ 58 | } proc; 59 | void *data; /*!< Internal allocator data */ 60 | } pb_allocator_t; 61 | 62 | /* ---------------------------------------------------------------------------- 63 | * Inline functions 64 | * ------------------------------------------------------------------------- */ 65 | 66 | /*! 67 | * Allocate a memory block of given size. 68 | * 69 | * \param[in,out] allocator Allocator 70 | * \param[in] size Bytes to be allocated 71 | * \return Memory block 72 | */ 73 | PB_INLINE PB_WARN_UNUSED_RESULT 74 | void * 75 | pb_allocator_allocate(pb_allocator_t *allocator, size_t size) { 76 | assert(allocator && size); 77 | return allocator->proc.allocate(allocator->data, size); 78 | } 79 | 80 | /*! 81 | * Change the size of a previously allocated memory block. 82 | * 83 | * \param[in,out] allocator Allocator 84 | * \param[in,out] block Memory block to be resized 85 | * \param[in] size Bytes to be allocated 86 | * \return Memory block 87 | */ 88 | PB_INLINE PB_WARN_UNUSED_RESULT 89 | void * 90 | pb_allocator_resize(pb_allocator_t *allocator, void *block, size_t size) { 91 | assert(allocator && size); 92 | return allocator->proc.resize(allocator->data, block, size); 93 | } 94 | 95 | /*! 96 | * Free an allocated memory block. 97 | * 98 | * \param[in,out] allocator Allocator 99 | * \param[in,out] block Memory block to be freed 100 | */ 101 | PB_INLINE void 102 | pb_allocator_free(pb_allocator_t *allocator, void *block) { 103 | assert(allocator && block); 104 | return allocator->proc.free(allocator->data, block); 105 | } 106 | 107 | #endif /* PB_INCLUDE_CORE_ALLOCATOR_H */ 108 | -------------------------------------------------------------------------------- /include/protobluff/descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_DESCRIPTOR_H 24 | #define PB_INCLUDE_DESCRIPTOR_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | /* ---------------------------------------------------------------------------- 31 | * Constants 32 | * ------------------------------------------------------------------------- */ 33 | 34 | #define INT32 PB_TYPE_INT32 /*!< 32-bit integer, var., signed */ 35 | #define INT64 PB_TYPE_INT64 /*!< 64-bit integer, var., signed */ 36 | #define UINT32 PB_TYPE_UINT32 /*!< 32-bit integer, var., unsigned */ 37 | #define UINT64 PB_TYPE_UINT64 /*!< 32-bit integer, var., unsigned */ 38 | #define SINT32 PB_TYPE_SINT32 /*!< 32-bit integer, var., signed */ 39 | #define SINT64 PB_TYPE_SINT64 /*!< 64-bit integer, var., signed */ 40 | #define FIXED32 PB_TYPE_FIXED32 /*!< 32-bit integer, fix., unsigned */ 41 | #define FIXED64 PB_TYPE_FIXED64 /*!< 64-bit integer, fix., unsigned */ 42 | #define SFIXED32 PB_TYPE_SFIXED32 /*!< 32-bit integer, fix., signed */ 43 | #define SFIXED64 PB_TYPE_SFIXED64 /*!< 64-bit integer, fix., signed */ 44 | #define BOOL PB_TYPE_BOOL /*!< Boolean, var. */ 45 | #define ENUM PB_TYPE_ENUM /*!< Enumeration, var. */ 46 | #define FLOAT PB_TYPE_FLOAT /*!< Single-precison float */ 47 | #define DOUBLE PB_TYPE_DOUBLE /*!< Double-precison float */ 48 | #define STRING PB_TYPE_STRING /*!< String */ 49 | #define BYTES PB_TYPE_BYTES /*!< Byte array */ 50 | #define MESSAGE PB_TYPE_MESSAGE /*!< Message */ 51 | 52 | /* ------------------------------------------------------------------------- */ 53 | 54 | #define REQUIRED PB_LABEL_REQUIRED /*!< Required field */ 55 | #define OPTIONAL PB_LABEL_OPTIONAL /*!< Optional field */ 56 | #define REPEATED PB_LABEL_REPEATED /*!< Repeated field */ 57 | #define ONEOF PB_LABEL_ONEOF /*!< Oneof member */ 58 | 59 | /* ------------------------------------------------------------------------- */ 60 | 61 | #define PACKED PB_FLAG_PACKED /*!< Flag: packed field */ 62 | 63 | #endif /* PB_INCLUDE_DESCRIPTOR_H */ 64 | -------------------------------------------------------------------------------- /include/protobluff/message.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_MESSAGE_H 24 | #define PB_INCLUDE_MESSAGE_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #endif /* PB_INCLUDE_MESSAGE_H */ 37 | -------------------------------------------------------------------------------- /include/protobluff/message/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_MESSAGE_BUFFER_H 24 | #define PB_INCLUDE_MESSAGE_BUFFER_H 25 | 26 | #include 27 | #include 28 | 29 | /* ---------------------------------------------------------------------------- 30 | * Interface 31 | * ------------------------------------------------------------------------- */ 32 | 33 | PB_EXPORT void 34 | pb_buffer_dump( 35 | const pb_buffer_t *buffer); /* Buffer */ 36 | 37 | #endif /* PB_INCLUDE_MESSAGE_BUFFER_H */ 38 | -------------------------------------------------------------------------------- /include/protobluff/message/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_MESSAGE_COMMON_H 24 | #define PB_INCLUDE_MESSAGE_COMMON_H 25 | 26 | #include 27 | 28 | #include 29 | 30 | /* ---------------------------------------------------------------------------- 31 | * Type definitions 32 | * ------------------------------------------------------------------------- */ 33 | 34 | typedef size_t pb_version_t; /*!< Version */ 35 | 36 | /* ------------------------------------------------------------------------- */ 37 | 38 | typedef struct pb_offset_t { 39 | size_t start; /*!< Start offset */ 40 | size_t end; /*!< End offset */ 41 | struct { 42 | ptrdiff_t origin; /*!< Relative offset to origin */ 43 | ptrdiff_t tag; /*!< Relative offset to tag */ 44 | ptrdiff_t length; /*!< Relative offset to length */ 45 | } diff; 46 | } pb_offset_t; 47 | 48 | /* ---------------------------------------------------------------------------- 49 | * Interface 50 | * ------------------------------------------------------------------------- */ 51 | 52 | PB_EXPORT const char * 53 | pb_error_string( 54 | pb_error_t error); /* Error */ 55 | 56 | #endif /* PB_INCLUDE_MESSAGE_COMMON_H */ 57 | -------------------------------------------------------------------------------- /include/protobluff/message/nested.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_MESSAGE_NESTED_H 24 | #define PB_INCLUDE_MESSAGE_NESTED_H 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Interface 33 | * ------------------------------------------------------------------------- */ 34 | 35 | PB_EXPORT int 36 | pb_message_nested_has( 37 | pb_message_t *message, /* Message */ 38 | const pb_tag_t tags[], /* Tags */ 39 | size_t size); /* Tag count */ 40 | 41 | PB_EXPORT int 42 | pb_message_nested_match( 43 | pb_message_t *message, /* Message */ 44 | const pb_tag_t tags[], /* Tags */ 45 | size_t size, /* Tag count */ 46 | const void *value); /* Pointer holding value */ 47 | 48 | PB_EXPORT PB_WARN_UNUSED_RESULT 49 | pb_error_t 50 | pb_message_nested_get( 51 | pb_message_t *message, /* Message */ 52 | const pb_tag_t tags[], /* Tags */ 53 | size_t size, /* Tag count */ 54 | void *value); /* Pointer receiving value */ 55 | 56 | PB_EXPORT PB_WARN_UNUSED_RESULT 57 | pb_error_t 58 | pb_message_nested_put( 59 | pb_message_t *message, /* Message */ 60 | const pb_tag_t tags[], /* Tags */ 61 | size_t size, /* Tag count */ 62 | const void *value); /* Pointer holding value */ 63 | 64 | PB_EXPORT PB_WARN_UNUSED_RESULT 65 | pb_error_t 66 | pb_message_nested_erase( 67 | pb_message_t *message, /* Message */ 68 | const pb_tag_t tags[], /* Tags */ 69 | size_t size); /* Tag count */ 70 | 71 | #endif /* PB_INCLUDE_MESSAGE_NESTED_H */ 72 | -------------------------------------------------------------------------------- /include/protobluff/message/oneof.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_MESSAGE_ONEOF_H 24 | #define PB_INCLUDE_MESSAGE_ONEOF_H 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /* ---------------------------------------------------------------------------- 33 | * Forward declarations 34 | * ------------------------------------------------------------------------- */ 35 | 36 | struct pb_message_t; 37 | 38 | /* ---------------------------------------------------------------------------- 39 | * Type definitions 40 | * ------------------------------------------------------------------------- */ 41 | 42 | typedef struct pb_oneof_t { 43 | const pb_oneof_descriptor_t 44 | *descriptor; /*!< Oneof descriptor */ 45 | pb_cursor_t cursor; /*!< Cursor */ 46 | } pb_oneof_t; 47 | 48 | /* ---------------------------------------------------------------------------- 49 | * Interface 50 | * ------------------------------------------------------------------------- */ 51 | 52 | PB_EXPORT PB_WARN_UNUSED_RESULT 53 | pb_oneof_t 54 | pb_oneof_create( 55 | const pb_oneof_descriptor_t 56 | *descriptor, /* Oneof descriptor */ 57 | struct pb_message_t *message); /* Message */ 58 | 59 | PB_EXPORT void 60 | pb_oneof_destroy( 61 | pb_oneof_t *oneof); /* Oneof */ 62 | 63 | PB_EXPORT pb_tag_t 64 | pb_oneof_case( 65 | pb_oneof_t *oneof); /* Oneof */ 66 | 67 | PB_EXPORT PB_WARN_UNUSED_RESULT 68 | pb_error_t 69 | pb_oneof_clear( 70 | pb_oneof_t *oneof); /* Oneof */ 71 | 72 | /* ---------------------------------------------------------------------------- 73 | * Inline functions 74 | * ------------------------------------------------------------------------- */ 75 | 76 | /*! 77 | * Retrieve the descriptor of a oneof. 78 | * 79 | * \param[in] oneof Oneof 80 | * \return Oneof Descriptor 81 | */ 82 | PB_INLINE const pb_oneof_descriptor_t * 83 | pb_oneof_descriptor(const pb_oneof_t *oneof) { 84 | assert(oneof); 85 | return oneof->descriptor; 86 | } 87 | 88 | /*! 89 | * Retrieve the internal error state of a oneof. 90 | * 91 | * \param[in] oneof Oneof 92 | * \return Error code 93 | */ 94 | PB_INLINE pb_error_t 95 | pb_oneof_error(const pb_oneof_t *oneof) { 96 | assert(oneof); 97 | return pb_cursor_error(&(oneof->cursor)) != PB_ERROR_EOM 98 | ? pb_cursor_error(&(oneof->cursor)) 99 | : PB_ERROR_NONE; 100 | } 101 | 102 | /*! 103 | * Test whether a oneof is valid. 104 | * 105 | * \param[in] oneof Oneof 106 | * \return Test result 107 | */ 108 | PB_INLINE int 109 | pb_oneof_valid(const pb_oneof_t *oneof) { 110 | assert(oneof); 111 | return !pb_oneof_error(oneof); 112 | } 113 | 114 | #endif /* PB_INCLUDE_MESSAGE_ONEOF_H */ 115 | -------------------------------------------------------------------------------- /include/protobluff/message/part.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_MESSAGE_PART_H 24 | #define PB_INCLUDE_MESSAGE_PART_H 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Type definitions 33 | * ------------------------------------------------------------------------- */ 34 | 35 | typedef struct pb_part_t { 36 | pb_journal_t *journal; /*!< Journal */ 37 | pb_version_t version; /*!< Version */ 38 | pb_offset_t offset; /*!< Offsets */ 39 | } pb_part_t; 40 | 41 | /* ---------------------------------------------------------------------------- 42 | * Interface 43 | * ------------------------------------------------------------------------- */ 44 | 45 | PB_EXPORT pb_error_t 46 | pb_part_error( 47 | const pb_part_t *part); /* Part */ 48 | 49 | PB_EXPORT void 50 | pb_part_dump( 51 | const pb_part_t *part); /* Part */ 52 | 53 | /* ---------------------------------------------------------------------------- 54 | * Inline functions 55 | * ------------------------------------------------------------------------- */ 56 | 57 | /*! 58 | * Test whether a part is valid. 59 | * 60 | * \param[in] part Part 61 | * \return Test result 62 | */ 63 | PB_INLINE int 64 | pb_part_valid(const pb_part_t *part) { 65 | assert(part); 66 | return !pb_part_error(part); 67 | } 68 | 69 | #endif /* PB_INCLUDE_MESSAGE_PART_H */ 70 | -------------------------------------------------------------------------------- /include/protobluff/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_UTIL_H 24 | #define PB_INCLUDE_UTIL_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #endif /* PB_INCLUDE_UTIL_H */ 31 | -------------------------------------------------------------------------------- /include/protobluff/util/chunk_allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_UTIL_CHUNK_ALLOCATOR_H 24 | #define PB_INCLUDE_UTIL_CHUNK_ALLOCATOR_H 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Interface 33 | * ------------------------------------------------------------------------- */ 34 | 35 | PB_EXPORT PB_WARN_UNUSED_RESULT 36 | pb_allocator_t 37 | pb_chunk_allocator_create(); 38 | 39 | PB_EXPORT PB_WARN_UNUSED_RESULT 40 | pb_allocator_t 41 | pb_chunk_allocator_create_with_capacity( 42 | size_t capacity); /* Chunk capacity */ 43 | 44 | PB_EXPORT void 45 | pb_chunk_allocator_destroy( 46 | pb_allocator_t *allocator); /* Allocator */ 47 | 48 | #endif /* PB_INCLUDE_UTIL_CHUNK_ALLOCATOR_H */ 49 | -------------------------------------------------------------------------------- /include/protobluff/util/descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_UTIL_DESCRIPTOR_H 24 | #define PB_INCLUDE_UTIL_DESCRIPTOR_H 25 | 26 | #include 27 | #include 28 | 29 | /* ---------------------------------------------------------------------------- 30 | * Interface 31 | * ------------------------------------------------------------------------- */ 32 | 33 | PB_EXPORT const pb_field_descriptor_t * 34 | pb_descriptor_field_by_name( 35 | const pb_descriptor_t *descriptor, /* Descriptor */ 36 | const char name[]); /* Name */ 37 | 38 | /* ------------------------------------------------------------------------- */ 39 | 40 | PB_EXPORT const pb_enum_value_descriptor_t * 41 | pb_enum_descriptor_value_by_name( 42 | const pb_enum_descriptor_t 43 | *descriptor, /* Enum descriptor */ 44 | const char name[]); /* Name */ 45 | 46 | #endif /* PB_INCLUDE_UTIL_DESCRIPTOR_H */ 47 | -------------------------------------------------------------------------------- /include/protobluff/util/validator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_INCLUDE_UTIL_VALIDATOR_H 24 | #define PB_INCLUDE_UTIL_VALIDATOR_H 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | /* ---------------------------------------------------------------------------- 33 | * Type definitions 34 | * ------------------------------------------------------------------------- */ 35 | 36 | typedef struct pb_validator_t { 37 | const pb_descriptor_t *descriptor; /*!< Descriptor */ 38 | } pb_validator_t; 39 | 40 | /* ---------------------------------------------------------------------------- 41 | * Interface 42 | * ------------------------------------------------------------------------- */ 43 | 44 | PB_EXPORT PB_WARN_UNUSED_RESULT 45 | pb_error_t 46 | pb_validator_check( 47 | const pb_validator_t *validator, /* Validator */ 48 | const pb_buffer_t *buffer); /* Buffer */ 49 | 50 | /* ---------------------------------------------------------------------------- 51 | * Inline functions 52 | * ------------------------------------------------------------------------- */ 53 | 54 | /*! 55 | * Create a validator. 56 | * 57 | * \param[in] descriptor Descriptor 58 | * \return Validator 59 | */ 60 | PB_INLINE PB_WARN_UNUSED_RESULT 61 | pb_validator_t 62 | pb_validator_create(const pb_descriptor_t *descriptor) { 63 | assert(descriptor); 64 | pb_validator_t validator = { 65 | .descriptor = descriptor 66 | }; 67 | return validator; 68 | } 69 | 70 | /*! 71 | * Destroy a validator. 72 | * 73 | * \param[in,out] validator Validator 74 | */ 75 | PB_INLINE void 76 | pb_validator_destroy(pb_validator_t *validator) { 77 | assert(validator); /* Nothing to be done */ 78 | } 79 | 80 | /*! 81 | * Retrieve the descriptor of a validator. 82 | * 83 | * \param[in] validator Validator 84 | * \return Descriptor 85 | */ 86 | PB_INLINE const pb_descriptor_t * 87 | pb_validator_descriptor(const pb_validator_t *validator) { 88 | assert(validator); 89 | return validator->descriptor; 90 | } 91 | 92 | #endif /* PB_INCLUDE_UTIL_VALIDATOR_H */ 93 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # Project information 22 | site_name: protobluff 23 | site_description: A modular Protocol Buffers implementation for C 24 | site_author: Martin Donath 25 | site_url: https://squidfunk.github.io/protobluff/ 26 | 27 | # Repository 28 | repo_name: squidfunk/protobluff 29 | repo_url: https://github.com/squidfunk/protobluff 30 | edit_uri: "" 31 | 32 | # Copyright 33 | copyright: 'Copyright © 2013 - 2016 Martin Donath' 34 | 35 | # Documentation and theme 36 | theme: 37 | name: material 38 | feature: 39 | tabs: true 40 | palette: 41 | primary: teal 42 | accent: teal 43 | 44 | # Extra variables 45 | extra: 46 | social: 47 | - type: globe 48 | link: http://struct.cc 49 | - type: github-alt 50 | link: https://github.com/squidfunk 51 | - type: twitter 52 | link: https://twitter.com/squidfunk 53 | - type: linkedin 54 | link: https://linkedin.com/in/squidfunk 55 | 56 | # Extensions 57 | markdown_extensions: 58 | - markdown.extensions.admonition 59 | - markdown.extensions.codehilite: 60 | guess_lang: false 61 | - markdown.extensions.def_list 62 | - markdown.extensions.footnotes 63 | - markdown.extensions.meta 64 | - markdown.extensions.toc: 65 | permalink: true 66 | - pymdownx.arithmatex 67 | - pymdownx.betterem: 68 | smart_enable: all 69 | - pymdownx.caret 70 | - pymdownx.critic 71 | - pymdownx.details 72 | - pymdownx.emoji: 73 | emoji_generator: !!python/name:pymdownx.emoji.to_svg 74 | - pymdownx.inlinehilite 75 | - pymdownx.keys 76 | - pymdownx.magiclink 77 | - pymdownx.mark 78 | - pymdownx.smartsymbols 79 | - pymdownx.superfences 80 | - pymdownx.tasklist: 81 | custom_checkbox: true 82 | - pymdownx.tilde 83 | 84 | # Page tree 85 | pages: 86 | - About: index.md 87 | - Getting started: getting-started.md 88 | - Design rationale: design-rationale.md 89 | - Similar projects: similar-projects.md 90 | - Developer guide: 91 | - Choosing a runtime: guide/runtimes.md 92 | - Buffers and journals: guide/buffers-and-journals.md 93 | - Working with messages: guide/messages.md 94 | - Scalar types: guide/scalar-types.md 95 | - Repeated fields: guide/repeated-fields.md 96 | - Error handling: guide/error-handling.md 97 | - Custom allocators: guide/allocators.md 98 | - Miscellaneous: guide/miscellaneous.md 99 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Subdirectories 23 | # ----------------------------------------------------------------------------- 24 | 25 | SUBDIRS = core message util generator 26 | 27 | # ----------------------------------------------------------------------------- 28 | # Shared library: libprotobluff-lite 29 | # ----------------------------------------------------------------------------- 30 | 31 | # Build libprotobluff-lite shared library 32 | lib_LTLIBRARIES = libprotobluff-lite.la 33 | libprotobluff_lite_la_SOURCES = 34 | libprotobluff_lite_la_LIBADD = \ 35 | @top_builddir@/src/core/libprotobluff-core.la 36 | libprotobluff_lite_la_LDFLAGS = \ 37 | -version-info @VERSION_INFO@ 38 | 39 | # ----------------------------------------------------------------------------- 40 | # Shared library: libprotobluff 41 | # ----------------------------------------------------------------------------- 42 | 43 | # Build libprotobluff shared library 44 | lib_LTLIBRARIES += libprotobluff.la 45 | libprotobluff_la_SOURCES = 46 | libprotobluff_la_LIBADD = \ 47 | @top_builddir@/src/message/libprotobluff-message.la \ 48 | @top_builddir@/src/util/libprotobluff-util.la \ 49 | @top_builddir@/src/core/libprotobluff-core.la 50 | libprotobluff_la_LDFLAGS = \ 51 | -version-info @VERSION_INFO@ 52 | -------------------------------------------------------------------------------- /src/core/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Intermediary library: core 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build core intermediary library 26 | noinst_LTLIBRARIES = libprotobluff-core.la 27 | libprotobluff_core_la_SOURCES = \ 28 | allocator.c \ 29 | buffer.c \ 30 | decoder.c \ 31 | descriptor.c \ 32 | encoder.c \ 33 | stream.c \ 34 | varint.c 35 | libprotobluff_core_la_CPPFLAGS = \ 36 | -I@top_builddir@/src \ 37 | -I@top_builddir@/include \ 38 | @OPTIMIZATIONS@ \ 39 | @coverage_CPPFLAGS@ 40 | libprotobluff_core_la_LDFLAGS = \ 41 | @coverage_LDFLAGS@ 42 | -------------------------------------------------------------------------------- /src/core/allocator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include "core/allocator.h" 27 | 28 | /* ---------------------------------------------------------------------------- 29 | * System-default allocator callbacks 30 | * ------------------------------------------------------------------------- */ 31 | 32 | /*! 33 | * Allocate a memory block of given size. 34 | * 35 | * \param[in,out] data Internal allocator data 36 | * \param[in] size Bytes to be allocated 37 | * \return Memory block 38 | */ 39 | static void * 40 | allocator_allocate(void *data, size_t size) { 41 | assert(!data && size); 42 | return malloc(size); 43 | } 44 | 45 | /*! 46 | * Change the size of a previously allocated memory block. 47 | * 48 | * \param[in,out] data Internal allocator data 49 | * \param[in,out] block Memory block to be resized 50 | * \param[in] size Bytes to be allocated 51 | * \return Memory block 52 | */ 53 | static void * 54 | allocator_resize(void *data, void *block, size_t size) { 55 | assert(!data && size); 56 | return realloc(block, size); 57 | } 58 | 59 | /*! 60 | * Free an allocated memory block. 61 | * 62 | * \param[in,out] data Internal allocator data 63 | * \param[in,out] block Memory block to be freed 64 | */ 65 | static void 66 | allocator_free(void *data, void *block) { 67 | assert(!data && block); 68 | free(block); 69 | } 70 | 71 | /* ---------------------------------------------------------------------------- 72 | * Allocators 73 | * ------------------------------------------------------------------------- */ 74 | 75 | /*! System-default allocator */ 76 | pb_allocator_t 77 | allocator_default = { 78 | .proc = { 79 | .allocate = allocator_allocate, 80 | .resize = allocator_resize, 81 | .free = allocator_free 82 | }, 83 | .data = NULL 84 | }; 85 | 86 | /*! Zero-copy fake-allocator */ 87 | pb_allocator_t 88 | allocator_zero_copy = {}; 89 | -------------------------------------------------------------------------------- /src/core/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_CORE_ALLOCATOR_H 24 | #define PB_CORE_ALLOCATOR_H 25 | 26 | #include 27 | 28 | /* ---------------------------------------------------------------------------- 29 | * Allocators 30 | * ------------------------------------------------------------------------- */ 31 | 32 | /*! System-default allocator */ 33 | extern pb_allocator_t 34 | allocator_default; 35 | 36 | /*! Zero-copy fake-allocator */ 37 | extern pb_allocator_t 38 | allocator_zero_copy; 39 | 40 | #endif /* PB_CORE_ALLOCATOR_H */ 41 | -------------------------------------------------------------------------------- /src/core/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_CORE_BUFFER_H 24 | #define PB_CORE_BUFFER_H 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include "core/allocator.h" 33 | #include "core/common.h" 34 | 35 | /* ---------------------------------------------------------------------------- 36 | * Interface 37 | * ------------------------------------------------------------------------- */ 38 | 39 | PB_WARN_UNUSED_RESULT 40 | extern uint8_t * 41 | pb_buffer_grow( 42 | pb_buffer_t *buffer, /* Buffer */ 43 | size_t size); /* Additional size */ 44 | 45 | /* ---------------------------------------------------------------------------- 46 | * Inline functions 47 | * ------------------------------------------------------------------------- */ 48 | 49 | /*! 50 | * Create a zero-copy buffer. 51 | * 52 | * This function is only for internal use (mainly by the decoder), as the size 53 | * may be initialized to zero. 54 | * 55 | * \param[in,out] data[] Raw data 56 | * \param[in] size Raw data size 57 | * \return Buffer 58 | */ 59 | PB_INLINE PB_WARN_UNUSED_RESULT 60 | pb_buffer_t 61 | pb_buffer_create_zero_copy_internal(uint8_t data[], size_t size) { 62 | pb_buffer_t buffer = { 63 | .allocator = &allocator_zero_copy, 64 | .data = data, 65 | .size = size 66 | }; 67 | return buffer; 68 | } 69 | 70 | /*! 71 | * Create an invalid buffer. 72 | * 73 | * \return Buffer 74 | */ 75 | PB_INLINE PB_WARN_UNUSED_RESULT 76 | pb_buffer_t 77 | pb_buffer_create_invalid(void) { 78 | pb_buffer_t buffer = {}; 79 | return buffer; 80 | } 81 | 82 | /*! 83 | * Retrieve the raw data of a buffer from a given offset. 84 | * 85 | * \warning This function does no runtime check for a valid buffer, as it is 86 | * only used internally. Errors are catched with assertions during development. 87 | * 88 | * \param[in] buffer Buffer 89 | * \param[in] offset Offset 90 | * \return Raw data from offset 91 | */ 92 | PB_INLINE uint8_t * 93 | pb_buffer_data_from(const pb_buffer_t *buffer, size_t offset) { 94 | assert(buffer && offset <= buffer->size); 95 | assert(pb_buffer_valid(buffer)); 96 | return &(buffer->data[offset]); 97 | } 98 | 99 | /* LCOV_EXCL_START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ 100 | 101 | /*! 102 | * Retrieve the raw data of a buffer at a given offset. 103 | * 104 | * \warning This function does no runtime check for a valid buffer, as it is 105 | * only used internally. Errors are catched with assertions during development. 106 | * 107 | * \param[in] buffer Buffer 108 | * \param[in] offset Offset 109 | * \return Raw data at offset 110 | */ 111 | PB_INLINE uint8_t 112 | pb_buffer_data_at(const pb_buffer_t *buffer, size_t offset) { 113 | assert(buffer && offset < buffer->size); 114 | assert(pb_buffer_valid(buffer)); 115 | return buffer->data[offset]; 116 | } 117 | 118 | /* LCOV_EXCL_STOP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ 119 | 120 | #endif /* PB_CORE_BUFFER_H */ 121 | -------------------------------------------------------------------------------- /src/core/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_CORE_COMMON_H 24 | #define PB_CORE_COMMON_H 25 | 26 | #include 27 | #include 28 | 29 | /* ---------------------------------------------------------------------------- 30 | * Compiler attributes 31 | * ------------------------------------------------------------------------- */ 32 | 33 | /* 34 | * Branch-prediction helpers. 35 | */ 36 | #define likely_(condition) __builtin_expect((condition), 1) 37 | #define unlikely_(condition) __builtin_expect((condition), 0) 38 | 39 | #endif /* PB_CORE_COMMON_H */ 40 | -------------------------------------------------------------------------------- /src/core/decoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_CORE_DECODER_H 24 | #define PB_CORE_DECODER_H 25 | 26 | #include 27 | 28 | #endif /* PB_CORE_DECODER_H */ 29 | -------------------------------------------------------------------------------- /src/core/descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_CORE_DESCRIPTOR_H 24 | #define PB_CORE_DESCRIPTOR_H 25 | 26 | #include 27 | 28 | #include 29 | 30 | #include "core/common.h" 31 | 32 | /* ---------------------------------------------------------------------------- 33 | * Interface 34 | * ------------------------------------------------------------------------- */ 35 | 36 | /*! 37 | * Reset a descriptor's extension. 38 | * 39 | * This function is defined as an inline function, as it is only needed for 40 | * testing purposes and doesn't need to be exported. 41 | * 42 | * \param[in,out] descriptor Descriptor 43 | */ 44 | PB_INLINE void 45 | pb_descriptor_reset(pb_descriptor_t *descriptor) { 46 | assert(descriptor); 47 | descriptor->extension = NULL; 48 | } 49 | 50 | #endif /* PB_CORE_DESCRIPTOR_H */ 51 | -------------------------------------------------------------------------------- /src/core/encoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_CORE_ENCODER_H 24 | #define PB_CORE_ENCODER_H 25 | 26 | #include 27 | 28 | #include "core/buffer.h" 29 | #include "core/common.h" 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Inline functions 33 | * ------------------------------------------------------------------------- */ 34 | 35 | /*! 36 | * Create an invalid encoder. 37 | * 38 | * \return Encoder 39 | */ 40 | PB_INLINE PB_WARN_UNUSED_RESULT 41 | pb_encoder_t 42 | pb_encoder_create_invalid(void) { 43 | pb_encoder_t encoder = { 44 | .descriptor = NULL, 45 | .buffer = pb_buffer_create_invalid() 46 | }; 47 | return encoder; 48 | } 49 | 50 | #endif /* PB_CORE_ENCODER_H */ 51 | -------------------------------------------------------------------------------- /src/generator/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Executable: protoc-gen-protobluff 23 | # ----------------------------------------------------------------------------- 24 | 25 | if HAVE_PROTOBUF 26 | 27 | # Build protoc-gen-protobluff executable 28 | bin_PROGRAMS = protoc-gen-protobluff 29 | protoc_gen_protobluff_SOURCES = \ 30 | enum.cc \ 31 | enum_value.cc \ 32 | extension.cc \ 33 | field.cc \ 34 | file.cc \ 35 | generator.cc \ 36 | message.cc \ 37 | oneof.cc \ 38 | protoc-gen-protobluff.cc \ 39 | strutil.cc 40 | protoc_gen_protobluff_CXXFLAGS = \ 41 | -Wno-sign-compare 42 | protoc_gen_protobluff_CPPFLAGS = \ 43 | -I@top_builddir@/src \ 44 | -I@top_builddir@/include \ 45 | @OPTIMIZATIONS@ 46 | protoc_gen_protobluff_LDFLAGS = \ 47 | @protobuf_LIBS@ 48 | 49 | endif # HAVE_PROTOBUF 50 | -------------------------------------------------------------------------------- /src/generator/enum.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_GENERATOR_ENUM_HH 24 | #define PB_GENERATOR_ENUM_HH 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "generator/enum_value.hh" 34 | 35 | /* ---------------------------------------------------------------------------- 36 | * Interface 37 | * ------------------------------------------------------------------------- */ 38 | 39 | namespace protobluff { 40 | 41 | using ::std::map; 42 | using ::std::string; 43 | using ::std::unique_ptr; 44 | 45 | using ::google::protobuf::EnumDescriptor; 46 | using ::google::protobuf::io::Printer; 47 | 48 | class Enum { 49 | 50 | public: 51 | explicit 52 | Enum( 53 | const EnumDescriptor 54 | *descriptor); /* Enum descriptor */ 55 | 56 | void 57 | GenerateValues( 58 | Printer *printer) /* Printer */ 59 | const; 60 | 61 | void 62 | GenerateDeclaration( 63 | Printer *printer) /* Printer */ 64 | const; 65 | 66 | void 67 | GenerateDescriptor( 68 | Printer *printer) /* Printer */ 69 | const; 70 | 71 | private: 72 | const EnumDescriptor *descriptor_; /* Enum descriptor */ 73 | unique_ptr< 74 | unique_ptr[] 75 | > values_; /* Enum value generators */ 76 | map variables_; /* Variables */ 77 | }; 78 | } 79 | 80 | #endif /* PB_GENERATOR_ENUM_HH */ 81 | -------------------------------------------------------------------------------- /src/generator/enum_value.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include "generator/enum_value.hh" 29 | #include "generator/strutil.hh" 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Interface 33 | * ------------------------------------------------------------------------- */ 34 | 35 | namespace protobluff { 36 | 37 | using ::google::protobuf::EnumValueDescriptor; 38 | using ::google::protobuf::io::Printer; 39 | 40 | using ::google::protobuf::SimpleItoa; 41 | using ::google::protobuf::StringReplace; 42 | using ::google::protobuf::UpperString; 43 | 44 | /*! 45 | * Create an enum value generator. 46 | * 47 | * \param[in] descriptor Enum value descriptor 48 | */ 49 | EnumValue:: 50 | EnumValue(const EnumValueDescriptor *descriptor) : 51 | descriptor_(descriptor) { 52 | 53 | /* Extract full name for signature */ 54 | variables_["signature"] = descriptor_->full_name(); 55 | 56 | /* Extract name and number */ 57 | variables_["name"] = descriptor_->name(); 58 | variables_["number"] = SimpleItoa(descriptor_->number()); 59 | 60 | /* Prepare constant value */ 61 | variables_["constant"] = StringReplace( 62 | variables_["signature"], ".", "_", true); 63 | UpperString(&(variables_["constant"])); 64 | } 65 | 66 | /*! 67 | * Generate value. 68 | * 69 | * \param[in,out] printer Printer 70 | */ 71 | void EnumValue:: 72 | GenerateValue(Printer *printer) const { 73 | assert(printer); 74 | printer->Print(variables_, 75 | "#define `constant`_V `number`\n"); 76 | } 77 | 78 | /*! 79 | * Generate descriptor. 80 | * 81 | * \param[in,out] printer Printer 82 | */ 83 | void EnumValue:: 84 | GenerateDescriptor(Printer *printer) const { 85 | assert(printer); 86 | printer->Print(variables_, 87 | "\n" 88 | "/* `signature` = `number` */\n" 89 | "{ .number = `number`,\n" 90 | " .name = \"`name`\" }"); 91 | } 92 | 93 | /*! 94 | * Comparator for enum value generators. 95 | * 96 | * \param[in] x Enum value generator 97 | * \param[in] y Enum value generator 98 | * \return Test result 99 | */ 100 | bool 101 | EnumValueComparator(const EnumValue *x, const EnumValue *y) { 102 | return x->descriptor_->number() < y->descriptor_->number(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/generator/enum_value.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_GENERATOR_ENUM_VALUE_HH 24 | #define PB_GENERATOR_ENUM_VALUE_HH 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include "generator/enum_value.hh" 33 | 34 | /* ---------------------------------------------------------------------------- 35 | * Interface 36 | * ------------------------------------------------------------------------- */ 37 | 38 | namespace protobluff { 39 | 40 | using ::std::map; 41 | using ::std::string; 42 | 43 | using ::google::protobuf::EnumValueDescriptor; 44 | using ::google::protobuf::io::Printer; 45 | 46 | class EnumValue { 47 | 48 | public: 49 | explicit 50 | EnumValue( 51 | const EnumValueDescriptor 52 | *descriptor); /* Enum value descriptor */ 53 | 54 | void 55 | GenerateValue( 56 | Printer *printer) /* Printer */ 57 | const; 58 | 59 | void 60 | GenerateDescriptor( 61 | Printer *printer) /* Printer */ 62 | const; 63 | 64 | friend bool 65 | EnumValueComparator( 66 | const EnumValue *x, /* Enum value generator */ 67 | const EnumValue *y); /* Enum value generator */ 68 | 69 | private: 70 | const EnumValueDescriptor 71 | *descriptor_; /* Enum value descriptor */ 72 | map variables_; /* Variables */ 73 | }; 74 | 75 | bool 76 | EnumValueComparator( 77 | const EnumValue *x, /* Enum value generator */ 78 | const EnumValue *y); /* Enum value generator */ 79 | } 80 | 81 | #endif /* PB_GENERATOR_ENUM_VALUE_HH */ 82 | -------------------------------------------------------------------------------- /src/generator/extension.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_GENERATOR_EXTENSION_HH 24 | #define PB_GENERATOR_EXTENSION_HH 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "generator/field.hh" 34 | 35 | /* ---------------------------------------------------------------------------- 36 | * Interface 37 | * ------------------------------------------------------------------------- */ 38 | 39 | namespace protobluff { 40 | 41 | using ::std::map; 42 | using ::std::string; 43 | using ::std::vector; 44 | 45 | using ::google::protobuf::Descriptor; 46 | using ::google::protobuf::FieldDescriptor; 47 | using ::google::protobuf::io::Printer; 48 | 49 | class Extension { 50 | 51 | public: 52 | 53 | explicit 54 | Extension( 55 | const Descriptor *descriptor, /* Descriptor */ 56 | const Descriptor 57 | *scope = NULL); /* Scope descriptor */ 58 | 59 | void 60 | AddField( 61 | const FieldDescriptor 62 | *descriptor); /* Field descriptor */ 63 | 64 | void 65 | GenerateDefaults( 66 | Printer *printer) /* Printer */ 67 | const; 68 | 69 | void 70 | GenerateDescriptor( 71 | Printer *printer) /* Printer */ 72 | const; 73 | 74 | void 75 | GenerateInitializer( 76 | Printer *printer) /* Printer */ 77 | const; 78 | 79 | void 80 | GenerateAccessors( 81 | Printer *printer) /* Printer */ 82 | const; 83 | 84 | bool 85 | HasDefaults() 86 | const; 87 | 88 | private: 89 | const Descriptor *descriptor_; /* Descriptor */ 90 | const Descriptor *scope_; /* Scope descriptor */ 91 | vector fields_; /* Field generators */ 92 | map variables_; /* Variables */ 93 | }; 94 | } 95 | 96 | #endif /* PB_GENERATOR_EXTENSION_HH */ 97 | -------------------------------------------------------------------------------- /src/generator/field.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_GENERATOR_FIELD_HH 24 | #define PB_GENERATOR_FIELD_HH 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | /* ---------------------------------------------------------------------------- 34 | * Interface 35 | * ------------------------------------------------------------------------- */ 36 | 37 | namespace protobluff { 38 | 39 | using ::std::map; 40 | using ::std::string; 41 | using ::std::vector; 42 | 43 | using ::google::protobuf::FieldDescriptor; 44 | using ::google::protobuf::io::Printer; 45 | 46 | class Field { 47 | 48 | public: 49 | explicit 50 | Field( 51 | const FieldDescriptor 52 | *descriptor); /* Field descriptor */ 53 | 54 | void 55 | GenerateTag( 56 | Printer *printer) /* Printer */ 57 | const; 58 | 59 | void 60 | GenerateDefault( 61 | Printer *printer) /* Printer */ 62 | const; 63 | 64 | void 65 | GenerateDescriptor( 66 | Printer *printer) /* Printer */ 67 | const; 68 | 69 | void 70 | GenerateEncoder( 71 | Printer *printer) /* Printer */ 72 | const; 73 | 74 | void 75 | GenerateAccessors( 76 | Printer *printer) /* Printer */ 77 | const; 78 | 79 | void 80 | GenerateAccessors( 81 | Printer *printer, /* Printer */ 82 | vector< 83 | const FieldDescriptor * 84 | > &trace) /* Trace */ 85 | const; 86 | 87 | bool 88 | HasDefault() 89 | const; 90 | 91 | friend bool 92 | FieldComparator( 93 | const Field *x, /* Field generator */ 94 | const Field *y); /* Field generator */ 95 | 96 | private: 97 | const FieldDescriptor 98 | *descriptor_; /* Field descriptor */ 99 | map variables_; /* Variables */ 100 | 101 | bool 102 | ShouldTrace() 103 | const; 104 | }; 105 | 106 | bool 107 | FieldComparator( 108 | const Field *x, /* Field generator */ 109 | const Field *y); /* Field generator */ 110 | } 111 | 112 | #endif /* PB_GENERATOR_FIELD_HH */ 113 | -------------------------------------------------------------------------------- /src/generator/file.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_GENERATOR_FILE_HH 24 | #define PB_GENERATOR_FILE_HH 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "generator/enum.hh" 36 | #include "generator/extension.hh" 37 | #include "generator/message.hh" 38 | 39 | /* ---------------------------------------------------------------------------- 40 | * Interface 41 | * ------------------------------------------------------------------------- */ 42 | 43 | namespace protobluff { 44 | 45 | using ::std::map; 46 | using ::std::string; 47 | using ::std::unique_ptr; 48 | using ::std::vector; 49 | 50 | using ::google::protobuf::FileDescriptor; 51 | using ::google::protobuf::FileOptions; 52 | using ::google::protobuf::io::Printer; 53 | 54 | class File { 55 | 56 | public: 57 | explicit 58 | File( 59 | const FileDescriptor 60 | *descriptor); /* File descriptor */ 61 | 62 | void 63 | GenerateHeader( 64 | Printer *printer) /* Printer */ 65 | const; 66 | 67 | void 68 | GenerateSource( 69 | Printer *printer) /* Printer */ 70 | const; 71 | 72 | bool 73 | HasDefaults() 74 | const; 75 | 76 | bool 77 | HasEnums() 78 | const; 79 | 80 | bool 81 | HasOneofs() 82 | const; 83 | 84 | bool 85 | HasExtensions() 86 | const; 87 | 88 | private: 89 | const FileDescriptor *descriptor_; /* File descriptor */ 90 | const FileOptions::OptimizeMode 91 | mode_; /* Optimization mode */ 92 | unique_ptr< 93 | unique_ptr[] 94 | > enums_; /* Enum generators */ 95 | unique_ptr< 96 | unique_ptr[] 97 | > messages_; /* Message generators */ 98 | vector extensions_; /* Extension generators */ 99 | map variables_; /* Variables */ 100 | 101 | void 102 | PrintBanner( 103 | Printer *printer, /* Printer */ 104 | const char title[]) /* Title */ 105 | const; 106 | 107 | void 108 | PrintDisclaimer( 109 | Printer *printer) /* Printer */ 110 | const; 111 | }; 112 | } 113 | 114 | #endif /* PB_GENERATOR_FILE_HH */ 115 | -------------------------------------------------------------------------------- /src/generator/generator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "generator/file.hh" 33 | #include "generator/generator.hh" 34 | #include "generator/strutil.hh" 35 | 36 | /* ---------------------------------------------------------------------------- 37 | * Interface 38 | * ------------------------------------------------------------------------- */ 39 | 40 | namespace protobluff { 41 | 42 | using ::std::string; 43 | using ::std::unique_ptr; 44 | 45 | using ::google::protobuf::compiler::CodeGenerator; 46 | using ::google::protobuf::compiler::OutputDirectory; 47 | using ::google::protobuf::FileDescriptor; 48 | using ::google::protobuf::io::Printer; 49 | using ::google::protobuf::io::ZeroCopyOutputStream; 50 | 51 | using ::google::protobuf::StripSuffixString; 52 | 53 | /*! 54 | * Generate Protobluff-compatible source and header files from a file. 55 | * 56 | * \param[in] descriptor File descriptor 57 | * \param[in] parameter Command-line parameters 58 | * \param[in] directory Output directory 59 | * \param[out] error Error pointer 60 | */ 61 | bool Generator:: 62 | Generate( 63 | const FileDescriptor *descriptor, const string ¶meter, 64 | OutputDirectory *directory, string *error) const { 65 | assert(descriptor && directory && error); 66 | 67 | /* Construct basename for source and header files */ 68 | string basename = StripSuffixString(descriptor->name(), ".proto") + ".pb"; 69 | 70 | /* Create file generator from descriptor */ 71 | File file (descriptor); 72 | 73 | /* Generate header file */ 74 | { 75 | unique_ptr output( 76 | directory->Open(basename + ".h")); 77 | Printer printer (output.get(), '`'); 78 | file.GenerateHeader(&printer); 79 | } 80 | 81 | /* Generate source file */ 82 | { 83 | unique_ptr output( 84 | directory->Open(basename + ".c")); 85 | Printer printer (output.get(), '`'); 86 | file.GenerateSource(&printer); 87 | } 88 | return true; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/generator/generator.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_GENERATOR_GENERATOR_HH 24 | #define PB_GENERATOR_GENERATOR_HH 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Interface 33 | * ------------------------------------------------------------------------- */ 34 | 35 | namespace protobluff { 36 | 37 | using ::std::string; 38 | 39 | using ::google::protobuf::compiler::CodeGenerator; 40 | using ::google::protobuf::compiler::OutputDirectory; 41 | using ::google::protobuf::FileDescriptor; 42 | 43 | class Generator : public CodeGenerator { 44 | 45 | public: 46 | bool Generate( 47 | const FileDescriptor 48 | *descriptor, /* File descriptor */ 49 | const string ¶meter, /* Command-line parameters */ 50 | OutputDirectory *directory, /* Output directory */ 51 | string *error) /* Error pointer */ 52 | const; 53 | }; 54 | } 55 | 56 | #endif /* PB_GENERATOR_GENERATOR_HH */ 57 | -------------------------------------------------------------------------------- /src/generator/oneof.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_GENERATOR_ONEOF_HH 24 | #define PB_GENERATOR_ONEOF_HH 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "generator/field.hh" 34 | 35 | /* ---------------------------------------------------------------------------- 36 | * Interface 37 | * ------------------------------------------------------------------------- */ 38 | 39 | namespace protobluff { 40 | 41 | using ::std::map; 42 | using ::std::string; 43 | using ::std::unique_ptr; 44 | 45 | using ::google::protobuf::OneofDescriptor; 46 | using ::google::protobuf::io::Printer; 47 | 48 | class Oneof { 49 | 50 | public: 51 | explicit 52 | Oneof( 53 | const OneofDescriptor 54 | *descriptor); /* Oneof descriptor */ 55 | 56 | void 57 | GenerateDeclaration( 58 | Printer *printer) /* Printer */ 59 | const; 60 | 61 | void 62 | GenerateDescriptor( 63 | Printer *printer) /* Printer */ 64 | const; 65 | 66 | void 67 | GenerateAccessors( 68 | Printer *printer) /* Printer */ 69 | const; 70 | 71 | private: 72 | const OneofDescriptor 73 | *descriptor_; /* Oneof descriptor */ 74 | unique_ptr< 75 | unique_ptr[] 76 | > fields_; /* Field generators */ 77 | map variables_; /* Variables */ 78 | }; 79 | } 80 | 81 | #endif /* PB_GENERATOR_ONEOF_HH */ 82 | -------------------------------------------------------------------------------- /src/generator/protoc-gen-protobluff.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | 25 | #include "generator/generator.hh" 26 | 27 | /* ---------------------------------------------------------------------------- 28 | * Program 29 | * ------------------------------------------------------------------------- */ 30 | 31 | /*! 32 | * Execute the Protobluff generator on the given input files. 33 | * 34 | * \param[in] argc Argument count 35 | * \param[in] argv[] Arguments 36 | * \return Exit code 37 | */ 38 | int 39 | main(int argc, char *argv[]) { 40 | protobluff::Generator generator; 41 | return PluginMain(argc, argv, &generator); 42 | } 43 | -------------------------------------------------------------------------------- /src/message/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Intermediary library: message 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build message intermediary library 26 | noinst_LTLIBRARIES = libprotobluff-message.la 27 | libprotobluff_message_la_SOURCES = \ 28 | buffer.c \ 29 | common.c \ 30 | cursor.c \ 31 | field.c \ 32 | journal.c \ 33 | message.c \ 34 | nested.c \ 35 | oneof.c \ 36 | part.c 37 | libprotobluff_message_la_CPPFLAGS = \ 38 | -I@top_builddir@/src \ 39 | -I@top_builddir@/include \ 40 | @OPTIMIZATIONS@ \ 41 | @coverage_CPPFLAGS@ 42 | libprotobluff_message_la_LDFLAGS = \ 43 | @coverage_LDFLAGS@ 44 | -------------------------------------------------------------------------------- /src/message/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_MESSAGE_BUFFER_H 24 | #define PB_MESSAGE_BUFFER_H 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "core/buffer.h" 32 | #include "message/common.h" 33 | 34 | /* ---------------------------------------------------------------------------- 35 | * Interface 36 | * ------------------------------------------------------------------------- */ 37 | 38 | PB_WARN_UNUSED_RESULT 39 | extern pb_error_t 40 | pb_buffer_write( 41 | pb_buffer_t *buffer, /* Buffer */ 42 | size_t start, /* Start offset */ 43 | size_t end, /* End offset */ 44 | const uint8_t data[], /* Raw data */ 45 | size_t size); /* Raw data size */ 46 | 47 | PB_WARN_UNUSED_RESULT 48 | extern pb_error_t 49 | pb_buffer_clear( 50 | pb_buffer_t *buffer, /* Buffer */ 51 | size_t start, /* Start offset */ 52 | size_t end); /* End offset */ 53 | 54 | extern void 55 | pb_buffer_dump_range( 56 | const pb_buffer_t *buffer, /* Buffer */ 57 | size_t start, /* Start offset */ 58 | size_t end); /* End offset */ 59 | 60 | #endif /* PB_MESSAGE_BUFFER_H */ 61 | -------------------------------------------------------------------------------- /src/message/common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include "message/common.h" 24 | 25 | /* ---------------------------------------------------------------------------- 26 | * Mappings 27 | * ------------------------------------------------------------------------- */ 28 | 29 | /*! Mapping: error ==> error string */ 30 | static const char * 31 | error_map[] = { 32 | [PB_ERROR_NONE] = "None", 33 | [PB_ERROR_ALLOC] = "Allocation failed", 34 | [PB_ERROR_INVALID] = "Invalid arguments or data", 35 | [PB_ERROR_VARINT] = "Invalid varint", 36 | [PB_ERROR_OFFSET] = "Invalid offset", 37 | [PB_ERROR_ABSENT] = "Absent field or value", 38 | [PB_ERROR_EOM] = "Cursor reached end of message" 39 | }; 40 | 41 | /* ---------------------------------------------------------------------------- 42 | * Interface 43 | * ------------------------------------------------------------------------- */ 44 | 45 | /* LCOV_EXCL_START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ 46 | 47 | /*! 48 | * Retrieve a string representation of an error. 49 | * 50 | * \param[in] error Error 51 | * \return Error string 52 | */ 53 | extern const char * 54 | pb_error_string(pb_error_t error) { 55 | return error_map[error]; 56 | } 57 | 58 | /* LCOV_EXCL_STOP <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ 59 | -------------------------------------------------------------------------------- /src/message/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_MESSAGE_COMMON_H 24 | #define PB_MESSAGE_COMMON_H 25 | 26 | #include 27 | 28 | #include "core/common.h" 29 | 30 | #endif /* PB_MESSAGE_COMMON_H */ 31 | -------------------------------------------------------------------------------- /src/message/nested.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_MESSAGE_NESTED_H 24 | #define PB_MESSAGE_NESTED_H 25 | 26 | #include 27 | 28 | #endif /* PB_MESSAGE_NESTED_H */ 29 | -------------------------------------------------------------------------------- /src/message/oneof.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include "core/descriptor.h" 27 | #include "message/common.h" 28 | #include "message/cursor.h" 29 | #include "message/message.h" 30 | #include "message/oneof.h" 31 | 32 | /* ---------------------------------------------------------------------------- 33 | * Interface 34 | * ------------------------------------------------------------------------- */ 35 | 36 | /*! 37 | * Create a oneof from a descriptor and a message. 38 | * 39 | * \param[in] descriptor Oneof descriptor 40 | * \param[in,out] message Message 41 | * \return Oneof 42 | */ 43 | extern pb_oneof_t 44 | pb_oneof_create( 45 | const pb_oneof_descriptor_t *descriptor, pb_message_t *message) { 46 | assert(descriptor && message); 47 | pb_oneof_t oneof = { 48 | .descriptor = descriptor, 49 | .cursor = pb_cursor_create_without_tag(message) 50 | }; 51 | return oneof; 52 | } 53 | 54 | /*! 55 | * Destroy a oneof. 56 | * 57 | * \param[in,out] oneof Oneof 58 | */ 59 | extern void 60 | pb_oneof_destroy(pb_oneof_t *oneof) { 61 | assert(oneof); 62 | pb_cursor_destroy(&(oneof->cursor)); 63 | } 64 | 65 | /*! 66 | * Retrieve the active tag of a oneof. 67 | * 68 | * \param[in,out] oneof Oneof 69 | * \return Tag 70 | */ 71 | extern pb_tag_t 72 | pb_oneof_case(pb_oneof_t *oneof) { 73 | assert(oneof); 74 | pb_tag_t tag = 0; 75 | if (pb_cursor_rewind(&(oneof->cursor))) { 76 | do { 77 | const pb_field_descriptor_t *descriptor = 78 | pb_cursor_descriptor(&(oneof->cursor)); 79 | if (pb_field_descriptor_oneof(descriptor) == oneof->descriptor) 80 | tag = pb_cursor_tag(&(oneof->cursor)); 81 | } while (pb_cursor_next(&(oneof->cursor))); 82 | } 83 | return tag; 84 | } 85 | 86 | /*! 87 | * Clear all members of a oneof. 88 | * 89 | * \param[in,out] oneof Oneof 90 | * \return Error code 91 | */ 92 | extern pb_error_t 93 | pb_oneof_clear(pb_oneof_t *oneof) { 94 | assert(oneof); 95 | pb_error_t error = PB_ERROR_NONE; 96 | if (pb_cursor_rewind(&(oneof->cursor))) { 97 | do { 98 | const pb_field_descriptor_t *descriptor = 99 | pb_cursor_descriptor(&(oneof->cursor)); 100 | if (pb_field_descriptor_oneof(descriptor) == oneof->descriptor) 101 | error = pb_cursor_erase(&(oneof->cursor)); 102 | } while (!error && pb_cursor_next(&(oneof->cursor))); 103 | } 104 | return error; 105 | } 106 | -------------------------------------------------------------------------------- /src/message/oneof.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_MESSAGE_ONEOF_H 24 | #define PB_MESSAGE_ONEOF_H 25 | 26 | #include 27 | 28 | #include "message/common.h" 29 | #include "message/cursor.h" 30 | 31 | /* ---------------------------------------------------------------------------- 32 | * Inline functions 33 | * ------------------------------------------------------------------------- */ 34 | 35 | /*! 36 | * Create an invalid oneof. 37 | * 38 | * \return Oneof 39 | */ 40 | PB_INLINE PB_WARN_UNUSED_RESULT 41 | pb_oneof_t 42 | pb_oneof_create_invalid(void) { 43 | pb_oneof_t oneof = { 44 | .descriptor = NULL, 45 | .cursor = pb_cursor_create_invalid() 46 | }; 47 | return oneof; 48 | } 49 | 50 | #endif /* PB_MESSAGE_ONEOF_H */ 51 | -------------------------------------------------------------------------------- /src/protobluff-lite.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | includedir=@includedir@ 4 | libdir=@libdir@ 5 | 6 | Name: protobluff-lite 7 | Description: A modular Protocol Buffers implementation for C 8 | URL: https://github.com/squidfunk/protobluff 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lprotobluff-lite 12 | Conflicts: protobluff 13 | -------------------------------------------------------------------------------- /src/protobluff.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | includedir=@includedir@ 4 | libdir=@libdir@ 5 | 6 | Name: protobluff 7 | Description: A modular Protocol Buffers implementation for C 8 | URL: https://github.com/squidfunk/protobluff 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lprotobluff 12 | Conflicts: protobluff-lite 13 | -------------------------------------------------------------------------------- /src/util/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Intermediary library: util 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build util intermediary library 26 | noinst_LTLIBRARIES = libprotobluff-util.la 27 | libprotobluff_util_la_SOURCES = \ 28 | chunk_allocator.c \ 29 | descriptor.c \ 30 | validator.c 31 | libprotobluff_util_la_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include \ 34 | @OPTIMIZATIONS@ \ 35 | @coverage_CPPFLAGS@ 36 | libprotobluff_util_la_LDFLAGS = \ 37 | @coverage_LDFLAGS@ 38 | -------------------------------------------------------------------------------- /src/util/chunk_allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_UTIL_CHUNK_ALLOCATOR_H 24 | #define PB_UTIL_CHUNK_ALLOCATOR_H 25 | 26 | #include 27 | 28 | #endif /* PB_UTIL_CHUNK_ALLOCATOR_H */ 29 | -------------------------------------------------------------------------------- /src/util/descriptor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "core/common.h" 28 | #include "util/descriptor.h" 29 | 30 | /* ---------------------------------------------------------------------------- 31 | * Interface 32 | * ------------------------------------------------------------------------- */ 33 | 34 | /*! 35 | * Retrieve the field descriptor for a given name from a descriptor. 36 | * 37 | * \warning Querying a descriptor by name is far less efficient than querying 38 | * by tag, as a lot more comparisons are involved. 39 | * 40 | * \param[in] descriptor Descriptor 41 | * \param[in] name[] Name 42 | * \return Field descriptor 43 | */ 44 | extern const pb_field_descriptor_t * 45 | pb_descriptor_field_by_name( 46 | const pb_descriptor_t *descriptor, const char name[]) { 47 | assert(descriptor && name); 48 | for (size_t f = 0; f < descriptor->field.size; ++f) { 49 | if (strcmp(pb_field_descriptor_name(&(descriptor->field.data[f])), name)) 50 | continue; 51 | return &(descriptor->field.data[f]); 52 | } 53 | return pb_descriptor_extension(descriptor) ? 54 | pb_descriptor_field_by_name( 55 | pb_descriptor_extension(descriptor), name) : NULL; 56 | } 57 | 58 | /* ------------------------------------------------------------------------- */ 59 | 60 | /*! 61 | * Retrieve the value descriptor for a given name from an enum descriptor. 62 | * 63 | * \warning Querying an enum descriptor by name is far less efficient than 64 | * querying by number, as a lot more comparisons are involved. 65 | * 66 | * \param[in] descriptor Enum descriptor 67 | * \param[in] name Name 68 | * \return Enum value descriptor 69 | */ 70 | extern const struct pb_enum_value_descriptor_t * 71 | pb_enum_descriptor_value_by_name( 72 | const pb_enum_descriptor_t *descriptor, const char name[]) { 73 | assert(descriptor && name); 74 | for (size_t v = 0; v < descriptor->value.size; ++v) { 75 | if (strcmp(pb_enum_value_descriptor_name( 76 | &(descriptor->value.data[v])), name)) 77 | continue; 78 | return &(descriptor->value.data[v]); 79 | } 80 | return NULL; 81 | } 82 | -------------------------------------------------------------------------------- /src/util/descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_UTIL_DESCRIPTOR_H 24 | #define PB_UTIL_DESCRIPTOR_H 25 | 26 | #include 27 | 28 | #include "core/descriptor.h" 29 | 30 | #endif /* PB_UTIL_DESCRIPTOR_H */ 31 | -------------------------------------------------------------------------------- /src/util/validator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013-2020 Martin Donath 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef PB_UTIL_VALIDATOR_H 24 | #define PB_UTIL_VALIDATOR_H 25 | 26 | #include 27 | 28 | #endif /* PB_UTIL_VALIDATOR_H */ 29 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Subdirectories 23 | # ----------------------------------------------------------------------------- 24 | 25 | SUBDIRS = core message util 26 | 27 | # ----------------------------------------------------------------------------- 28 | # Tests 29 | # ----------------------------------------------------------------------------- 30 | 31 | # Add core tests 32 | TESTS = \ 33 | core/buffer/test \ 34 | core/decoder/test \ 35 | core/descriptor/test \ 36 | core/encoder/test \ 37 | core/stream/test \ 38 | core/varint/test 39 | 40 | # Add message tests 41 | TESTS += \ 42 | message/buffer/test \ 43 | message/cursor/test \ 44 | message/field/test \ 45 | message/journal/test \ 46 | message/message/test \ 47 | message/nested/test \ 48 | message/oneof/test \ 49 | message/part/test 50 | 51 | # Add util tests 52 | TESTS += \ 53 | util/chunk_allocator/test \ 54 | util/descriptor/test \ 55 | util/validator/test 56 | 57 | # ----------------------------------------------------------------------------- 58 | # Coverage report 59 | # ----------------------------------------------------------------------------- 60 | 61 | if HAVE_COVERAGE 62 | 63 | # Reset execution counts 64 | clean-local: 65 | @LCOV@ -z -d @top_builddir@/src 66 | rm -rf coverage 67 | rm -f coverage.info 68 | 69 | endif # HAVE_COVERAGE 70 | -------------------------------------------------------------------------------- /tests/core/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Subdirectories 23 | # ----------------------------------------------------------------------------- 24 | 25 | SUBDIRS = buffer decoder descriptor encoder stream varint 26 | -------------------------------------------------------------------------------- /tests/core/buffer/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/core/buffer 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/core/buffer test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/core/libprotobluff-core.la \ 36 | @check_LIBS@ 37 | test_LDFLAGS = \ 38 | @coverage_LDFLAGS@ 39 | -------------------------------------------------------------------------------- /tests/core/decoder/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/core/decoder 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/core/decoder test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/core/libprotobluff-core.la \ 36 | @check_LIBS@ 37 | test_LDFLAGS = \ 38 | @coverage_LDFLAGS@ 39 | -------------------------------------------------------------------------------- /tests/core/descriptor/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/core/descriptor 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/core/descriptor test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/core/libprotobluff-core.la \ 36 | @check_LIBS@ 37 | test_LDFLAGS = \ 38 | @coverage_LDFLAGS@ 39 | -------------------------------------------------------------------------------- /tests/core/encoder/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/core/encoder 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/core/encoder test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/core/libprotobluff-core.la \ 36 | @check_LIBS@ 37 | test_LDFLAGS = \ 38 | @coverage_LDFLAGS@ 39 | -------------------------------------------------------------------------------- /tests/core/stream/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/core/stream 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/core/stream test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/core/libprotobluff-core.la \ 36 | @check_LIBS@ 37 | test_LDFLAGS = \ 38 | @coverage_LDFLAGS@ 39 | -------------------------------------------------------------------------------- /tests/core/varint/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/core/varint 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/core/varint test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/core/libprotobluff-core.la \ 36 | @check_LIBS@ 37 | test_LDFLAGS = \ 38 | @coverage_LDFLAGS@ 39 | -------------------------------------------------------------------------------- /tests/message/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Subdirectories 23 | # ----------------------------------------------------------------------------- 24 | 25 | SUBDIRS = buffer cursor field journal message nested oneof part 26 | -------------------------------------------------------------------------------- /tests/message/buffer/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/buffer 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/buffer test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/message/cursor/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/cursor 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/cursor test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/message/field/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/field 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/field test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/message/journal/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/journal 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/journal test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/message/message/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/message 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/message test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/message/nested/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/nested 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/nested test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/message/oneof/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/oneof 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/oneof test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/message/part/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/message/part 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/message/part test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/message/libprotobluff-message.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/util/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Subdirectories 23 | # ----------------------------------------------------------------------------- 24 | 25 | SUBDIRS = chunk_allocator descriptor validator 26 | -------------------------------------------------------------------------------- /tests/util/chunk_allocator/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/util/chunk_allocator 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/util/chunk_allocator test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/util/libprotobluff-util.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/util/descriptor/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/util/descriptor 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/util/descriptor test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/util/libprotobluff-util.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /tests/util/validator/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Test suite: protobluff/util/validator 23 | # ----------------------------------------------------------------------------- 24 | 25 | # Build protobluff/util/validator test suite 26 | check_PROGRAMS = test 27 | test_SOURCES = \ 28 | test.c 29 | test_CFLAGS = \ 30 | @check_CFLAGS@ 31 | test_CPPFLAGS = \ 32 | -I@top_builddir@/src \ 33 | -I@top_builddir@/include 34 | test_LDADD = \ 35 | @top_builddir@/src/util/libprotobluff-util.la \ 36 | @top_builddir@/src/core/libprotobluff-core.la \ 37 | @check_LIBS@ 38 | test_LDFLAGS = \ 39 | @coverage_LDFLAGS@ 40 | -------------------------------------------------------------------------------- /valgrind.supp: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2020 Martin Donath 2 | 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to 5 | # deal in the Software without restriction, including without limitation the 6 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | # sell copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | # IN THE SOFTWARE. 20 | 21 | # ----------------------------------------------------------------------------- 22 | # Suppress invalid reads related to SSE optimizations 23 | # ----------------------------------------------------------------------------- 24 | 25 | { 26 | 27 | Memcheck:Addr16 28 | ... 29 | fun:pb_varint_scan 30 | } 31 | --------------------------------------------------------------------------------