├── .github ├── FUNDING.yml └── workflows │ └── test.yml ├── .gitignore ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── benchmark ├── .gitignore ├── Makefile ├── README.rst ├── benchmark.proto ├── common.mk ├── flatbuffers │ ├── Makefile │ ├── README.rst │ ├── benchmark.fbs │ ├── benchmark_generated.h │ └── main.cpp ├── google │ ├── Makefile │ ├── README.rst │ ├── benchmark.pb.cc │ ├── benchmark.pb.h │ └── main.cpp ├── nanopb │ ├── Makefile │ ├── README.rst │ ├── benchmark.pb.c │ ├── benchmark.pb.h │ ├── benchmark.proto │ ├── main.c │ ├── pb.h │ ├── pb_common.c │ ├── pb_common.h │ ├── pb_decode.c │ ├── pb_decode.h │ ├── pb_encode.c │ └── pb_encode.h ├── pbtools │ ├── Makefile │ ├── benchmark.c │ ├── benchmark.h │ └── main.c ├── protobuf-c │ ├── Makefile │ ├── README.rst │ ├── benchmark.pb-c.c │ ├── benchmark.pb-c.h │ └── main.c └── termgraph │ ├── decoding-time-speed.dat │ ├── encoding-time-speed.dat │ └── executable-size-text-speed.dat ├── crate ├── Cargo.toml ├── README.md └── src │ └── lib.rs ├── docs ├── Makefile ├── conf.py ├── index.rst └── make.bat ├── examples ├── Makefile ├── address_book │ ├── Makefile │ ├── address_book.proto │ ├── generated │ │ ├── address_book.c │ │ └── address_book.h │ ├── main.c │ ├── mys │ │ ├── .gitignore │ │ ├── package.toml │ │ └── src │ │ │ ├── address_book.mys │ │ │ └── main.mys │ └── rust │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── hello_world │ ├── Makefile │ ├── generated │ │ ├── hello_world.c │ │ └── hello_world.h │ ├── hello_world.proto │ └── main.c ├── oneof │ ├── Makefile │ ├── generated │ │ ├── oneof.c │ │ └── oneof.h │ ├── main.c │ ├── mys │ │ ├── .gitignore │ │ ├── package.toml │ │ └── src │ │ │ ├── main.mys │ │ │ └── oneof.mys │ └── oneof.proto └── repeated │ ├── Makefile │ ├── generated │ ├── repeated.c │ └── repeated.h │ ├── main.c │ └── repeated.proto ├── lib ├── CMakeLists.txt ├── Makefile ├── include │ └── pbtools.h └── src │ └── pbtools.c ├── pbtools ├── __init__.py ├── __main__.py ├── c_source │ └── __init__.py ├── errors.py ├── mys_source │ └── __init__.py ├── parser.py ├── rust_source │ └── __init__.py ├── subparsers │ ├── __init__.py │ ├── generate_c_source.py │ ├── generate_mys_source.py │ └── generate_rust_source.py └── version.py ├── requirements.txt ├── setup.py └── tests ├── Makefile ├── __init__.py ├── files ├── Makefile ├── add_and_remove_fields.proto ├── address_book.proto ├── benchmark.proto ├── bool.proto ├── bytes.proto ├── c_source │ ├── add_and_remove_fields.c │ ├── add_and_remove_fields.h │ ├── address_book.c │ ├── address_book.h │ ├── benchmark.c │ ├── benchmark.h │ ├── bool.c │ ├── bool.h │ ├── bytes.c │ ├── bytes.h │ ├── double.c │ ├── double.h │ ├── enum.c │ ├── enum.h │ ├── enum_provider.c │ ├── enum_provider.h │ ├── enum_user.c │ ├── enum_user.h │ ├── enums_upper_case_address_book.c │ ├── enums_upper_case_address_book.h │ ├── field_names.c │ ├── field_names.h │ ├── fixed32.c │ ├── fixed32.h │ ├── fixed64.c │ ├── fixed64.h │ ├── float.c │ ├── float.h │ ├── fuzzer.c │ ├── fuzzer.h │ ├── imported.c │ ├── imported.h │ ├── imported1.c │ ├── imported1.h │ ├── imported2.c │ ├── imported2.h │ ├── imported3.c │ ├── imported3.h │ ├── imported_duplicated_package.c │ ├── imported_duplicated_package.h │ ├── importing.c │ ├── importing.h │ ├── int32.c │ ├── int32.h │ ├── int64.c │ ├── int64.h │ ├── map.c │ ├── map.h │ ├── message.c │ ├── message.h │ ├── no_package.c │ ├── no_package.h │ ├── no_package_imported.c │ ├── no_package_imported.h │ ├── no_package_importing.c │ ├── no_package_importing.h │ ├── oneof.c │ ├── oneof.h │ ├── optional_fields.c │ ├── optional_fields.h │ ├── options.c │ ├── options.h │ ├── ordering.c │ ├── ordering.h │ ├── repeated.c │ ├── repeated.h │ ├── scalar_value_types.c │ ├── scalar_value_types.h │ ├── service.c │ ├── service.h │ ├── sfixed32.c │ ├── sfixed32.h │ ├── sfixed64.c │ ├── sfixed64.h │ ├── sint32.c │ ├── sint32.h │ ├── sint64.c │ ├── sint64.h │ ├── string.c │ ├── string.h │ ├── sub_message_pointers_message.c │ ├── sub_message_pointers_message.h │ ├── sub_message_pointers_repeated.c │ ├── sub_message_pointers_repeated.h │ ├── tags.c │ ├── tags.h │ ├── uint32.c │ ├── uint32.h │ ├── uint64.c │ └── uint64.h ├── comments.proto ├── comments_missing_multi_line_end.proto ├── comments_nested_multi_line.proto ├── double.proto ├── enum.proto ├── enum_provider.proto ├── enum_user.proto ├── field_names.proto ├── fixed32.proto ├── fixed64.proto ├── float.proto ├── fuzzer.proto ├── imported.proto ├── importing.proto ├── imports │ ├── ImportedDuplicatedPackage.proto │ ├── imported1.proto │ ├── imported2.proto │ └── imported3.proto ├── int32.proto ├── int64.proto ├── main.py ├── map.proto ├── message.proto ├── missing_type.proto ├── mys_source │ └── address_book.mys ├── no_package.proto ├── no_package_imported.proto ├── no_package_importing.proto ├── oneof.proto ├── optional_fields.proto ├── options.proto ├── ordering.proto ├── public_imported.proto ├── public_importing.proto ├── repeated.proto ├── reserved.proto ├── rust_source │ └── address_book.rs ├── scalar_value_types.proto ├── service.proto ├── sfixed32.proto ├── sfixed64.proto ├── sint32.proto ├── sint64.proto ├── string.proto ├── tags.proto ├── uint32.proto └── uint64.proto ├── main.c ├── main_fuzzer.c ├── nala.c ├── nala.h ├── test_c_source.py ├── test_command_line.py ├── test_parser.py └── utils.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: eerimoq 2 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Python package 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | macos: 7 | runs-on: macos-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Set up Python 3.9 11 | uses: actions/setup-python@v1 12 | with: 13 | python-version: 3.9 14 | - name: Install dependencies 15 | run: | 16 | python -m pip install --upgrade pip 17 | pip install -r requirements.txt 18 | - name: Test Python 19 | run: | 20 | python -m unittest 21 | - name: Test C 22 | run: | 23 | make test-c 24 | - name: Examples 25 | run: | 26 | make -C examples 27 | 28 | linux: 29 | runs-on: ubuntu-latest 30 | steps: 31 | - uses: actions/checkout@v1 32 | - name: Set up Python 3.9 33 | uses: actions/setup-python@v1 34 | with: 35 | python-version: 3.9 36 | - name: Install dependencies 37 | run: | 38 | python -m pip install --upgrade pip 39 | pip install -r requirements.txt 40 | - name: Test Python 41 | run: | 42 | python -m unittest 43 | - name: Test C 44 | run: | 45 | make test-c 46 | - name: Test CMake 47 | run: | 48 | mkdir lib/build 49 | cd lib/build 50 | cmake .. 51 | make 52 | cmake --install . --prefix foo 53 | ls foo/include/pbtools.h foo/lib/libpbtools.a 54 | - name: Examples 55 | run: | 56 | make -C examples 57 | 58 | release: 59 | needs: [linux, macos] 60 | runs-on: ubuntu-20.04 61 | if: startsWith(github.ref, 'refs/tags') 62 | 63 | steps: 64 | - name: Checkout 65 | uses: actions/checkout@v1 66 | - name: Set up Python 3.9 67 | uses: actions/setup-python@v1 68 | with: 69 | python-version: 3.9 70 | - name: Install pypa/build 71 | run: | 72 | python -m pip install build --user 73 | - name: Build a binary wheel and a source tarball 74 | run: | 75 | git clean -dfx 76 | python -m build --sdist --outdir dist/ . 77 | - name: Publish distribution 📦 to PyPI 78 | uses: pypa/gh-action-pypi-publish@master 79 | with: 80 | skip_existing: true 81 | password: ${{ secrets.pypi_password }} 82 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | *.o 8 | a.out* 9 | 10 | # Distribution / packaging 11 | .Python 12 | env/ 13 | venv/ 14 | .venv/ 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *,cover 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | # Vim IDE 62 | *~ 63 | *.swp 64 | *.swo 65 | 66 | # IntelliJ IDEA 67 | .idea/ 68 | 69 | main 70 | *_pb2.py 71 | /*.[hc] 72 | *.gcda 73 | *.gcno 74 | tests/crash-* 75 | tests/main_fuzzer* 76 | /address_book 77 | report.json 78 | generated 79 | lib/libpbtools.a 80 | Cargo.lock 81 | /*.rs -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Erik Moqvist 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 deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | 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 all 13 | 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 NONINFRINGEMENT. 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 FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include Makefile 3 | recursive-include tests *.py *.proto *.h *.c 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | INC += pbtools/c_source/ 2 | SRC ?= \ 3 | pbtools/c_source/pbtools.c \ 4 | tests/files/c_source/int32.c \ 5 | tests/files/c_source/int64.c \ 6 | tests/files/c_source/sint32.c \ 7 | tests/files/c_source/sint64.c \ 8 | tests/files/c_source/uint32.c \ 9 | tests/files/c_source/uint64.c \ 10 | tests/files/c_source/fixed32.c \ 11 | tests/files/c_source/fixed64.c \ 12 | tests/files/c_source/sfixed32.c \ 13 | tests/files/c_source/sfixed64.c \ 14 | tests/files/c_source/float.c \ 15 | tests/files/c_source/double.c \ 16 | tests/files/c_source/bool.c \ 17 | tests/files/c_source/string.c \ 18 | tests/files/c_source/bytes.c \ 19 | tests/files/c_source/enum.c \ 20 | tests/files/c_source/address_book.c \ 21 | tests/files/c_source/tags.c \ 22 | tests/files/c_source/oneof.c \ 23 | tests/files/c_source/repeated.c \ 24 | tests/files/c_source/scalar_value_types.c \ 25 | tests/files/c_source/benchmark.c \ 26 | tests/files/c_source/message.c \ 27 | tests/files/c_source/no_package.c \ 28 | tests/files/c_source/ordering.c \ 29 | tests/files/c_source/importing.c \ 30 | tests/files/c_source/imported.c \ 31 | tests/files/c_source/imported1.c \ 32 | tests/files/c_source/imported2.c \ 33 | tests/files/c_source/imported3.c \ 34 | tests/files/c_source/imported_duplicated_package.c \ 35 | tests/files/c_source/no_package_importing.c \ 36 | tests/files/c_source/no_package_imported.c \ 37 | tests/files/c_source/enum_user.c \ 38 | tests/files/c_source/enum_provider.c \ 39 | tests/files/c_source/field_names.c 40 | CFLAGS += $(INC:%=-I%) 41 | CFLAGS += -O2 42 | CFLAGS += -c 43 | CFLAGS += -Wall 44 | CFLAGS += -Wextra 45 | 46 | test: 47 | $(MAKE) test-python 48 | $(MAKE) test-c 49 | 50 | test-python: 51 | python3 -m unittest 52 | 53 | test-c: 54 | $(MAKE) -C tests 55 | $(MAKE) -C lib 56 | 57 | test-c-avr: 58 | avr-gcc $(CFLAGS) $(SRC) 59 | 60 | test-c-arm: 61 | arm-none-eabi-gcc $(CFLAGS) $(SRC) 62 | 63 | test-c-fuzzer: 64 | $(MAKE) -C tests fuzzer 65 | 66 | release-to-pypi: 67 | python setup.py sdist 68 | python setup.py bdist_wheel --universal 69 | twine upload dist/* 70 | 71 | generate: 72 | $(MAKE) -C examples generate 73 | $(MAKE) -C benchmark/pbtools generate 74 | $(MAKE) -C tests fuzzer-generate 75 | 76 | rust-crate: 77 | cd crate && cargo build 78 | 79 | rust: 80 | cd examples/address_book/rust && cargo build && ./target/debug/rust 81 | -------------------------------------------------------------------------------- /benchmark/.gitignore: -------------------------------------------------------------------------------- 1 | main-size 2 | main-size-lto 3 | main-speed 4 | main-speed-lto 5 | nanopb-repo -------------------------------------------------------------------------------- /benchmark/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C nanopb 3 | $(MAKE) -C pbtools 4 | 5 | graphs: 6 | echo "Encoding time:" 7 | termgraph termgraph/encoding-time-speed.dat | sort 8 | echo "Decoding time:" 9 | termgraph termgraph/decoding-time-speed.dat | sort 10 | echo "Executable size:" 11 | termgraph termgraph/executable-size-text-speed.dat | sort 12 | -------------------------------------------------------------------------------- /benchmark/benchmark.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package benchmark; 4 | 5 | option java_package = "com.google.protobuf.benchmarks"; 6 | option optimize_for = SPEED; 7 | option cc_enable_arenas = true; 8 | 9 | enum Enum { 10 | E0 = 0; 11 | E1 = 1; 12 | E2 = 2; 13 | E3 = 3; 14 | E5 = 5; 15 | } 16 | 17 | message SubMessage { 18 | uint32 field1 = 1; 19 | uint32 field2 = 2; 20 | int32 field3 = 3; 21 | string field15 = 15; 22 | bytes field12 = 12; 23 | int64 field13 = 13; 24 | int64 field14 = 14; 25 | fixed64 field21 = 21; 26 | int32 field22 = 22; 27 | bool field206 = 206; 28 | fixed32 field203 = 203; 29 | int32 field204 = 204; 30 | string field205 = 205; 31 | uint64 field207 = 207; 32 | Enum field300 = 300; 33 | } 34 | 35 | message Message1 { 36 | bool field80 = 80; 37 | bool field81 = 81; 38 | int32 field2 = 2; 39 | int32 field3 = 3; 40 | int32 field280 = 280; 41 | int32 field6 = 6; 42 | int64 field22 = 22; 43 | repeated string field4 = 4; 44 | bool field59 = 59; 45 | int32 field16 = 16; 46 | int32 field150 = 150; 47 | int32 field23 = 23; 48 | bool field24 = 24; 49 | int32 field25 = 25; 50 | SubMessage field15 = 15; 51 | bool field78 = 78; 52 | int32 field67 = 67; 53 | int32 field68 = 68; 54 | int32 field128 = 128; 55 | string field129 = 129; 56 | int32 field131 = 131; 57 | } 58 | 59 | message Message2 { 60 | Enum field1 = 1; 61 | uint64 field2 = 2; 62 | sint32 field3 = 3; 63 | string field4 = 4; 64 | int32 field5 = 5; 65 | bool field6 = 6; 66 | } 67 | 68 | message Message3 { 69 | message SubMessage { 70 | int32 field28 = 28; 71 | int64 field2 = 2; 72 | int32 field12 = 12; 73 | string field19 = 19; 74 | int32 field11 = 11; 75 | } 76 | 77 | repeated SubMessage field13 = 13; 78 | } 79 | 80 | message Message { 81 | oneof oneof { 82 | Message1 message1 = 1; 83 | Message2 message2 = 2; 84 | Message3 message3 = 7; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /benchmark/common.mk: -------------------------------------------------------------------------------- 1 | SHELL = /usr/bin/env bash 2 | 3 | CFLAGS = \ 4 | -Igenerated \ 5 | -ffunction-sections \ 6 | -fdata-sections \ 7 | -Wl,--gc-sections 8 | 9 | OPT_SIZE = -Os 10 | OPT_SPEED = -O2 11 | 12 | ITERATIONS = 2000000 13 | -------------------------------------------------------------------------------- /benchmark/flatbuffers/Makefile: -------------------------------------------------------------------------------- 1 | ARGS = \ 2 | $(CFLAGS) \ 3 | -std=c++11 \ 4 | *.cpp 5 | 6 | all: 7 | g++ $(ARGS) $(OPT_SIZE) -o main-size 8 | g++ $(ARGS) $(OPT_SPEED) -o main-speed 9 | size main-size 10 | size main-speed 11 | time ./main-size encode $(ITERATIONS) 12 | time ./main-size decode $(ITERATIONS) 13 | time ./main-speed encode $(ITERATIONS) 14 | time ./main-speed decode $(ITERATIONS) 15 | 16 | generate: 17 | flatc --cpp benchmark.fbs 18 | 19 | include ../common.mk 20 | -------------------------------------------------------------------------------- /benchmark/flatbuffers/README.rst: -------------------------------------------------------------------------------- 1 | .. code-block:: text 2 | 3 | $ git clone https://github.com/google/flatbuffers.git 4 | $ cd flatbuffers 5 | $ cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release 6 | $ make -j4 7 | $ sudo make install 8 | -------------------------------------------------------------------------------- /benchmark/flatbuffers/benchmark.fbs: -------------------------------------------------------------------------------- 1 | namespace benchmark; 2 | 3 | enum Enum : int { 4 | E0 = 0, 5 | E1, 6 | E2, 7 | E3, 8 | E5 9 | } 10 | 11 | table SubMessage { 12 | field1:uint; 13 | field2:uint; 14 | field3:int; 15 | field15:string; 16 | field12:[ubyte]; 17 | field13:long; 18 | field14:long; 19 | field21:ulong; 20 | field22:int; 21 | field206:bool; 22 | field203:uint; 23 | field204:int; 24 | field205:string; 25 | field207:ulong; 26 | field300:Enum; 27 | } 28 | 29 | table Message1 { 30 | field80:bool; 31 | field81:bool; 32 | field2:int; 33 | field3:int; 34 | field280:int; 35 | field6:int; 36 | field22:long; 37 | field4:[string]; 38 | field59:bool; 39 | field16:int; 40 | field150:int; 41 | field23:int; 42 | field24:bool; 43 | field25:int; 44 | field15:SubMessage; 45 | field78:bool; 46 | field67:int; 47 | field68:int; 48 | field128:int; 49 | field129:string; 50 | field131:int; 51 | } 52 | 53 | table Message2 { 54 | field1:Enum; 55 | field2:ulong; 56 | field3:int; 57 | field4:string; 58 | field5:int; 59 | field6:bool; 60 | } 61 | 62 | table SubMessage2 { 63 | field28:int; 64 | field2:long; 65 | field12:int; 66 | field19:string; 67 | field11:int; 68 | } 69 | 70 | table Message3 { 71 | field13:[SubMessage2]; 72 | } 73 | 74 | union Oneof { 75 | message1:Message1, 76 | message2:Message2, 77 | message3:Message3 78 | } 79 | 80 | table Message { 81 | oneof:Oneof; 82 | } 83 | -------------------------------------------------------------------------------- /benchmark/google/Makefile: -------------------------------------------------------------------------------- 1 | ARGS = \ 2 | $(CFLAGS) \ 3 | *.cpp *.cc \ 4 | -lprotobuf -pthread 5 | 6 | all: 7 | g++ $(ARGS) $(OPT_SIZE) -o main-size 8 | g++ $(ARGS) $(OPT_SPEED) -o main-speed 9 | size main-size 10 | size main-speed 11 | time ./main-size encode $(ITERATIONS) 12 | time ./main-size decode $(ITERATIONS) 13 | time ./main-speed encode $(ITERATIONS) 14 | time ./main-speed decode $(ITERATIONS) 15 | 16 | include ../common.mk 17 | -------------------------------------------------------------------------------- /benchmark/google/README.rst: -------------------------------------------------------------------------------- 1 | Probably have to regenerate as protobuf headers and libraries are not 2 | part of this benchmark. 3 | 4 | ``sudo snap install protobuf`` probably needed. 5 | -------------------------------------------------------------------------------- /benchmark/nanopb/Makefile: -------------------------------------------------------------------------------- 1 | ARGS = -I. $(CFLAGS) *.c 2 | 3 | all: 4 | gcc $(ARGS) $(OPT_SIZE) -o main-size 5 | gcc $(ARGS) $(OPT_SIZE) -flto -o main-size-lto 6 | gcc $(ARGS) $(OPT_SPEED) -o main-speed 7 | gcc $(ARGS) $(OPT_SPEED) -flto -o main-speed-lto 8 | readelf -s -W main-size | sort -k3 -n 9 | readelf -s -W main-size-lto | sort -k3 -n 10 | size main-size 11 | size main-size-lto 12 | size main-speed 13 | size main-speed-lto 14 | time ./main-size encode $(ITERATIONS) 15 | time ./main-size decode $(ITERATIONS) 16 | time ./main-size-lto encode $(ITERATIONS) 17 | time ./main-size-lto decode $(ITERATIONS) 18 | time ./main-speed encode $(ITERATIONS) 19 | time ./main-speed decode $(ITERATIONS) 20 | time ./main-speed-lto encode $(ITERATIONS) 21 | time ./main-speed-lto decode $(ITERATIONS) 22 | 23 | include ../common.mk 24 | -------------------------------------------------------------------------------- /benchmark/nanopb/README.rst: -------------------------------------------------------------------------------- 1 | Help 2 | ---- 3 | 4 | .. code-block:: Text 5 | 6 | $ git clone https://github.com/nanopb/nanopb.git nanopb-repo 7 | $ protoc \ 8 | --plugin=protoc-gen-nanopb=nanopb-repo/generator/protoc-gen-nanopb \ 9 | -I=. \ 10 | -I=nanopb-repo/generator/proto \ 11 | --nanopb_out=. \ 12 | benchmark.proto 13 | -------------------------------------------------------------------------------- /benchmark/nanopb/benchmark.pb.c: -------------------------------------------------------------------------------- 1 | /* Automatically generated nanopb constant definitions */ 2 | /* Generated by nanopb-0.4.0-dev */ 3 | 4 | #include "benchmark.pb.h" 5 | 6 | /* @@protoc_insertion_point(includes) */ 7 | #if PB_PROTO_HEADER_VERSION != 40 8 | #error Regenerate this file with the current version of nanopb generator. 9 | #endif 10 | 11 | PB_BIND(benchmark_SubMessage, benchmark_SubMessage, 2) 12 | 13 | 14 | PB_BIND(benchmark_Message1, benchmark_Message1, 2) 15 | 16 | 17 | PB_BIND(benchmark_Message2, benchmark_Message2, AUTO) 18 | 19 | 20 | PB_BIND(benchmark_Message3, benchmark_Message3, AUTO) 21 | 22 | 23 | PB_BIND(benchmark_Message3_SubMessage, benchmark_Message3_SubMessage, AUTO) 24 | 25 | 26 | PB_BIND(benchmark_Message, benchmark_Message, 2) 27 | 28 | 29 | 30 | 31 | /* @@protoc_insertion_point(eof) */ 32 | -------------------------------------------------------------------------------- /benchmark/nanopb/benchmark.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "nanopb.proto"; 4 | 5 | package benchmark; 6 | 7 | option java_package = "com.google.protobuf.benchmarks"; 8 | option optimize_for = SPEED; 9 | option cc_enable_arenas = true; 10 | option (nanopb_fileopt).no_unions = true; 11 | 12 | enum Enum { 13 | E0 = 0; 14 | E1 = 1; 15 | E2 = 2; 16 | E3 = 3; 17 | E5 = 5; 18 | } 19 | 20 | message SubMessage { 21 | uint32 field1 = 1; 22 | uint32 field2 = 2; 23 | int32 field3 = 3; 24 | string field15 = 15; 25 | bytes field12 = 12; 26 | int64 field13 = 13; 27 | int64 field14 = 14; 28 | fixed64 field21 = 21; 29 | int32 field22 = 22; 30 | bool field206 = 206; 31 | fixed32 field203 = 203; 32 | int32 field204 = 204; 33 | string field205 = 205; 34 | uint64 field207 = 207; 35 | Enum field300 = 300; 36 | } 37 | 38 | message Message1 { 39 | bool field80 = 80; 40 | bool field81 = 81; 41 | int32 field2 = 2; 42 | int32 field3 = 3; 43 | int32 field280 = 280; 44 | int32 field6 = 6; 45 | int64 field22 = 22; 46 | repeated string field4 = 4; 47 | bool field59 = 59; 48 | int32 field16 = 16; 49 | int32 field150 = 150; 50 | int32 field23 = 23; 51 | bool field24 = 24; 52 | int32 field25 = 25; 53 | SubMessage field15 = 15; 54 | bool field78 = 78; 55 | int32 field67 = 67; 56 | int32 field68 = 68; 57 | int32 field128 = 128; 58 | string field129 = 129; 59 | int32 field131 = 131; 60 | } 61 | 62 | message Message2 { 63 | Enum field1 = 1; 64 | uint64 field2 = 2; 65 | sint32 field3 = 3; 66 | string field4 = 4; 67 | int32 field5 = 5; 68 | bool field6 = 6; 69 | } 70 | 71 | message Message3 { 72 | message SubMessage { 73 | int32 field28 = 28; 74 | int64 field2 = 2; 75 | int32 field12 = 12; 76 | string field19 = 19; 77 | int32 field11 = 11; 78 | } 79 | 80 | repeated SubMessage field13 = 13; 81 | } 82 | 83 | message Message { 84 | oneof oneof { 85 | Message1 message1 = 1; 86 | Message2 message2 = 2; 87 | Message3 message3 = 7; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /benchmark/nanopb/pb_common.h: -------------------------------------------------------------------------------- 1 | /* pb_common.h: Common support functions for pb_encode.c and pb_decode.c. 2 | * These functions are rarely needed by applications directly. 3 | */ 4 | 5 | #ifndef PB_COMMON_H_INCLUDED 6 | #define PB_COMMON_H_INCLUDED 7 | 8 | #include "pb.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /* Initialize the field iterator structure to beginning. 15 | * Returns false if the message type is empty. */ 16 | bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_msgdesc_t *desc, void *message); 17 | 18 | /* Get a field iterator for extension field. */ 19 | bool pb_field_iter_begin_extension(pb_field_iter_t *iter, pb_extension_t *extension); 20 | 21 | /* Advance the iterator to the next field. 22 | * Returns false when the iterator wraps back to the first field. */ 23 | bool pb_field_iter_next(pb_field_iter_t *iter); 24 | 25 | /* Advance the iterator until it points at a field with the given tag. 26 | * Returns false if no such field exists. */ 27 | bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag); 28 | 29 | #ifdef __cplusplus 30 | } /* extern "C" */ 31 | #endif 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /benchmark/pbtools/Makefile: -------------------------------------------------------------------------------- 1 | ARGS = \ 2 | -I ../../lib/include \ 3 | $(CFLAGS) \ 4 | *.c \ 5 | ../../lib/src/pbtools.c 6 | 7 | all: 8 | gcc $(ARGS) $(OPT_SIZE) -o main-size 9 | gcc $(ARGS) $(OPT_SIZE) -flto -o main-size-lto 10 | gcc $(ARGS) $(OPT_SPEED) -o main-speed 11 | gcc $(ARGS) $(OPT_SPEED) -flto -o main-speed-lto 12 | readelf -s -W main-size | sort -k3 -n 13 | readelf -s -W main-size-lto | sort -k3 -n 14 | size main-size 15 | size main-size-lto 16 | size main-speed 17 | size main-speed-lto 18 | time ./main-size encode $(ITERATIONS) 19 | time ./main-size decode $(ITERATIONS) 20 | time ./main-size-lto encode $(ITERATIONS) 21 | time ./main-size-lto decode $(ITERATIONS) 22 | time ./main-speed encode $(ITERATIONS) 23 | time ./main-speed decode $(ITERATIONS) 24 | time ./main-speed-lto encode $(ITERATIONS) 25 | time ./main-speed-lto decode $(ITERATIONS) 26 | 27 | generate: 28 | env PYTHONPATH=../.. \ 29 | python3 -m pbtools generate_c_source ../benchmark.proto 30 | 31 | include ../common.mk 32 | -------------------------------------------------------------------------------- /benchmark/protobuf-c/Makefile: -------------------------------------------------------------------------------- 1 | ARGS = \ 2 | $(CFLAGS) \ 3 | *.c -static -lprotobuf-c 4 | 5 | all: 6 | gcc $(ARGS) $(OPT_SIZE) -o main-size 7 | gcc $(ARGS) $(OPT_SIZE) -flto -o main-size-lto 8 | gcc $(ARGS) $(OPT_SPEED) -o main-speed 9 | gcc $(ARGS) $(OPT_SPEED) -flto -o main-speed-lto 10 | readelf -s -W main-size | sort -k3 -n 11 | readelf -s -W main-size-lto | sort -k3 -n 12 | size main-size 13 | size main-size-lto 14 | size main-speed 15 | size main-speed-lto 16 | time ./main-size encode $(ITERATIONS) 17 | time ./main-size decode $(ITERATIONS) 18 | time ./main-size-lto encode $(ITERATIONS) 19 | time ./main-size-lto decode $(ITERATIONS) 20 | time ./main-speed encode $(ITERATIONS) 21 | time ./main-speed decode $(ITERATIONS) 22 | time ./main-speed-lto encode $(ITERATIONS) 23 | time ./main-speed-lto decode $(ITERATIONS) 24 | 25 | include ../common.mk 26 | -------------------------------------------------------------------------------- /benchmark/protobuf-c/README.rst: -------------------------------------------------------------------------------- 1 | git clone https://github.com/protobuf-c/protobuf-c.git 2 | 3 | Follow build and install instructions in the readme. 4 | -------------------------------------------------------------------------------- /benchmark/termgraph/decoding-time-speed.dat: -------------------------------------------------------------------------------- 1 | # Decoding time -O2/-O3 [ms] 2 | 3 | pbtools 1594 4 | google 1997 5 | protobuf-c 2508 6 | nanopb 6433 7 | flatbuffers 100 -------------------------------------------------------------------------------- /benchmark/termgraph/encoding-time-speed.dat: -------------------------------------------------------------------------------- 1 | # Encoding time -O2/-O3 [ms] 2 | 3 | pbtools 1457 4 | protobuf-c 1892 5 | google 2231 6 | nanopb 9580 7 | flatbuffers 2506 -------------------------------------------------------------------------------- /benchmark/termgraph/executable-size-text-speed.dat: -------------------------------------------------------------------------------- 1 | # Text segment size -O2/-O3 [bytes] 2 | 3 | pbtools 17484 4 | nanopb 21256 5 | flatbuffers 40017 -------------------------------------------------------------------------------- /crate/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pbtools" 3 | version = "0.15.0" 4 | authors = ["Erik Moqvist "] 5 | description = "Google Protocol Buffers encoding and decoding." 6 | license = "MIT" 7 | repository = "https://github.com/eerimoq/pbtools" 8 | keywords = ["protobuf", "proto", "proto3", "protocol-buffers"] 9 | readme = "README.md" 10 | edition = "2018" 11 | 12 | [dependencies] 13 | num_enum = "0.5.1" -------------------------------------------------------------------------------- /crate/README.md: -------------------------------------------------------------------------------- 1 | # Google Protocol Buffers encoding and decoding 2 | 3 | 🚧 🚧 🚧 🚧 🚧 **Under construction - DO NOT USE** 🚧 🚧 🚧 🚧 🚧 4 | 5 | Install the [Python 3 package 6 | pbtools](https://pypi.org/project/pbtools/) and use it to generate 7 | Rust source code from protobuf specification(s). Add the generated 8 | file(s) to your project's crate. Add this crate as a dependency in 9 | your project's Cargo.toml file and you should be good to go. 10 | 11 | 🚧 🚧 🚧 🚧 🚧 **Under construction - DO NOT USE** 🚧 🚧 🚧 🚧 🚧 12 | 13 | ``` console 14 | $ pip install pbtools 15 | $ pbtools generate_rust_source address_book.proto 16 | $ ls -l 17 | address_book.rs 18 | ``` 19 | 20 | # Example usage 21 | 22 | See 23 | https://github.com/eerimoq/pbtools/tree/rust/examples/address_book/rust 24 | for the complete example. 25 | 26 | ``` rust 27 | use address_book::{AddressBook, Person}; 28 | use address_book::person::{PhoneNumber, PhoneType}; 29 | 30 | fn main() { 31 | // Encode. 32 | let mut address_book = AddressBook { 33 | people: vec![ 34 | Person { 35 | name: String::from("Kalle Kula"), 36 | id: 56, 37 | email: String::from("kalle.kula@foobar.com"), 38 | phones: vec![ 39 | PhoneNumber { 40 | number: String::from("+46701232345"), 41 | type_: PhoneType::HOME 42 | }, 43 | PhoneNumber { 44 | number: String::from("+46999999999"), 45 | type_: PhoneType::WORK 46 | } 47 | ] 48 | } 49 | ] 50 | }; 51 | 52 | let encoded = address_book.encode(); 53 | println!("Encoded: {:?}", encoded); 54 | 55 | // Decode. 56 | address_book = Default::default(); 57 | 58 | match address_book.decode(encoded) { 59 | Ok(()) => println!("Ok!"), 60 | Err(message) => println!("Error: {}", message) 61 | } 62 | 63 | println!("Decoded:\n{:#?}", address_book); 64 | } 65 | ``` 66 | -------------------------------------------------------------------------------- /crate/src/lib.rs: -------------------------------------------------------------------------------- 1 | use num_enum::TryFromPrimitive; 2 | use std::convert::TryFrom; 3 | 4 | #[derive(Debug, Eq, PartialEq, TryFromPrimitive)] 5 | #[repr(u32)] 6 | enum WireType { 7 | Varint = 0, 8 | Bits64 = 1, 9 | LengthDelimited = 2, 10 | Bits32 = 5 11 | } 12 | 13 | pub struct Encoder { 14 | pub encoded: Vec 15 | } 16 | 17 | impl Encoder { 18 | fn write_tagged_varint(&mut self, 19 | field_number: u32, 20 | wire_type: WireType, 21 | value: u64) { 22 | if value > 0 { 23 | self.write_tag(field_number, wire_type); 24 | self.write_varint(value); 25 | } 26 | } 27 | 28 | fn write_tag(&mut self, field_number: u32, wire_type: WireType) { 29 | self.write_varint((field_number << 3 | wire_type as u32) as u64); 30 | } 31 | 32 | fn write_varint(&mut self, mut value: u64) { 33 | loop { 34 | let item = value as u8; 35 | value >>= 7; 36 | 37 | if value == 0 { 38 | self.encoded.push(item); 39 | break; 40 | } else { 41 | self.encoded.push(item | 0x80); 42 | } 43 | } 44 | } 45 | 46 | pub fn write_length_delimited(&mut self, field_number: u32, value: u64) { 47 | self.write_tag(field_number, WireType::LengthDelimited); 48 | self.write_varint(value); 49 | } 50 | 51 | pub fn write_string(&mut self, field_number: u32, value: &String) { 52 | self.write_tagged_varint(field_number, 53 | WireType::LengthDelimited, 54 | value.len() as u64); 55 | self.encoded.extend(value.as_bytes()); 56 | } 57 | 58 | pub fn write_int32(&mut self, field_number: u32, value: i32) { 59 | self.write_tagged_varint(field_number, 60 | WireType::Varint, 61 | value as i64 as u64); 62 | } 63 | } 64 | 65 | pub struct Decoder { 66 | pub pos: usize, 67 | pub encoded: Vec 68 | } 69 | 70 | impl Decoder { 71 | pub fn available(&self) -> bool { 72 | self.pos < self.encoded.len() 73 | } 74 | 75 | pub fn read_tag(&mut self) -> (u32, u32) { 76 | if self.pos < self.encoded.len() { 77 | self.pos += 1; 78 | (1, self.encoded[self.pos - 1] as u32) 79 | } else { 80 | (0, 0) 81 | } 82 | } 83 | 84 | pub fn read_varint(&mut self) -> u64 { 85 | 5 86 | } 87 | 88 | pub fn read_length_delimited(&mut self) -> u64{ 89 | 3 90 | } 91 | 92 | pub fn read_string(&mut self, _wire_type: u32) -> String { 93 | String::from("koko") 94 | } 95 | 96 | pub fn read_int32(&mut self, _wire_type: u32) -> i32 { 97 | 5 98 | } 99 | 100 | pub fn seek(&mut self, offset: u32) { 101 | self.pos += offset as usize; 102 | } 103 | 104 | pub fn skip_field(&mut self, wire_type: u32) { 105 | match WireType::try_from(wire_type) { 106 | Ok(WireType::Varint) => { 107 | self.read_varint(); 108 | }, 109 | Ok(WireType::Bits64) => self.seek(8), 110 | Ok(WireType::LengthDelimited) => { 111 | self.read_length_delimited(); 112 | }, 113 | Ok(WireType::Bits32) => self.seek(4), 114 | Err(message) => panic!("{}", message) 115 | }; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. pbtools documentation master file, created by 2 | sphinx-quickstart on Sat Apr 25 11:54:09 2015. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | Google protocol buffers tools 10 | ============================= 11 | 12 | .. include:: ../README.rst 13 | 14 | Functions and classes 15 | ===================== 16 | 17 | .. autofunction:: pbtools.parse_file 18 | 19 | .. autoclass:: pbtools.parser.Proto 20 | :members: 21 | 22 | .. autoclass:: pbtools.parser.Message 23 | :members: 24 | 25 | .. autofunction:: pbtools.c_source.generate_files 26 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C address_book 3 | $(MAKE) -C hello_world 4 | $(MAKE) -C oneof 5 | $(MAKE) -C repeated 6 | 7 | generate: 8 | $(MAKE) -C address_book generate 9 | $(MAKE) -C hello_world generate 10 | $(MAKE) -C oneof generate 11 | $(MAKE) -C repeated generate 12 | -------------------------------------------------------------------------------- /examples/address_book/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc \ 3 | -O2 \ 4 | -Wall \ 5 | -Wno-gnu-alignof-expression \ 6 | -I ../../lib/include \ 7 | -I generated \ 8 | generated/*.c \ 9 | ../../lib/src/pbtools.c \ 10 | main.c \ 11 | -o main 12 | ./main 13 | 14 | generate: 15 | rm -rf generated 16 | mkdir -p generated 17 | cd generated && \ 18 | env PYTHONPATH=../../.. \ 19 | python3 -m pbtools generate_c_source ../address_book.proto 20 | -------------------------------------------------------------------------------- /examples/address_book/address_book.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package address_book; 4 | 5 | message Person { 6 | string name = 1; 7 | int32 id = 2; 8 | string email = 3; 9 | 10 | enum PhoneType { 11 | MOBILE = 0; 12 | HOME = 1; 13 | WORK = 2; 14 | } 15 | 16 | message PhoneNumber { 17 | string number = 1; 18 | PhoneType type = 2; 19 | } 20 | 21 | repeated PhoneNumber phones = 4; 22 | } 23 | 24 | message AddressBook { 25 | repeated Person people = 1; 26 | } 27 | -------------------------------------------------------------------------------- /examples/address_book/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "address_book.h" 10 | 11 | int main(int argc, const char *argv[]) 12 | { 13 | uint8_t encoded[128]; 14 | int size; 15 | uint8_t workspace[1024]; 16 | struct address_book_address_book_t *address_book_p; 17 | struct address_book_person_t *person_p; 18 | struct address_book_person_phone_number_t *phone_number_p; 19 | 20 | address_book_p = address_book_address_book_new(&workspace[0], 21 | sizeof(workspace)); 22 | assert(address_book_p != NULL); 23 | 24 | /* Add one person to the address book. */ 25 | assert(address_book_address_book_people_alloc(address_book_p, 1) == 0); 26 | person_p = &address_book_p->people.items_p[0]; 27 | person_p->name_p = "Kalle Kula"; 28 | person_p->id = 56; 29 | person_p->email_p = "kalle.kula@foobar.com"; 30 | 31 | /* Add phone numbers. */ 32 | assert(address_book_person_phones_alloc(person_p, 2) == 0); 33 | 34 | /* Home. */ 35 | phone_number_p = &person_p->phones.items_p[0]; 36 | phone_number_p->number_p = "+46701232345"; 37 | phone_number_p->type = address_book_person_phone_type_home_e; 38 | 39 | /* Work. */ 40 | phone_number_p = &person_p->phones.items_p[1]; 41 | phone_number_p->number_p = "+46999999999"; 42 | phone_number_p->type = address_book_person_phone_type_work_e; 43 | 44 | /* Encode the message. */ 45 | size = address_book_address_book_encode(address_book_p, 46 | &encoded[0], 47 | sizeof(encoded)); 48 | assert(size == 75); 49 | assert(memcmp(&encoded[0], 50 | "\x0a\x49\x0a\x0a\x4b\x61\x6c\x6c\x65\x20" 51 | "\x4b\x75\x6c\x61\x10\x38\x1a\x15\x6b\x61" 52 | "\x6c\x6c\x65\x2e\x6b\x75\x6c\x61\x40\x66" 53 | "\x6f\x6f\x62\x61\x72\x2e\x63\x6f\x6d\x22" 54 | "\x10\x0a\x0c\x2b\x34\x36\x37\x30\x31\x32" 55 | "\x33\x32\x33\x34\x35\x10\x01\x22\x10\x0a" 56 | "\x0c\x2b\x34\x36\x39\x39\x39\x39\x39\x39" 57 | "\x39\x39\x39\x10\x02", 58 | size) == 0); 59 | 60 | /* Decode the message. */ 61 | address_book_p = address_book_address_book_new(&workspace[0], 62 | sizeof(workspace)); 63 | assert(address_book_p != NULL); 64 | size = address_book_address_book_decode(address_book_p, &encoded[0], size); 65 | assert(size >= 0); 66 | assert(address_book_p->people.length == 1); 67 | 68 | /* Check the decoded person. */ 69 | person_p = &address_book_p->people.items_p[0]; 70 | assert(strcmp(person_p->name_p, "Kalle Kula") == 0); 71 | assert(person_p->id == 56); 72 | assert(strcmp(person_p->email_p, "kalle.kula@foobar.com") == 0); 73 | assert(person_p->phones.length == 2); 74 | 75 | /* Check home phone number. */ 76 | phone_number_p = &person_p->phones.items_p[0]; 77 | assert(strcmp(phone_number_p->number_p, "+46701232345") == 0); 78 | assert(phone_number_p->type == address_book_person_phone_type_home_e); 79 | 80 | /* Check work phone number. */ 81 | phone_number_p = &person_p->phones.items_p[1]; 82 | assert(strcmp(phone_number_p->number_p, "+46999999999") == 0); 83 | assert(phone_number_p->type == address_book_person_phone_type_work_e); 84 | 85 | return (0); 86 | } 87 | -------------------------------------------------------------------------------- /examples/address_book/mys/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *~ 3 | .coverage 4 | .mys-coverage.txt 5 | coverage/ 6 | -------------------------------------------------------------------------------- /examples/address_book/mys/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "address_book" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | 6 | [dependencies] 7 | pbtools = "latest" 8 | -------------------------------------------------------------------------------- /examples/address_book/mys/src/address_book.mys: -------------------------------------------------------------------------------- 1 | # This file was generated by pbtools. 2 | 3 | from pbtools.decoder import Decoder 4 | from pbtools.encoder import Encoder 5 | from pbtools import WireType 6 | 7 | @enum(i32) 8 | class PersonPhoneType: 9 | Mobile = 0 10 | Home = 1 11 | Work = 2 12 | 13 | class PersonPhoneNumber: 14 | number: string 15 | type: PersonPhoneType 16 | 17 | def clear(self): 18 | self.number = "" 19 | self.type = PersonPhoneType(0) 20 | 21 | def to_bytes_inner(self, encoder: Encoder): 22 | encoder.write_enum(2, i32(self.type)) 23 | encoder.write_string(1, self.number) 24 | 25 | def from_bytes_inner(self, decoder: Decoder): 26 | while decoder.available(): 27 | field_number, wire_type = decoder.read_tag() 28 | 29 | match field_number: 30 | case 1: 31 | self.number = decoder.read_string(wire_type) 32 | case 2: 33 | self.type = PersonPhoneType(decoder.read_int32(wire_type)) 34 | case _: 35 | decoder.skip_field(wire_type) 36 | 37 | class Person: 38 | name: string 39 | id: i32 40 | email: string 41 | phones: [PersonPhoneNumber] 42 | 43 | def clear(self): 44 | self.name = "" 45 | self.id = 0 46 | self.email = "" 47 | self.phones = [] 48 | 49 | def to_bytes_inner(self, encoder: Encoder): 50 | for phone in reversed(self.phones): 51 | length = encoder.length() 52 | phone.to_bytes_inner(encoder) 53 | encoder.write_length_delimited(4, encoder.length() - length) 54 | 55 | encoder.write_string(3, self.email) 56 | encoder.write_int32(2, self.id) 57 | encoder.write_string(1, self.name) 58 | 59 | def from_bytes_inner(self, decoder: Decoder): 60 | while decoder.available(): 61 | field_number, wire_type = decoder.read_tag() 62 | 63 | match field_number: 64 | case 1: 65 | self.name = decoder.read_string(wire_type) 66 | case 2: 67 | self.id = decoder.read_int32(wire_type) 68 | case 3: 69 | self.email = decoder.read_string(wire_type) 70 | case 4: 71 | phone = PersonPhoneNumber("", PersonPhoneType.Mobile) 72 | phone.from_bytes_inner( 73 | decoder.slice(i64( 74 | decoder.read_length_delimited(WireType.LengthDelimited)))) 75 | self.phones.append(phone) 76 | case _: 77 | decoder.skip_field(wire_type) 78 | 79 | class AddressBook: 80 | people: [Person] 81 | 82 | def clear(self): 83 | self.people.clear() 84 | 85 | def to_bytes(self) -> bytes: 86 | encoder = Encoder() 87 | self.to_bytes_inner(encoder) 88 | 89 | return encoder.finalize() 90 | 91 | def from_bytes(self, data: bytes): 92 | self.clear() 93 | self.from_bytes_inner(Decoder(data, 0, i64(len(data)))) 94 | 95 | def to_bytes_inner(self, encoder: Encoder): 96 | for person in reversed(self.people): 97 | length = encoder.length() 98 | person.to_bytes_inner(encoder) 99 | encoder.write_length_delimited(1, encoder.length() - length) 100 | 101 | def from_bytes_inner(self, decoder: Decoder): 102 | while decoder.available(): 103 | field_number, wire_type = decoder.read_tag() 104 | 105 | match field_number: 106 | case 1: 107 | person = Person("", 0, "", []) 108 | person.from_bytes_inner( 109 | decoder.slice(i64( 110 | decoder.read_length_delimited(WireType.LengthDelimited)))) 111 | self.people.append(person) 112 | case _: 113 | decoder.skip_field(wire_type) 114 | -------------------------------------------------------------------------------- /examples/address_book/mys/src/main.mys: -------------------------------------------------------------------------------- 1 | from .address_book import AddressBook 2 | from .address_book import Person 3 | from .address_book import PersonPhoneNumber 4 | from .address_book import PersonPhoneType 5 | 6 | def main(): 7 | address_book = AddressBook([ 8 | Person("Kalle Kula", 9 | 56, 10 | "kalle.kula@foobar.com", 11 | [ 12 | PersonPhoneNumber("+46701232345", PersonPhoneType.Home), 13 | PersonPhoneNumber("+46999999999", PersonPhoneType.Work) 14 | ]) 15 | ]) 16 | 17 | print(address_book) 18 | encoded = address_book.to_bytes() 19 | assert encoded == (b"\x0a\x49\x0a\x0a\x4b\x61\x6c\x6c\x65\x20" 20 | b"\x4b\x75\x6c\x61\x10\x38\x1a\x15\x6b\x61" 21 | b"\x6c\x6c\x65\x2e\x6b\x75\x6c\x61\x40\x66" 22 | b"\x6f\x6f\x62\x61\x72\x2e\x63\x6f\x6d\x22" 23 | b"\x10\x0a\x0c\x2b\x34\x36\x37\x30\x31\x32" 24 | b"\x33\x32\x33\x34\x35\x10\x01\x22\x10\x0a" 25 | b"\x0c\x2b\x34\x36\x39\x39\x39\x39\x39\x39" 26 | b"\x39\x39\x39\x10\x02") 27 | 28 | address_book.from_bytes(encoded) 29 | print(address_book) 30 | -------------------------------------------------------------------------------- /examples/address_book/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | pbtools = { path = "../../../crate" } -------------------------------------------------------------------------------- /examples/hello_world/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc \ 3 | -O2 \ 4 | -Wall \ 5 | -Wno-gnu-alignof-expression \ 6 | -I ../../lib/include \ 7 | -Igenerated \ 8 | generated/*.c \ 9 | ../../lib/src/pbtools.c \ 10 | main.c \ 11 | -o main 12 | ./main 13 | 14 | generate: 15 | rm -rf generated 16 | mkdir -p generated 17 | cd generated && \ 18 | env PYTHONPATH=../../.. \ 19 | python3 -m pbtools generate_c_source ../hello_world.proto 20 | -------------------------------------------------------------------------------- /examples/hello_world/generated/hello_world.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef HELLO_WORLD_H 32 | #define HELLO_WORLD_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message hello_world.Foo. 42 | */ 43 | struct hello_world_foo_repeated_t { 44 | int length; 45 | struct hello_world_foo_t *items_p; 46 | }; 47 | 48 | struct hello_world_foo_t { 49 | struct pbtools_message_base_t base; 50 | int32_t bar; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of hello_world.Foo. 55 | */ 56 | struct hello_world_foo_t * 57 | hello_world_foo_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int hello_world_foo_encode( 62 | struct hello_world_foo_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int hello_world_foo_decode( 67 | struct hello_world_foo_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void hello_world_foo_init( 74 | struct hello_world_foo_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void hello_world_foo_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct hello_world_foo_t *self_p); 80 | 81 | void hello_world_foo_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct hello_world_foo_t *self_p); 84 | 85 | void hello_world_foo_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct hello_world_foo_repeated_t *repeated_p); 89 | 90 | void hello_world_foo_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct hello_world_foo_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /examples/hello_world/hello_world.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package hello_world; 4 | 5 | message Foo { 6 | int32 bar = 1; 7 | } 8 | -------------------------------------------------------------------------------- /examples/hello_world/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hello_world.h" 3 | 4 | int main(int argc, const char *argv[]) 5 | { 6 | int size; 7 | uint8_t workspace[64]; 8 | uint8_t encoded[16]; 9 | struct hello_world_foo_t *foo_p; 10 | 11 | /* Encode. */ 12 | foo_p = hello_world_foo_new(&workspace[0], sizeof(workspace)); 13 | 14 | if (foo_p == NULL) { 15 | return (1); 16 | } 17 | 18 | foo_p->bar = 78; 19 | size = hello_world_foo_encode(foo_p, &encoded[0], sizeof(encoded)); 20 | 21 | if (size < 0) { 22 | return (2); 23 | } 24 | 25 | printf("Successfully encoded Foo into %d bytes.\n", size); 26 | 27 | /* Decode. */ 28 | foo_p = hello_world_foo_new(&workspace[0], sizeof(workspace)); 29 | 30 | if (foo_p == NULL) { 31 | return (3); 32 | } 33 | 34 | size = hello_world_foo_decode(foo_p, &encoded[0], size); 35 | 36 | if (size < 0) { 37 | return (4); 38 | } 39 | 40 | printf("Successfully decoded %d bytes into Foo.\n", size); 41 | printf("Foo.bar: %d\n", foo_p->bar); 42 | 43 | return (0); 44 | } 45 | -------------------------------------------------------------------------------- /examples/oneof/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc \ 3 | -O2 \ 4 | -Wall \ 5 | -Wno-gnu-alignof-expression \ 6 | -I ../../lib/include \ 7 | -Igenerated \ 8 | generated/*.c \ 9 | ../../lib/src/pbtools.c \ 10 | main.c \ 11 | -o main 12 | ./main 13 | 14 | generate: 15 | rm -rf generated 16 | mkdir -p generated 17 | cd generated && \ 18 | env PYTHONPATH=../../.. \ 19 | python3 -m pbtools generate_c_source ../oneof.proto 20 | -------------------------------------------------------------------------------- /examples/oneof/generated/oneof.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef ONEOF_H 32 | #define ONEOF_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Enum oneof.Foo.bar. 42 | */ 43 | enum oneof_foo_bar_e { 44 | oneof_foo_bar_none_e = 0, 45 | oneof_foo_bar_fie_e = 1, 46 | oneof_foo_bar_fum_e = 2 47 | }; 48 | 49 | /** 50 | * Message oneof.Foo. 51 | */ 52 | struct oneof_foo_repeated_t { 53 | int length; 54 | struct oneof_foo_t *items_p; 55 | }; 56 | 57 | struct oneof_foo_t { 58 | struct pbtools_message_base_t base; 59 | enum oneof_foo_bar_e bar; 60 | union { 61 | int32_t fie; 62 | bool fum; 63 | }; 64 | }; 65 | 66 | void oneof_foo_fie_init( 67 | struct oneof_foo_t *self_p); 68 | 69 | void oneof_foo_fum_init( 70 | struct oneof_foo_t *self_p); 71 | 72 | /** 73 | * Encoding and decoding of oneof.Foo. 74 | */ 75 | struct oneof_foo_t * 76 | oneof_foo_new( 77 | void *workspace_p, 78 | size_t size); 79 | 80 | int oneof_foo_encode( 81 | struct oneof_foo_t *self_p, 82 | uint8_t *encoded_p, 83 | size_t size); 84 | 85 | int oneof_foo_decode( 86 | struct oneof_foo_t *self_p, 87 | const uint8_t *encoded_p, 88 | size_t size); 89 | 90 | /* Internal functions. Do not use! */ 91 | 92 | void oneof_foo_init( 93 | struct oneof_foo_t *self_p, 94 | struct pbtools_heap_t *heap_p); 95 | 96 | void oneof_foo_encode_inner( 97 | struct pbtools_encoder_t *encoder_p, 98 | struct oneof_foo_t *self_p); 99 | 100 | void oneof_foo_decode_inner( 101 | struct pbtools_decoder_t *decoder_p, 102 | struct oneof_foo_t *self_p); 103 | 104 | void oneof_foo_encode_repeated_inner( 105 | struct pbtools_encoder_t *encoder_p, 106 | int field_number, 107 | struct oneof_foo_repeated_t *repeated_p); 108 | 109 | void oneof_foo_decode_repeated_inner( 110 | struct pbtools_decoder_t *decoder_p, 111 | struct pbtools_repeated_info_t *repeated_info_p, 112 | struct oneof_foo_repeated_t *repeated_p); 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /examples/oneof/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "oneof.h" 3 | 4 | int main(int argc, const char *argv[]) 5 | { 6 | int size; 7 | uint8_t workspace[64]; 8 | uint8_t encoded[16]; 9 | struct oneof_foo_t *foo_p; 10 | 11 | /* Encode. */ 12 | foo_p = oneof_foo_new(&workspace[0], sizeof(workspace)); 13 | 14 | if (foo_p == NULL) { 15 | return (1); 16 | } 17 | 18 | oneof_foo_fie_init(foo_p); 19 | foo_p->fie = 789; 20 | size = oneof_foo_encode(foo_p, &encoded[0], sizeof(encoded)); 21 | 22 | if (size < 0) { 23 | return (2); 24 | } 25 | 26 | printf("Successfully encoded Foo into %d bytes.\n", size); 27 | 28 | /* Decode. */ 29 | foo_p = oneof_foo_new(&workspace[0], sizeof(workspace)); 30 | 31 | if (foo_p == NULL) { 32 | return (3); 33 | } 34 | 35 | size = oneof_foo_decode(foo_p, &encoded[0], size); 36 | 37 | if (size < 0) { 38 | return (4); 39 | } 40 | 41 | printf("Successfully decoded %d bytes into Foo.\n", size); 42 | 43 | switch (foo_p->bar) { 44 | 45 | case oneof_foo_bar_fie_e: 46 | printf("Foo.fie: %d\n", foo_p->fie); 47 | break; 48 | 49 | case oneof_foo_bar_fum_e: 50 | printf("Foo.fum: %d\n", foo_p->fum); 51 | break; 52 | 53 | default: 54 | printf("Unknown choice %d\n", foo_p->bar); 55 | break; 56 | } 57 | 58 | return (0); 59 | } 60 | -------------------------------------------------------------------------------- /examples/oneof/mys/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *~ 3 | .coverage 4 | .mys-coverage.txt 5 | coverage/ 6 | -------------------------------------------------------------------------------- /examples/oneof/mys/package.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "oneof" 3 | version = "0.1.0" 4 | authors = ["Erik Moqvist "] 5 | 6 | [dependencies] 7 | pbtools = {"path" = "../../../../mys/package-pbtools"} 8 | -------------------------------------------------------------------------------- /examples/oneof/mys/src/main.mys: -------------------------------------------------------------------------------- 1 | from .oneof import Foo 2 | from .oneof import FooBar 3 | 4 | def main(): 5 | foo = Foo(FooBar.Fie, 789, False) 6 | 7 | print(foo) 8 | encoded = foo.to_bytes() 9 | assert encoded == b"\x08\x95\x06" 10 | 11 | foo.from_bytes(encoded) 12 | print(foo) 13 | -------------------------------------------------------------------------------- /examples/oneof/mys/src/oneof.mys: -------------------------------------------------------------------------------- 1 | # This file was generated by pbtools. 2 | 3 | from pbtools import Decoder 4 | from pbtools import Encoder 5 | 6 | @enum 7 | class FooBar: 8 | Fie = 0 9 | Fum = 1 10 | 11 | class Foo: 12 | bar: FooBar 13 | fie: i32 14 | fum: bool 15 | 16 | def clear(self): 17 | self.bar = FooBar.Fie 18 | self.fie = 0 19 | self.fum = False 20 | 21 | def to_bytes(self) -> bytes: 22 | encoder = Encoder() 23 | self.to_bytes_inner(encoder) 24 | 25 | return encoder.data() 26 | 27 | def from_bytes(self, data: bytes): 28 | self.clear() 29 | self.from_bytes_inner(Decoder(data, 0, i64(len(data)))) 30 | 31 | def to_bytes_inner(self, encoder: Encoder): 32 | match self.bar: 33 | case FooBar.Fie: 34 | encoder.write_i32_always(1, self.fie) 35 | case FooBar.Fum: 36 | encoder.write_bool_always(2, self.fum) 37 | 38 | def from_bytes_inner(self, decoder: Decoder): 39 | while decoder.available(): 40 | field_number, wire_type = decoder.read_tag() 41 | 42 | match field_number: 43 | case 1: 44 | self.fie = decoder.read_i32(wire_type) 45 | case 2: 46 | self.fum = decoder.read_bool(wire_type) 47 | case _: 48 | decoder.skip_field(wire_type) 49 | -------------------------------------------------------------------------------- /examples/oneof/oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package oneof; 4 | 5 | message Foo { 6 | oneof bar { 7 | int32 fie = 1; 8 | bool fum = 2; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/repeated/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc \ 3 | -O2 \ 4 | -Wall \ 5 | -Wno-gnu-alignof-expression \ 6 | -I ../../lib/include \ 7 | -Igenerated \ 8 | generated/*.c \ 9 | ../../lib/src/pbtools.c \ 10 | main.c \ 11 | -o main 12 | ./main 13 | 14 | generate: 15 | rm -rf generated 16 | mkdir -p generated 17 | cd generated && \ 18 | env PYTHONPATH=../../.. \ 19 | python3 -m pbtools generate_c_source ../repeated.proto 20 | -------------------------------------------------------------------------------- /examples/repeated/generated/repeated.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef REPEATED_H 32 | #define REPEATED_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message Coordinates. 42 | */ 43 | struct coordinates_repeated_t { 44 | int length; 45 | struct coordinates_t *items_p; 46 | }; 47 | 48 | struct coordinates_t { 49 | struct pbtools_message_base_t base; 50 | struct pbtools_repeated_int32_t xs; 51 | struct pbtools_repeated_int32_t ys; 52 | }; 53 | 54 | int coordinates_xs_alloc( 55 | struct coordinates_t *self_p, 56 | int length); 57 | 58 | int coordinates_ys_alloc( 59 | struct coordinates_t *self_p, 60 | int length); 61 | 62 | /** 63 | * Encoding and decoding of Coordinates. 64 | */ 65 | struct coordinates_t * 66 | coordinates_new( 67 | void *workspace_p, 68 | size_t size); 69 | 70 | int coordinates_encode( 71 | struct coordinates_t *self_p, 72 | uint8_t *encoded_p, 73 | size_t size); 74 | 75 | int coordinates_decode( 76 | struct coordinates_t *self_p, 77 | const uint8_t *encoded_p, 78 | size_t size); 79 | 80 | /* Internal functions. Do not use! */ 81 | 82 | void coordinates_init( 83 | struct coordinates_t *self_p, 84 | struct pbtools_heap_t *heap_p); 85 | 86 | void coordinates_encode_inner( 87 | struct pbtools_encoder_t *encoder_p, 88 | struct coordinates_t *self_p); 89 | 90 | void coordinates_decode_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct coordinates_t *self_p); 93 | 94 | void coordinates_encode_repeated_inner( 95 | struct pbtools_encoder_t *encoder_p, 96 | int field_number, 97 | struct coordinates_repeated_t *repeated_p); 98 | 99 | void coordinates_decode_repeated_inner( 100 | struct pbtools_decoder_t *decoder_p, 101 | struct pbtools_repeated_info_t *repeated_info_p, 102 | struct coordinates_repeated_t *repeated_p); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /examples/repeated/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "repeated.h" 3 | 4 | static int32_t xs[] = { 1, 3, 5, 7, 9 }; 5 | 6 | int main(int argc, const char *argv[]) 7 | { 8 | int i; 9 | int res; 10 | int size; 11 | uint8_t workspace[128]; 12 | uint8_t encoded[64]; 13 | struct coordinates_t *coordinates_p; 14 | 15 | /* Encode. */ 16 | coordinates_p = coordinates_new(&workspace[0], sizeof(workspace)); 17 | 18 | if (coordinates_p == NULL) { 19 | return (1); 20 | } 21 | 22 | /* Set the length and items. */ 23 | coordinates_p->xs.length = 5; 24 | coordinates_p->xs.items_p = &xs[0]; 25 | 26 | /* Alternatively, allocate a buffer in the workspace. */ 27 | res = coordinates_ys_alloc(coordinates_p, 5); 28 | 29 | if (res != 0) { 30 | return (2); 31 | } 32 | 33 | coordinates_p->ys.items_p[0] = 0; 34 | coordinates_p->ys.items_p[1] = 2; 35 | coordinates_p->ys.items_p[2] = 4; 36 | coordinates_p->ys.items_p[3] = 6; 37 | coordinates_p->ys.items_p[4] = 8; 38 | 39 | size = coordinates_encode(coordinates_p, &encoded[0], sizeof(encoded)); 40 | 41 | if (size < 0) { 42 | return (3); 43 | } 44 | 45 | printf("Successfully encoded Coordinates into %d bytes.\n", size); 46 | 47 | /* Decode. */ 48 | coordinates_p = coordinates_new(&workspace[0], sizeof(workspace)); 49 | 50 | if (coordinates_p == NULL) { 51 | return (4); 52 | } 53 | 54 | size = coordinates_decode(coordinates_p, &encoded[0], size); 55 | 56 | if (size < 0) { 57 | return (5); 58 | } 59 | 60 | printf("Successfully decoded %d bytes into Coordinates.\n", size); 61 | 62 | if (coordinates_p->xs.length != coordinates_p->ys.length) { 63 | return (6); 64 | } 65 | 66 | for (i = 0; i < coordinates_p->xs.length; i++) { 67 | printf("(%d, %d)\n", 68 | (int)coordinates_p->xs.items_p[i], 69 | (int)coordinates_p->ys.items_p[i]); 70 | } 71 | 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /examples/repeated/repeated.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Coordinates { 4 | repeated int32 xs = 1; 5 | repeated int32 ys = 2; 6 | } 7 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(pbtools C) 3 | add_library(pbtools src/pbtools.c) 4 | set_property(TARGET pbtools PROPERTY C_STANDARD 11) 5 | target_include_directories(pbtools PUBLIC 6 | "${PROJECT_BINARY_DIR}" 7 | "${PROJECT_SOURCE_DIR}/include") 8 | install(TARGETS pbtools DESTINATION lib) 9 | install(FILES include/pbtools.h DESTINATION include) 10 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | CC = $(CROSS_COMPILE)gcc 2 | AR = $(CROSS_COMPILE)ar 3 | 4 | LIBRARY = libpbtools.a 5 | PREFIX ?= /usr/local 6 | 7 | .PHONY: library install clean 8 | 9 | library: $(LIBRARY) 10 | 11 | install: 12 | find include -type f -exec install -Dm 644 "{}" "$(PREFIX)/{}" \; 13 | mkdir -p $(PREFIX)/lib 14 | install -m 644 $(LIBRARY) $(PREFIX)/lib 15 | 16 | clean: 17 | rm $(LIBRARY) 18 | 19 | $(LIBRARY): 20 | $(CC) $(CFLAGS_EXTRA) \ 21 | -Wall \ 22 | -O2 \ 23 | -std=gnu11 \ 24 | -Wno-gnu-alignof-expression \ 25 | -Iinclude src/pbtools.c \ 26 | -c \ 27 | -o pbtools.o 28 | $(AR) cr $(LIBRARY) pbtools.o 29 | -------------------------------------------------------------------------------- /pbtools/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import argparse 3 | 4 | from .parser import parse_file 5 | from .version import __version__ 6 | from .errors import Error 7 | 8 | 9 | __author__ = 'Erik Moqvist' 10 | 11 | 12 | def _main(): 13 | parser = argparse.ArgumentParser( 14 | description='Various Google Protobuf utilities.') 15 | 16 | parser.add_argument('-d', '--debug', action='store_true') 17 | parser.add_argument('--version', 18 | action='version', 19 | version=__version__, 20 | help='Print version information and exit.') 21 | 22 | # Workaround to make the subparser required in Python 3. 23 | subparsers = parser.add_subparsers(title='subcommands', 24 | dest='subcommand') 25 | subparsers.required = True 26 | 27 | # Import when used for less dependencies. For example, curses is 28 | # not part of all Python builds. 29 | from .subparsers import generate_c_source 30 | from .subparsers import generate_mys_source 31 | from .subparsers import generate_rust_source 32 | 33 | generate_c_source.add_subparser(subparsers) 34 | generate_mys_source.add_subparser(subparsers) 35 | generate_rust_source.add_subparser(subparsers) 36 | 37 | args = parser.parse_args() 38 | 39 | if args.debug: 40 | args.func(args) 41 | else: 42 | try: 43 | args.func(args) 44 | except BaseException as e: 45 | sys.exit('error: ' + str(e)) 46 | -------------------------------------------------------------------------------- /pbtools/__main__.py: -------------------------------------------------------------------------------- 1 | # Execute as "python -m cantools" 2 | 3 | from . import _main as main 4 | 5 | main() 6 | -------------------------------------------------------------------------------- /pbtools/errors.py: -------------------------------------------------------------------------------- 1 | class Error(Exception): 2 | pass 3 | -------------------------------------------------------------------------------- /pbtools/subparsers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eerimoq/pbtools/d0a8d063dafcf128a60d9e40f823c1a80a53ac90/pbtools/subparsers/__init__.py -------------------------------------------------------------------------------- /pbtools/subparsers/generate_c_source.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from ..parser import camel_to_snake_case 4 | from ..c_source import generate_files 5 | from ..c_source import Options 6 | 7 | 8 | def _do_generate_c_source(args): 9 | options = Options(args.enums_upper_case) 10 | generate_files(args.infiles, 11 | args.import_path, 12 | args.output_directory, 13 | options) 14 | 15 | 16 | def add_subparser(subparsers): 17 | subparser = subparsers.add_parser( 18 | 'generate_c_source', 19 | description='Generate C source code from given protobuf file(s).') 20 | subparser.add_argument( 21 | '-I', '--import-path', 22 | action='append', 23 | default=[], 24 | help='Path(s) where to search for imports.') 25 | subparser.add_argument( 26 | '-o', '--output-directory', 27 | default='.', 28 | help='Output directory (default: %(default)s).') 29 | subparser.add_argument( 30 | 'infiles', 31 | nargs='+', 32 | help='Input protobuf file(s).') 33 | subparser.add_argument( 34 | '--enums-upper-case', 35 | action='store_true', 36 | help='Use upper case for generated enums.') 37 | subparser.set_defaults(func=_do_generate_c_source) 38 | -------------------------------------------------------------------------------- /pbtools/subparsers/generate_mys_source.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from ..parser import camel_to_snake_case 4 | from ..mys_source import generate_files 5 | 6 | 7 | def _do_generate_mys_source(args): 8 | generate_files(args.infiles, 9 | args.import_path, 10 | args.output_directory) 11 | 12 | 13 | def add_subparser(subparsers): 14 | subparser = subparsers.add_parser( 15 | 'generate_mys_source', 16 | description='Generate Mys source code from given protobuf file(s).') 17 | subparser.add_argument( 18 | '-I', '--import-path', 19 | action='append', 20 | default=[], 21 | help='Path(s) where to search for imports.') 22 | subparser.add_argument( 23 | '-o', '--output-directory', 24 | default='.', 25 | help='Output directory (default: %(default)s).') 26 | subparser.add_argument( 27 | 'infiles', 28 | nargs='+', 29 | help='Input protobuf file(s).') 30 | subparser.set_defaults(func=_do_generate_mys_source) 31 | -------------------------------------------------------------------------------- /pbtools/subparsers/generate_rust_source.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from ..parser import camel_to_snake_case 4 | from ..rust_source import generate_files 5 | 6 | 7 | def _do_generate_rust_source(args): 8 | generate_files(args.infiles, 9 | args.import_path, 10 | args.output_directory) 11 | 12 | 13 | def add_subparser(subparsers): 14 | subparser = subparsers.add_parser( 15 | 'generate_rust_source', 16 | description='Generate Rust source code from given protobuf file(s).') 17 | subparser.add_argument( 18 | '-I', '--import-path', 19 | action='append', 20 | default=[], 21 | help='Path(s) where to search for imports.') 22 | subparser.add_argument( 23 | '-o', '--output-directory', 24 | default='.', 25 | help='Output directory (default: %(default)s).') 26 | subparser.add_argument( 27 | 'infiles', 28 | nargs='+', 29 | help='Input protobuf file(s).') 30 | subparser.set_defaults(func=_do_generate_rust_source) 31 | -------------------------------------------------------------------------------- /pbtools/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.47.0' 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | textparser 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup 4 | from setuptools import find_packages 5 | import re 6 | 7 | 8 | def find_version(): 9 | return re.search(r"^__version__ = '(.*)'$", 10 | open('pbtools/version.py', 'r').read(), 11 | re.MULTILINE).group(1) 12 | 13 | 14 | setup(name='pbtools', 15 | version=find_version(), 16 | description='Google Protocol Buffers tools.', 17 | long_description=open('README.rst', 'r').read(), 18 | author='Erik Moqvist', 19 | author_email='erik.moqvist@gmail.com', 20 | license='MIT', 21 | classifiers=[ 22 | 'License :: OSI Approved :: MIT License', 23 | 'Programming Language :: Python :: 3', 24 | ], 25 | keywords=['protobuf', 'proto', 'protocol buffers'], 26 | url='https://github.com/eerimoq/pbtools', 27 | packages=find_packages(exclude=['tests']), 28 | install_requires=[ 29 | 'textparser>=0.21.1' 30 | ], 31 | test_suite="tests", 32 | include_package_data=True, 33 | entry_points = { 34 | 'console_scripts': ['pbtools=pbtools.__init__:_main'] 35 | }) 36 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | FUZZER_CC ?= clang 2 | FUZZER_EXE = main_fuzzer 3 | FUZZER_C_SOURCES = \ 4 | main_fuzzer.c \ 5 | ../lib/src/pbtools.c \ 6 | files/c_source/fuzzer.c 7 | FUZZER_CFLAGS = \ 8 | -fprofile-instr-generate \ 9 | -fcoverage-mapping \ 10 | -I ../lib/include \ 11 | -g \ 12 | -fsanitize=address,fuzzer \ 13 | -fsanitize=signed-integer-overflow \ 14 | -fno-sanitize-recover=all 15 | FUZZER_EXECUTION_TIME ?= 30 16 | 17 | CFLAGS ?= \ 18 | -Wno-gnu-alignof-expression \ 19 | -Wno-unused-command-line-argument \ 20 | -fprofile-arcs \ 21 | -ftest-coverage \ 22 | -fsanitize=address \ 23 | -fsanitize=signed-integer-overflow \ 24 | -Wdouble-promotion \ 25 | -Wfloat-equal \ 26 | -Wformat=2 \ 27 | -Wshadow \ 28 | -Werror \ 29 | -O1 \ 30 | -g \ 31 | -no-pie \ 32 | -std=gnu11 \ 33 | -Wconversion \ 34 | -Wno-sign-conversion \ 35 | -Wall \ 36 | -Wextra \ 37 | -Wpedantic 38 | 39 | all: 40 | gcc \ 41 | -D PBTOOLS_CONFIG_FLOAT=0 \ 42 | -I ../lib/include \ 43 | -c \ 44 | -Wno-gnu-alignof-expression \ 45 | ../lib/src/pbtools.c \ 46 | -o no-float.o 47 | gcc -O2 -g nala.c -c -o nala.o 48 | gcc -O2 -g -I ../lib/include main.c -c -o main.o 49 | gcc \ 50 | $(CFLAGS) \ 51 | -I ../lib/include \ 52 | nala.o \ 53 | ../lib/src/pbtools.c \ 54 | files/c_source/int32.c \ 55 | files/c_source/int64.c \ 56 | files/c_source/sint32.c \ 57 | files/c_source/sint64.c \ 58 | files/c_source/uint32.c \ 59 | files/c_source/uint64.c \ 60 | files/c_source/fixed32.c \ 61 | files/c_source/fixed64.c \ 62 | files/c_source/sfixed32.c \ 63 | files/c_source/sfixed64.c \ 64 | files/c_source/float.c \ 65 | files/c_source/double.c \ 66 | files/c_source/bool.c \ 67 | files/c_source/string.c \ 68 | files/c_source/bytes.c \ 69 | files/c_source/enum.c \ 70 | files/c_source/address_book.c \ 71 | files/c_source/tags.c \ 72 | files/c_source/oneof.c \ 73 | files/c_source/repeated.c \ 74 | files/c_source/scalar_value_types.c \ 75 | files/c_source/benchmark.c \ 76 | files/c_source/message.c \ 77 | files/c_source/no_package.c \ 78 | files/c_source/ordering.c \ 79 | files/c_source/optional_fields.c \ 80 | files/c_source/importing.c \ 81 | files/c_source/imported.c \ 82 | files/c_source/imported1.c \ 83 | files/c_source/imported2.c \ 84 | files/c_source/imported3.c \ 85 | files/c_source/imported_duplicated_package.c \ 86 | files/c_source/no_package_importing.c \ 87 | files/c_source/no_package_imported.c \ 88 | files/c_source/enum_user.c \ 89 | files/c_source/enum_provider.c \ 90 | files/c_source/field_names.c \ 91 | files/c_source/map.c \ 92 | files/c_source/add_and_remove_fields.c \ 93 | main.o 94 | ./a.out 95 | 96 | fuzzer-generate: 97 | cd files/c_source && \ 98 | env PYTHONPATH=../../.. \ 99 | python3 -m pbtools generate_c_source ../fuzzer.proto 100 | 101 | fuzzer: 102 | $(FUZZER_CC) $(FUZZER_CFLAGS) $(FUZZER_C_SOURCES) -o $(FUZZER_EXE) 103 | rm -f $(FUZZER_EXE).profraw 104 | LLVM_PROFILE_FILE="$(FUZZER_EXE).profraw" \ 105 | ./$(FUZZER_EXE) \ 106 | -max_total_time=$(FUZZER_EXECUTION_TIME) \ 107 | -print_final_stats \ 108 | -max_len=1024 109 | llvm-profdata merge \ 110 | -sparse $(FUZZER_EXE).profraw \ 111 | -o $(FUZZER_EXE).profdata 112 | llvm-cov show ./$(FUZZER_EXE) \ 113 | -instr-profile=$(FUZZER_EXE).profdata 114 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eerimoq/pbtools/d0a8d063dafcf128a60d9e40f823c1a80a53ac90/tests/__init__.py -------------------------------------------------------------------------------- /tests/files/Makefile: -------------------------------------------------------------------------------- 1 | python-run: 2 | python3 main.py 3 | 4 | python-generate: 5 | protoc --python_out=. *.proto 6 | -------------------------------------------------------------------------------- /tests/files/add_and_remove_fields.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package add_and_remove_fields; 4 | 5 | // First version. 6 | message Version1 { 7 | int32 v1 = 1; 8 | } 9 | 10 | // v2 and v3 added. 11 | message Version2 { 12 | int32 v1 = 1; 13 | int32 v2 = 2; 14 | int32 v3 = 3; 15 | } 16 | 17 | // v1 and v2 removed, v4 added. 18 | message Version3 { 19 | int32 v3 = 3; 20 | int32 v4 = 4; 21 | } 22 | -------------------------------------------------------------------------------- /tests/files/address_book.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package address_book; 4 | 5 | message Person { 6 | string name = 1; 7 | int32 id = 2; 8 | string email = 3; 9 | 10 | enum PhoneType { 11 | MOBILE = 0; 12 | HOME = 1; 13 | WORK = 2; 14 | } 15 | 16 | message PhoneNumber { 17 | string number = 1; 18 | PhoneType type = 2; 19 | } 20 | 21 | repeated PhoneNumber phones = 4; 22 | } 23 | 24 | message AddressBook { 25 | repeated Person people = 1; 26 | } 27 | -------------------------------------------------------------------------------- /tests/files/benchmark.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package benchmark; 4 | 5 | option java_package = "com.google.protobuf.benchmarks"; 6 | option optimize_for = SPEED; 7 | option cc_enable_arenas = true; 8 | 9 | enum Enum { 10 | E0 = 0; 11 | E1 = 1; 12 | E2 = 2; 13 | E3 = 3; 14 | E5 = 5; 15 | } 16 | 17 | message SubMessage { 18 | uint32 field1 = 1; 19 | uint32 field2 = 2; 20 | int32 field3 = 3; 21 | string field15 = 15; 22 | bytes field12 = 12; 23 | int64 field13 = 13; 24 | int64 field14 = 14; 25 | fixed64 field21 = 21; 26 | int32 field22 = 22; 27 | bool field206 = 206; 28 | fixed32 field203 = 203; 29 | int32 field204 = 204; 30 | string field205 = 205; 31 | uint64 field207 = 207; 32 | Enum field300 = 300; 33 | } 34 | 35 | message Message1 { 36 | bool field80 = 80; 37 | bool field81 = 81; 38 | int32 field2 = 2; 39 | int32 field3 = 3; 40 | int32 field280 = 280; 41 | int32 field6 = 6; 42 | int64 field22 = 22; 43 | repeated string field4 = 4; 44 | bool field59 = 59; 45 | int32 field16 = 16; 46 | int32 field150 = 150; 47 | int32 field23 = 23; 48 | bool field24 = 24; 49 | int32 field25 = 25; 50 | SubMessage field15 = 15; 51 | bool field78 = 78; 52 | int32 field67 = 67; 53 | int32 field68 = 68; 54 | int32 field128 = 128; 55 | string field129 = 129; 56 | int32 field131 = 131; 57 | } 58 | 59 | message Message2 { 60 | Enum field1 = 1; 61 | uint64 field2 = 2; 62 | sint32 field3 = 3; 63 | string field4 = 4; 64 | int32 field5 = 5; 65 | bool field6 = 6; 66 | } 67 | 68 | message Message3 { 69 | message SubMessage { 70 | int32 field28 = 28; 71 | int64 field2 = 2; 72 | int32 field12 = 12; 73 | string field19 = 19; 74 | int32 field11 = 11; 75 | } 76 | 77 | repeated SubMessage field13 = 13; 78 | } 79 | 80 | message Message { 81 | oneof oneof { 82 | Message1 message1 = 1; 83 | Message2 message2 = 2; 84 | Message3 message3 = 7; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/files/bool.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package bool; 4 | 5 | message Message { 6 | bool value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/bytes.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package bytes; 4 | 5 | message Message { 6 | bytes value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/c_source/bool.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "bool.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | void bool_message_init( 39 | struct bool_message_t *self_p, 40 | struct pbtools_heap_t *heap_p) 41 | { 42 | self_p->base.heap_p = heap_p; 43 | self_p->value = 0; 44 | } 45 | 46 | void bool_message_encode_inner( 47 | struct pbtools_encoder_t *encoder_p, 48 | struct bool_message_t *self_p) 49 | { 50 | pbtools_encoder_write_bool(encoder_p, 1, self_p->value); 51 | } 52 | 53 | void bool_message_decode_inner( 54 | struct pbtools_decoder_t *decoder_p, 55 | struct bool_message_t *self_p) 56 | { 57 | int wire_type; 58 | 59 | while (pbtools_decoder_available(decoder_p)) { 60 | switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) { 61 | 62 | case 1: 63 | self_p->value = pbtools_decoder_read_bool(decoder_p, wire_type); 64 | break; 65 | 66 | default: 67 | pbtools_decoder_skip_field(decoder_p, wire_type); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | void bool_message_encode_repeated_inner( 74 | struct pbtools_encoder_t *encoder_p, 75 | int field_number, 76 | struct bool_message_repeated_t *repeated_p) 77 | { 78 | pbtools_encode_repeated_inner( 79 | encoder_p, 80 | field_number, 81 | (struct pbtools_repeated_message_t *)repeated_p, 82 | sizeof(struct bool_message_t), 83 | (pbtools_message_encode_inner_t)bool_message_encode_inner); 84 | } 85 | 86 | void bool_message_decode_repeated_inner( 87 | struct pbtools_decoder_t *decoder_p, 88 | struct pbtools_repeated_info_t *repeated_info_p, 89 | struct bool_message_repeated_t *repeated_p) 90 | { 91 | pbtools_decode_repeated_inner( 92 | decoder_p, 93 | repeated_info_p, 94 | (struct pbtools_repeated_message_t *)repeated_p, 95 | sizeof(struct bool_message_t), 96 | (pbtools_message_init_t)bool_message_init, 97 | (pbtools_message_decode_inner_t)bool_message_decode_inner); 98 | } 99 | 100 | struct bool_message_t * 101 | bool_message_new( 102 | void *workspace_p, 103 | size_t size) 104 | { 105 | return (pbtools_message_new( 106 | workspace_p, 107 | size, 108 | sizeof(struct bool_message_t), 109 | (pbtools_message_init_t)bool_message_init)); 110 | } 111 | 112 | int bool_message_encode( 113 | struct bool_message_t *self_p, 114 | uint8_t *encoded_p, 115 | size_t size) 116 | { 117 | return (pbtools_message_encode( 118 | &self_p->base, 119 | encoded_p, 120 | size, 121 | (pbtools_message_encode_inner_t)bool_message_encode_inner)); 122 | } 123 | 124 | int bool_message_decode( 125 | struct bool_message_t *self_p, 126 | const uint8_t *encoded_p, 127 | size_t size) 128 | { 129 | return (pbtools_message_decode( 130 | &self_p->base, 131 | encoded_p, 132 | size, 133 | (pbtools_message_decode_inner_t)bool_message_decode_inner)); 134 | } 135 | -------------------------------------------------------------------------------- /tests/files/c_source/bool.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef BOOL_H 32 | #define BOOL_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message bool.Message. 42 | */ 43 | struct bool_message_repeated_t { 44 | int length; 45 | struct bool_message_t *items_p; 46 | }; 47 | 48 | struct bool_message_t { 49 | struct pbtools_message_base_t base; 50 | bool value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of bool.Message. 55 | */ 56 | struct bool_message_t * 57 | bool_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int bool_message_encode( 62 | struct bool_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int bool_message_decode( 67 | struct bool_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void bool_message_init( 74 | struct bool_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void bool_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct bool_message_t *self_p); 80 | 81 | void bool_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct bool_message_t *self_p); 84 | 85 | void bool_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct bool_message_repeated_t *repeated_p); 89 | 90 | void bool_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct bool_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/bytes.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "bytes.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | void bytes_message_init( 39 | struct bytes_message_t *self_p, 40 | struct pbtools_heap_t *heap_p) 41 | { 42 | self_p->base.heap_p = heap_p; 43 | pbtools_bytes_init(&self_p->value); 44 | } 45 | 46 | void bytes_message_encode_inner( 47 | struct pbtools_encoder_t *encoder_p, 48 | struct bytes_message_t *self_p) 49 | { 50 | pbtools_encoder_write_bytes(encoder_p, 1, &self_p->value); 51 | } 52 | 53 | void bytes_message_decode_inner( 54 | struct pbtools_decoder_t *decoder_p, 55 | struct bytes_message_t *self_p) 56 | { 57 | int wire_type; 58 | 59 | while (pbtools_decoder_available(decoder_p)) { 60 | switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) { 61 | 62 | case 1: 63 | pbtools_decoder_read_bytes(decoder_p, wire_type, &self_p->value); 64 | break; 65 | 66 | default: 67 | pbtools_decoder_skip_field(decoder_p, wire_type); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | void bytes_message_encode_repeated_inner( 74 | struct pbtools_encoder_t *encoder_p, 75 | int field_number, 76 | struct bytes_message_repeated_t *repeated_p) 77 | { 78 | pbtools_encode_repeated_inner( 79 | encoder_p, 80 | field_number, 81 | (struct pbtools_repeated_message_t *)repeated_p, 82 | sizeof(struct bytes_message_t), 83 | (pbtools_message_encode_inner_t)bytes_message_encode_inner); 84 | } 85 | 86 | void bytes_message_decode_repeated_inner( 87 | struct pbtools_decoder_t *decoder_p, 88 | struct pbtools_repeated_info_t *repeated_info_p, 89 | struct bytes_message_repeated_t *repeated_p) 90 | { 91 | pbtools_decode_repeated_inner( 92 | decoder_p, 93 | repeated_info_p, 94 | (struct pbtools_repeated_message_t *)repeated_p, 95 | sizeof(struct bytes_message_t), 96 | (pbtools_message_init_t)bytes_message_init, 97 | (pbtools_message_decode_inner_t)bytes_message_decode_inner); 98 | } 99 | 100 | struct bytes_message_t * 101 | bytes_message_new( 102 | void *workspace_p, 103 | size_t size) 104 | { 105 | return (pbtools_message_new( 106 | workspace_p, 107 | size, 108 | sizeof(struct bytes_message_t), 109 | (pbtools_message_init_t)bytes_message_init)); 110 | } 111 | 112 | int bytes_message_encode( 113 | struct bytes_message_t *self_p, 114 | uint8_t *encoded_p, 115 | size_t size) 116 | { 117 | return (pbtools_message_encode( 118 | &self_p->base, 119 | encoded_p, 120 | size, 121 | (pbtools_message_encode_inner_t)bytes_message_encode_inner)); 122 | } 123 | 124 | int bytes_message_decode( 125 | struct bytes_message_t *self_p, 126 | const uint8_t *encoded_p, 127 | size_t size) 128 | { 129 | return (pbtools_message_decode( 130 | &self_p->base, 131 | encoded_p, 132 | size, 133 | (pbtools_message_decode_inner_t)bytes_message_decode_inner)); 134 | } 135 | -------------------------------------------------------------------------------- /tests/files/c_source/bytes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef BYTES_H 32 | #define BYTES_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message bytes.Message. 42 | */ 43 | struct bytes_message_repeated_t { 44 | int length; 45 | struct bytes_message_t *items_p; 46 | }; 47 | 48 | struct bytes_message_t { 49 | struct pbtools_message_base_t base; 50 | struct pbtools_bytes_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of bytes.Message. 55 | */ 56 | struct bytes_message_t * 57 | bytes_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int bytes_message_encode( 62 | struct bytes_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int bytes_message_decode( 67 | struct bytes_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void bytes_message_init( 74 | struct bytes_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void bytes_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct bytes_message_t *self_p); 80 | 81 | void bytes_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct bytes_message_t *self_p); 84 | 85 | void bytes_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct bytes_message_repeated_t *repeated_p); 89 | 90 | void bytes_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct bytes_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/double.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "double.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | void double_message_init( 39 | struct double_message_t *self_p, 40 | struct pbtools_heap_t *heap_p) 41 | { 42 | self_p->base.heap_p = heap_p; 43 | self_p->value = 0; 44 | } 45 | 46 | void double_message_encode_inner( 47 | struct pbtools_encoder_t *encoder_p, 48 | struct double_message_t *self_p) 49 | { 50 | pbtools_encoder_write_double(encoder_p, 1, self_p->value); 51 | } 52 | 53 | void double_message_decode_inner( 54 | struct pbtools_decoder_t *decoder_p, 55 | struct double_message_t *self_p) 56 | { 57 | int wire_type; 58 | 59 | while (pbtools_decoder_available(decoder_p)) { 60 | switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) { 61 | 62 | case 1: 63 | self_p->value = pbtools_decoder_read_double(decoder_p, wire_type); 64 | break; 65 | 66 | default: 67 | pbtools_decoder_skip_field(decoder_p, wire_type); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | void double_message_encode_repeated_inner( 74 | struct pbtools_encoder_t *encoder_p, 75 | int field_number, 76 | struct double_message_repeated_t *repeated_p) 77 | { 78 | pbtools_encode_repeated_inner( 79 | encoder_p, 80 | field_number, 81 | (struct pbtools_repeated_message_t *)repeated_p, 82 | sizeof(struct double_message_t), 83 | (pbtools_message_encode_inner_t)double_message_encode_inner); 84 | } 85 | 86 | void double_message_decode_repeated_inner( 87 | struct pbtools_decoder_t *decoder_p, 88 | struct pbtools_repeated_info_t *repeated_info_p, 89 | struct double_message_repeated_t *repeated_p) 90 | { 91 | pbtools_decode_repeated_inner( 92 | decoder_p, 93 | repeated_info_p, 94 | (struct pbtools_repeated_message_t *)repeated_p, 95 | sizeof(struct double_message_t), 96 | (pbtools_message_init_t)double_message_init, 97 | (pbtools_message_decode_inner_t)double_message_decode_inner); 98 | } 99 | 100 | struct double_message_t * 101 | double_message_new( 102 | void *workspace_p, 103 | size_t size) 104 | { 105 | return (pbtools_message_new( 106 | workspace_p, 107 | size, 108 | sizeof(struct double_message_t), 109 | (pbtools_message_init_t)double_message_init)); 110 | } 111 | 112 | int double_message_encode( 113 | struct double_message_t *self_p, 114 | uint8_t *encoded_p, 115 | size_t size) 116 | { 117 | return (pbtools_message_encode( 118 | &self_p->base, 119 | encoded_p, 120 | size, 121 | (pbtools_message_encode_inner_t)double_message_encode_inner)); 122 | } 123 | 124 | int double_message_decode( 125 | struct double_message_t *self_p, 126 | const uint8_t *encoded_p, 127 | size_t size) 128 | { 129 | return (pbtools_message_decode( 130 | &self_p->base, 131 | encoded_p, 132 | size, 133 | (pbtools_message_decode_inner_t)double_message_decode_inner)); 134 | } 135 | -------------------------------------------------------------------------------- /tests/files/c_source/double.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef DOUBLE_H 32 | #define DOUBLE_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message double.Message. 42 | */ 43 | struct double_message_repeated_t { 44 | int length; 45 | struct double_message_t *items_p; 46 | }; 47 | 48 | struct double_message_t { 49 | struct pbtools_message_base_t base; 50 | double value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of double.Message. 55 | */ 56 | struct double_message_t * 57 | double_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int double_message_encode( 62 | struct double_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int double_message_decode( 67 | struct double_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void double_message_init( 74 | struct double_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void double_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct double_message_t *self_p); 80 | 81 | void double_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct double_message_t *self_p); 84 | 85 | void double_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct double_message_repeated_t *repeated_p); 89 | 90 | void double_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct double_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/enum_provider.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "enum_provider.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /tests/files/c_source/enum_provider.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef ENUM_PROVIDER_H 32 | #define ENUM_PROVIDER_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Enum pkg.Enum. 42 | */ 43 | enum pkg_enum_e { 44 | pkg_a_e = 0, 45 | pkg_b_e = 1 46 | }; 47 | 48 | 49 | /* Internal functions. Do not use! */ 50 | 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /tests/files/c_source/enum_user.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "enum_user.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | void pkg_message_init( 39 | struct pkg_message_t *self_p, 40 | struct pbtools_heap_t *heap_p) 41 | { 42 | self_p->base.heap_p = heap_p; 43 | self_p->v1 = 0; 44 | } 45 | 46 | void pkg_message_encode_inner( 47 | struct pbtools_encoder_t *encoder_p, 48 | struct pkg_message_t *self_p) 49 | { 50 | pbtools_encoder_write_enum(encoder_p, 1, self_p->v1); 51 | } 52 | 53 | void pkg_message_decode_inner( 54 | struct pbtools_decoder_t *decoder_p, 55 | struct pkg_message_t *self_p) 56 | { 57 | int wire_type; 58 | 59 | while (pbtools_decoder_available(decoder_p)) { 60 | switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) { 61 | 62 | case 1: 63 | self_p->v1 = pbtools_decoder_read_enum(decoder_p, wire_type); 64 | break; 65 | 66 | default: 67 | pbtools_decoder_skip_field(decoder_p, wire_type); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | void pkg_message_encode_repeated_inner( 74 | struct pbtools_encoder_t *encoder_p, 75 | int field_number, 76 | struct pkg_message_repeated_t *repeated_p) 77 | { 78 | pbtools_encode_repeated_inner( 79 | encoder_p, 80 | field_number, 81 | (struct pbtools_repeated_message_t *)repeated_p, 82 | sizeof(struct pkg_message_t), 83 | (pbtools_message_encode_inner_t)pkg_message_encode_inner); 84 | } 85 | 86 | void pkg_message_decode_repeated_inner( 87 | struct pbtools_decoder_t *decoder_p, 88 | struct pbtools_repeated_info_t *repeated_info_p, 89 | struct pkg_message_repeated_t *repeated_p) 90 | { 91 | pbtools_decode_repeated_inner( 92 | decoder_p, 93 | repeated_info_p, 94 | (struct pbtools_repeated_message_t *)repeated_p, 95 | sizeof(struct pkg_message_t), 96 | (pbtools_message_init_t)pkg_message_init, 97 | (pbtools_message_decode_inner_t)pkg_message_decode_inner); 98 | } 99 | 100 | struct pkg_message_t * 101 | pkg_message_new( 102 | void *workspace_p, 103 | size_t size) 104 | { 105 | return (pbtools_message_new( 106 | workspace_p, 107 | size, 108 | sizeof(struct pkg_message_t), 109 | (pbtools_message_init_t)pkg_message_init)); 110 | } 111 | 112 | int pkg_message_encode( 113 | struct pkg_message_t *self_p, 114 | uint8_t *encoded_p, 115 | size_t size) 116 | { 117 | return (pbtools_message_encode( 118 | &self_p->base, 119 | encoded_p, 120 | size, 121 | (pbtools_message_encode_inner_t)pkg_message_encode_inner)); 122 | } 123 | 124 | int pkg_message_decode( 125 | struct pkg_message_t *self_p, 126 | const uint8_t *encoded_p, 127 | size_t size) 128 | { 129 | return (pbtools_message_decode( 130 | &self_p->base, 131 | encoded_p, 132 | size, 133 | (pbtools_message_decode_inner_t)pkg_message_decode_inner)); 134 | } 135 | -------------------------------------------------------------------------------- /tests/files/c_source/enum_user.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef ENUM_USER_H 32 | #define ENUM_USER_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | #include "enum_provider.h" 40 | 41 | /** 42 | * Message pkg.Message. 43 | */ 44 | struct pkg_message_repeated_t { 45 | int length; 46 | struct pkg_message_t *items_p; 47 | }; 48 | 49 | struct pkg_message_t { 50 | struct pbtools_message_base_t base; 51 | enum pkg_enum_e v1; 52 | }; 53 | 54 | /** 55 | * Encoding and decoding of pkg.Message. 56 | */ 57 | struct pkg_message_t * 58 | pkg_message_new( 59 | void *workspace_p, 60 | size_t size); 61 | 62 | int pkg_message_encode( 63 | struct pkg_message_t *self_p, 64 | uint8_t *encoded_p, 65 | size_t size); 66 | 67 | int pkg_message_decode( 68 | struct pkg_message_t *self_p, 69 | const uint8_t *encoded_p, 70 | size_t size); 71 | 72 | /* Internal functions. Do not use! */ 73 | 74 | void pkg_message_init( 75 | struct pkg_message_t *self_p, 76 | struct pbtools_heap_t *heap_p); 77 | 78 | void pkg_message_encode_inner( 79 | struct pbtools_encoder_t *encoder_p, 80 | struct pkg_message_t *self_p); 81 | 82 | void pkg_message_decode_inner( 83 | struct pbtools_decoder_t *decoder_p, 84 | struct pkg_message_t *self_p); 85 | 86 | void pkg_message_encode_repeated_inner( 87 | struct pbtools_encoder_t *encoder_p, 88 | int field_number, 89 | struct pkg_message_repeated_t *repeated_p); 90 | 91 | void pkg_message_decode_repeated_inner( 92 | struct pbtools_decoder_t *decoder_p, 93 | struct pbtools_repeated_info_t *repeated_info_p, 94 | struct pkg_message_repeated_t *repeated_p); 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /tests/files/c_source/fixed32.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef FIXED32_H 32 | #define FIXED32_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message fixed32.Message. 42 | */ 43 | struct fixed32_message_repeated_t { 44 | int length; 45 | struct fixed32_message_t *items_p; 46 | }; 47 | 48 | struct fixed32_message_t { 49 | struct pbtools_message_base_t base; 50 | uint32_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of fixed32.Message. 55 | */ 56 | struct fixed32_message_t * 57 | fixed32_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int fixed32_message_encode( 62 | struct fixed32_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int fixed32_message_decode( 67 | struct fixed32_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void fixed32_message_init( 74 | struct fixed32_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void fixed32_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct fixed32_message_t *self_p); 80 | 81 | void fixed32_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct fixed32_message_t *self_p); 84 | 85 | void fixed32_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct fixed32_message_repeated_t *repeated_p); 89 | 90 | void fixed32_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct fixed32_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/fixed64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef FIXED64_H 32 | #define FIXED64_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message fixed64.Message. 42 | */ 43 | struct fixed64_message_repeated_t { 44 | int length; 45 | struct fixed64_message_t *items_p; 46 | }; 47 | 48 | struct fixed64_message_t { 49 | struct pbtools_message_base_t base; 50 | uint64_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of fixed64.Message. 55 | */ 56 | struct fixed64_message_t * 57 | fixed64_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int fixed64_message_encode( 62 | struct fixed64_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int fixed64_message_decode( 67 | struct fixed64_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void fixed64_message_init( 74 | struct fixed64_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void fixed64_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct fixed64_message_t *self_p); 80 | 81 | void fixed64_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct fixed64_message_t *self_p); 84 | 85 | void fixed64_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct fixed64_message_repeated_t *repeated_p); 89 | 90 | void fixed64_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct fixed64_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/float.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "float.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | void float_message_init( 39 | struct float_message_t *self_p, 40 | struct pbtools_heap_t *heap_p) 41 | { 42 | self_p->base.heap_p = heap_p; 43 | self_p->value = 0; 44 | } 45 | 46 | void float_message_encode_inner( 47 | struct pbtools_encoder_t *encoder_p, 48 | struct float_message_t *self_p) 49 | { 50 | pbtools_encoder_write_float(encoder_p, 1, self_p->value); 51 | } 52 | 53 | void float_message_decode_inner( 54 | struct pbtools_decoder_t *decoder_p, 55 | struct float_message_t *self_p) 56 | { 57 | int wire_type; 58 | 59 | while (pbtools_decoder_available(decoder_p)) { 60 | switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) { 61 | 62 | case 1: 63 | self_p->value = pbtools_decoder_read_float(decoder_p, wire_type); 64 | break; 65 | 66 | default: 67 | pbtools_decoder_skip_field(decoder_p, wire_type); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | void float_message_encode_repeated_inner( 74 | struct pbtools_encoder_t *encoder_p, 75 | int field_number, 76 | struct float_message_repeated_t *repeated_p) 77 | { 78 | pbtools_encode_repeated_inner( 79 | encoder_p, 80 | field_number, 81 | (struct pbtools_repeated_message_t *)repeated_p, 82 | sizeof(struct float_message_t), 83 | (pbtools_message_encode_inner_t)float_message_encode_inner); 84 | } 85 | 86 | void float_message_decode_repeated_inner( 87 | struct pbtools_decoder_t *decoder_p, 88 | struct pbtools_repeated_info_t *repeated_info_p, 89 | struct float_message_repeated_t *repeated_p) 90 | { 91 | pbtools_decode_repeated_inner( 92 | decoder_p, 93 | repeated_info_p, 94 | (struct pbtools_repeated_message_t *)repeated_p, 95 | sizeof(struct float_message_t), 96 | (pbtools_message_init_t)float_message_init, 97 | (pbtools_message_decode_inner_t)float_message_decode_inner); 98 | } 99 | 100 | struct float_message_t * 101 | float_message_new( 102 | void *workspace_p, 103 | size_t size) 104 | { 105 | return (pbtools_message_new( 106 | workspace_p, 107 | size, 108 | sizeof(struct float_message_t), 109 | (pbtools_message_init_t)float_message_init)); 110 | } 111 | 112 | int float_message_encode( 113 | struct float_message_t *self_p, 114 | uint8_t *encoded_p, 115 | size_t size) 116 | { 117 | return (pbtools_message_encode( 118 | &self_p->base, 119 | encoded_p, 120 | size, 121 | (pbtools_message_encode_inner_t)float_message_encode_inner)); 122 | } 123 | 124 | int float_message_decode( 125 | struct float_message_t *self_p, 126 | const uint8_t *encoded_p, 127 | size_t size) 128 | { 129 | return (pbtools_message_decode( 130 | &self_p->base, 131 | encoded_p, 132 | size, 133 | (pbtools_message_decode_inner_t)float_message_decode_inner)); 134 | } 135 | -------------------------------------------------------------------------------- /tests/files/c_source/float.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef FLOAT_H 32 | #define FLOAT_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message float.Message. 42 | */ 43 | struct float_message_repeated_t { 44 | int length; 45 | struct float_message_t *items_p; 46 | }; 47 | 48 | struct float_message_t { 49 | struct pbtools_message_base_t base; 50 | float value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of float.Message. 55 | */ 56 | struct float_message_t * 57 | float_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int float_message_encode( 62 | struct float_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int float_message_decode( 67 | struct float_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void float_message_init( 74 | struct float_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void float_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct float_message_t *self_p); 80 | 81 | void float_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct float_message_t *self_p); 84 | 85 | void float_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct float_message_repeated_t *repeated_p); 89 | 90 | void float_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct float_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/imported.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef IMPORTED_H 32 | #define IMPORTED_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | #include "imported_duplicated_package.h" 40 | 41 | /** 42 | * Enum imported.ImportedEnum. 43 | */ 44 | enum imported_imported_enum_e { 45 | imported_a_e = 0, 46 | imported_b_e = 1 47 | }; 48 | 49 | /** 50 | * Message imported.ImportedMessage. 51 | */ 52 | struct imported_imported_message_repeated_t { 53 | int length; 54 | struct imported_imported_message_t *items_p; 55 | }; 56 | 57 | struct imported_imported_message_t { 58 | struct pbtools_message_base_t base; 59 | bool v1; 60 | struct imported_imported_duplicated_package_message_t *v2_p; 61 | }; 62 | 63 | int imported_imported_message_v2_alloc( 64 | struct imported_imported_message_t *self_p); 65 | 66 | /** 67 | * Encoding and decoding of imported.ImportedMessage. 68 | */ 69 | struct imported_imported_message_t * 70 | imported_imported_message_new( 71 | void *workspace_p, 72 | size_t size); 73 | 74 | int imported_imported_message_encode( 75 | struct imported_imported_message_t *self_p, 76 | uint8_t *encoded_p, 77 | size_t size); 78 | 79 | int imported_imported_message_decode( 80 | struct imported_imported_message_t *self_p, 81 | const uint8_t *encoded_p, 82 | size_t size); 83 | 84 | /* Internal functions. Do not use! */ 85 | 86 | void imported_imported_message_init( 87 | struct imported_imported_message_t *self_p, 88 | struct pbtools_heap_t *heap_p); 89 | 90 | void imported_imported_message_encode_inner( 91 | struct pbtools_encoder_t *encoder_p, 92 | struct imported_imported_message_t *self_p); 93 | 94 | void imported_imported_message_decode_inner( 95 | struct pbtools_decoder_t *decoder_p, 96 | struct imported_imported_message_t *self_p); 97 | 98 | void imported_imported_message_encode_repeated_inner( 99 | struct pbtools_encoder_t *encoder_p, 100 | int field_number, 101 | struct imported_imported_message_repeated_t *repeated_p); 102 | 103 | void imported_imported_message_decode_repeated_inner( 104 | struct pbtools_decoder_t *decoder_p, 105 | struct pbtools_repeated_info_t *repeated_info_p, 106 | struct imported_imported_message_repeated_t *repeated_p); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /tests/files/c_source/int64.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "int64.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | void int64_message_init( 39 | struct int64_message_t *self_p, 40 | struct pbtools_heap_t *heap_p) 41 | { 42 | self_p->base.heap_p = heap_p; 43 | self_p->value = 0; 44 | } 45 | 46 | void int64_message_encode_inner( 47 | struct pbtools_encoder_t *encoder_p, 48 | struct int64_message_t *self_p) 49 | { 50 | pbtools_encoder_write_int64(encoder_p, 1, self_p->value); 51 | } 52 | 53 | void int64_message_decode_inner( 54 | struct pbtools_decoder_t *decoder_p, 55 | struct int64_message_t *self_p) 56 | { 57 | int wire_type; 58 | 59 | while (pbtools_decoder_available(decoder_p)) { 60 | switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) { 61 | 62 | case 1: 63 | self_p->value = pbtools_decoder_read_int64(decoder_p, wire_type); 64 | break; 65 | 66 | default: 67 | pbtools_decoder_skip_field(decoder_p, wire_type); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | void int64_message_encode_repeated_inner( 74 | struct pbtools_encoder_t *encoder_p, 75 | int field_number, 76 | struct int64_message_repeated_t *repeated_p) 77 | { 78 | pbtools_encode_repeated_inner( 79 | encoder_p, 80 | field_number, 81 | (struct pbtools_repeated_message_t *)repeated_p, 82 | sizeof(struct int64_message_t), 83 | (pbtools_message_encode_inner_t)int64_message_encode_inner); 84 | } 85 | 86 | void int64_message_decode_repeated_inner( 87 | struct pbtools_decoder_t *decoder_p, 88 | struct pbtools_repeated_info_t *repeated_info_p, 89 | struct int64_message_repeated_t *repeated_p) 90 | { 91 | pbtools_decode_repeated_inner( 92 | decoder_p, 93 | repeated_info_p, 94 | (struct pbtools_repeated_message_t *)repeated_p, 95 | sizeof(struct int64_message_t), 96 | (pbtools_message_init_t)int64_message_init, 97 | (pbtools_message_decode_inner_t)int64_message_decode_inner); 98 | } 99 | 100 | struct int64_message_t * 101 | int64_message_new( 102 | void *workspace_p, 103 | size_t size) 104 | { 105 | return (pbtools_message_new( 106 | workspace_p, 107 | size, 108 | sizeof(struct int64_message_t), 109 | (pbtools_message_init_t)int64_message_init)); 110 | } 111 | 112 | int int64_message_encode( 113 | struct int64_message_t *self_p, 114 | uint8_t *encoded_p, 115 | size_t size) 116 | { 117 | return (pbtools_message_encode( 118 | &self_p->base, 119 | encoded_p, 120 | size, 121 | (pbtools_message_encode_inner_t)int64_message_encode_inner)); 122 | } 123 | 124 | int int64_message_decode( 125 | struct int64_message_t *self_p, 126 | const uint8_t *encoded_p, 127 | size_t size) 128 | { 129 | return (pbtools_message_decode( 130 | &self_p->base, 131 | encoded_p, 132 | size, 133 | (pbtools_message_decode_inner_t)int64_message_decode_inner)); 134 | } 135 | -------------------------------------------------------------------------------- /tests/files/c_source/int64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef INT64_H 32 | #define INT64_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message int64.Message. 42 | */ 43 | struct int64_message_repeated_t { 44 | int length; 45 | struct int64_message_t *items_p; 46 | }; 47 | 48 | struct int64_message_t { 49 | struct pbtools_message_base_t base; 50 | int64_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of int64.Message. 55 | */ 56 | struct int64_message_t * 57 | int64_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int int64_message_encode( 62 | struct int64_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int int64_message_decode( 67 | struct int64_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void int64_message_init( 74 | struct int64_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void int64_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct int64_message_t *self_p); 80 | 81 | void int64_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct int64_message_t *self_p); 84 | 85 | void int64_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct int64_message_repeated_t *repeated_p); 89 | 90 | void int64_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct int64_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/no_package.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef NO_PACKAGE_H 32 | #define NO_PACKAGE_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Enum M0.E1. 42 | */ 43 | enum m0_e1_e { 44 | m0_b_e = 0, 45 | m0_c_e = 1 46 | }; 47 | 48 | /** 49 | * Message M0.M1. 50 | */ 51 | struct m0_m1_repeated_t { 52 | int length; 53 | struct m0_m1_t *items_p; 54 | }; 55 | 56 | struct m0_m1_t { 57 | struct pbtools_message_base_t base; 58 | enum m0_e1_e v1; 59 | }; 60 | 61 | /** 62 | * Message M0. 63 | */ 64 | struct m0_repeated_t { 65 | int length; 66 | struct m0_t *items_p; 67 | }; 68 | 69 | struct m0_t { 70 | struct pbtools_message_base_t base; 71 | struct m0_m1_t *v1_p; 72 | struct m0_m1_repeated_t v2; 73 | enum m0_e1_e v3; 74 | }; 75 | 76 | int m0_v1_alloc( 77 | struct m0_t *self_p); 78 | 79 | int m0_v2_alloc( 80 | struct m0_t *self_p, 81 | int length); 82 | 83 | /** 84 | * Encoding and decoding of M0. 85 | */ 86 | struct m0_t * 87 | m0_new( 88 | void *workspace_p, 89 | size_t size); 90 | 91 | int m0_encode( 92 | struct m0_t *self_p, 93 | uint8_t *encoded_p, 94 | size_t size); 95 | 96 | int m0_decode( 97 | struct m0_t *self_p, 98 | const uint8_t *encoded_p, 99 | size_t size); 100 | 101 | /* Internal functions. Do not use! */ 102 | 103 | void m0_init( 104 | struct m0_t *self_p, 105 | struct pbtools_heap_t *heap_p); 106 | 107 | void m0_encode_inner( 108 | struct pbtools_encoder_t *encoder_p, 109 | struct m0_t *self_p); 110 | 111 | void m0_decode_inner( 112 | struct pbtools_decoder_t *decoder_p, 113 | struct m0_t *self_p); 114 | 115 | void m0_encode_repeated_inner( 116 | struct pbtools_encoder_t *encoder_p, 117 | int field_number, 118 | struct m0_repeated_t *repeated_p); 119 | 120 | void m0_decode_repeated_inner( 121 | struct pbtools_decoder_t *decoder_p, 122 | struct pbtools_repeated_info_t *repeated_info_p, 123 | struct m0_repeated_t *repeated_p); 124 | 125 | void m0_m1_init( 126 | struct m0_m1_t *self_p, 127 | struct pbtools_heap_t *heap_p); 128 | 129 | void m0_m1_encode_inner( 130 | struct pbtools_encoder_t *encoder_p, 131 | struct m0_m1_t *self_p); 132 | 133 | void m0_m1_decode_inner( 134 | struct pbtools_decoder_t *decoder_p, 135 | struct m0_m1_t *self_p); 136 | 137 | void m0_m1_encode_repeated_inner( 138 | struct pbtools_encoder_t *encoder_p, 139 | int field_number, 140 | struct m0_m1_repeated_t *repeated_p); 141 | 142 | void m0_m1_decode_repeated_inner( 143 | struct pbtools_decoder_t *decoder_p, 144 | struct pbtools_repeated_info_t *repeated_info_p, 145 | struct m0_m1_repeated_t *repeated_p); 146 | 147 | #ifdef __cplusplus 148 | } 149 | #endif 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /tests/files/c_source/no_package_imported.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef NO_PACKAGE_IMPORTED_H 32 | #define NO_PACKAGE_IMPORTED_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message NoPackageImportedMessage. 42 | */ 43 | struct no_package_imported_message_repeated_t { 44 | int length; 45 | struct no_package_imported_message_t *items_p; 46 | }; 47 | 48 | struct no_package_imported_message_t { 49 | struct pbtools_message_base_t base; 50 | int32_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of NoPackageImportedMessage. 55 | */ 56 | struct no_package_imported_message_t * 57 | no_package_imported_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int no_package_imported_message_encode( 62 | struct no_package_imported_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int no_package_imported_message_decode( 67 | struct no_package_imported_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void no_package_imported_message_init( 74 | struct no_package_imported_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void no_package_imported_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct no_package_imported_message_t *self_p); 80 | 81 | void no_package_imported_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct no_package_imported_message_t *self_p); 84 | 85 | void no_package_imported_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct no_package_imported_message_repeated_t *repeated_p); 89 | 90 | void no_package_imported_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct no_package_imported_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/no_package_importing.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef NO_PACKAGE_IMPORTING_H 32 | #define NO_PACKAGE_IMPORTING_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | #include "no_package_imported.h" 40 | 41 | /** 42 | * Message npi.Message2. 43 | */ 44 | struct npi_message2_repeated_t { 45 | int length; 46 | struct npi_message2_t *items_p; 47 | }; 48 | 49 | struct npi_message2_t { 50 | struct pbtools_message_base_t base; 51 | struct no_package_imported_message_t *v3_p; 52 | }; 53 | 54 | int npi_message2_v3_alloc( 55 | struct npi_message2_t *self_p); 56 | 57 | /** 58 | * Encoding and decoding of npi.Message2. 59 | */ 60 | struct npi_message2_t * 61 | npi_message2_new( 62 | void *workspace_p, 63 | size_t size); 64 | 65 | int npi_message2_encode( 66 | struct npi_message2_t *self_p, 67 | uint8_t *encoded_p, 68 | size_t size); 69 | 70 | int npi_message2_decode( 71 | struct npi_message2_t *self_p, 72 | const uint8_t *encoded_p, 73 | size_t size); 74 | 75 | /* Internal functions. Do not use! */ 76 | 77 | void npi_message2_init( 78 | struct npi_message2_t *self_p, 79 | struct pbtools_heap_t *heap_p); 80 | 81 | void npi_message2_encode_inner( 82 | struct pbtools_encoder_t *encoder_p, 83 | struct npi_message2_t *self_p); 84 | 85 | void npi_message2_decode_inner( 86 | struct pbtools_decoder_t *decoder_p, 87 | struct npi_message2_t *self_p); 88 | 89 | void npi_message2_encode_repeated_inner( 90 | struct pbtools_encoder_t *encoder_p, 91 | int field_number, 92 | struct npi_message2_repeated_t *repeated_p); 93 | 94 | void npi_message2_decode_repeated_inner( 95 | struct pbtools_decoder_t *decoder_p, 96 | struct pbtools_repeated_info_t *repeated_info_p, 97 | struct npi_message2_repeated_t *repeated_p); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /tests/files/c_source/optional_fields.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef OPTIONAL_FIELDS_H 32 | #define OPTIONAL_FIELDS_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Enum optional_fields.Enum. 42 | */ 43 | enum optional_fields_enum_e { 44 | optional_fields_a_e = 0, 45 | optional_fields_b_e = 1 46 | }; 47 | 48 | /** 49 | * Message optional_fields.Message. 50 | */ 51 | struct optional_fields_message_repeated_t { 52 | int length; 53 | struct optional_fields_message_t *items_p; 54 | }; 55 | 56 | struct optional_fields_message_t { 57 | struct pbtools_message_base_t base; 58 | struct { 59 | bool is_present; 60 | int32_t value; 61 | } v1; 62 | struct { 63 | bool is_present; 64 | bool value; 65 | } v2; 66 | struct { 67 | bool is_present; 68 | char *value_p; 69 | } v3; 70 | int32_t v4; 71 | struct { 72 | bool is_present; 73 | struct pbtools_bytes_t value; 74 | } v5; 75 | struct { 76 | bool is_present; 77 | enum optional_fields_enum_e value; 78 | } v6; 79 | }; 80 | 81 | /** 82 | * Encoding and decoding of optional_fields.Message. 83 | */ 84 | struct optional_fields_message_t * 85 | optional_fields_message_new( 86 | void *workspace_p, 87 | size_t size); 88 | 89 | int optional_fields_message_encode( 90 | struct optional_fields_message_t *self_p, 91 | uint8_t *encoded_p, 92 | size_t size); 93 | 94 | int optional_fields_message_decode( 95 | struct optional_fields_message_t *self_p, 96 | const uint8_t *encoded_p, 97 | size_t size); 98 | 99 | /* Internal functions. Do not use! */ 100 | 101 | void optional_fields_message_init( 102 | struct optional_fields_message_t *self_p, 103 | struct pbtools_heap_t *heap_p); 104 | 105 | void optional_fields_message_encode_inner( 106 | struct pbtools_encoder_t *encoder_p, 107 | struct optional_fields_message_t *self_p); 108 | 109 | void optional_fields_message_decode_inner( 110 | struct pbtools_decoder_t *decoder_p, 111 | struct optional_fields_message_t *self_p); 112 | 113 | void optional_fields_message_encode_repeated_inner( 114 | struct pbtools_encoder_t *encoder_p, 115 | int field_number, 116 | struct optional_fields_message_repeated_t *repeated_p); 117 | 118 | void optional_fields_message_decode_repeated_inner( 119 | struct pbtools_decoder_t *decoder_p, 120 | struct pbtools_repeated_info_t *repeated_info_p, 121 | struct optional_fields_message_repeated_t *repeated_p); 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /tests/files/c_source/options.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef OPTIONS_H 32 | #define OPTIONS_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message options.Message. 42 | */ 43 | struct options_message_repeated_t { 44 | int length; 45 | struct options_message_t *items_p; 46 | }; 47 | 48 | struct options_message_t { 49 | struct pbtools_message_base_t base; 50 | bool value; 51 | bool value2; 52 | bool value3; 53 | }; 54 | 55 | /** 56 | * Encoding and decoding of options.Message. 57 | */ 58 | struct options_message_t * 59 | options_message_new( 60 | void *workspace_p, 61 | size_t size); 62 | 63 | int options_message_encode( 64 | struct options_message_t *self_p, 65 | uint8_t *encoded_p, 66 | size_t size); 67 | 68 | int options_message_decode( 69 | struct options_message_t *self_p, 70 | const uint8_t *encoded_p, 71 | size_t size); 72 | 73 | /* Internal functions. Do not use! */ 74 | 75 | void options_message_init( 76 | struct options_message_t *self_p, 77 | struct pbtools_heap_t *heap_p); 78 | 79 | void options_message_encode_inner( 80 | struct pbtools_encoder_t *encoder_p, 81 | struct options_message_t *self_p); 82 | 83 | void options_message_decode_inner( 84 | struct pbtools_decoder_t *decoder_p, 85 | struct options_message_t *self_p); 86 | 87 | void options_message_encode_repeated_inner( 88 | struct pbtools_encoder_t *encoder_p, 89 | int field_number, 90 | struct options_message_repeated_t *repeated_p); 91 | 92 | void options_message_decode_repeated_inner( 93 | struct pbtools_decoder_t *decoder_p, 94 | struct pbtools_repeated_info_t *repeated_info_p, 95 | struct options_message_repeated_t *repeated_p); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /tests/files/c_source/scalar_value_types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef SCALAR_VALUE_TYPES_H 32 | #define SCALAR_VALUE_TYPES_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message scalar_value_types.Message. 42 | */ 43 | struct scalar_value_types_message_repeated_t { 44 | int length; 45 | struct scalar_value_types_message_t *items_p; 46 | }; 47 | 48 | struct scalar_value_types_message_t { 49 | struct pbtools_message_base_t base; 50 | bool v1; 51 | struct pbtools_bytes_t v2; 52 | double v3; 53 | uint32_t v4; 54 | uint64_t v5; 55 | float v6; 56 | int32_t v7; 57 | int64_t v8; 58 | int32_t v9; 59 | int64_t v10; 60 | int32_t v11; 61 | int64_t v12; 62 | char *v13_p; 63 | uint32_t v14; 64 | uint64_t v15; 65 | }; 66 | 67 | /** 68 | * Encoding and decoding of scalar_value_types.Message. 69 | */ 70 | struct scalar_value_types_message_t * 71 | scalar_value_types_message_new( 72 | void *workspace_p, 73 | size_t size); 74 | 75 | int scalar_value_types_message_encode( 76 | struct scalar_value_types_message_t *self_p, 77 | uint8_t *encoded_p, 78 | size_t size); 79 | 80 | int scalar_value_types_message_decode( 81 | struct scalar_value_types_message_t *self_p, 82 | const uint8_t *encoded_p, 83 | size_t size); 84 | 85 | /* Internal functions. Do not use! */ 86 | 87 | void scalar_value_types_message_init( 88 | struct scalar_value_types_message_t *self_p, 89 | struct pbtools_heap_t *heap_p); 90 | 91 | void scalar_value_types_message_encode_inner( 92 | struct pbtools_encoder_t *encoder_p, 93 | struct scalar_value_types_message_t *self_p); 94 | 95 | void scalar_value_types_message_decode_inner( 96 | struct pbtools_decoder_t *decoder_p, 97 | struct scalar_value_types_message_t *self_p); 98 | 99 | void scalar_value_types_message_encode_repeated_inner( 100 | struct pbtools_encoder_t *encoder_p, 101 | int field_number, 102 | struct scalar_value_types_message_repeated_t *repeated_p); 103 | 104 | void scalar_value_types_message_decode_repeated_inner( 105 | struct pbtools_decoder_t *decoder_p, 106 | struct pbtools_repeated_info_t *repeated_info_p, 107 | struct scalar_value_types_message_repeated_t *repeated_p); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /tests/files/c_source/sfixed32.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef SFIXED32_H 32 | #define SFIXED32_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message sfixed32.Message. 42 | */ 43 | struct sfixed32_message_repeated_t { 44 | int length; 45 | struct sfixed32_message_t *items_p; 46 | }; 47 | 48 | struct sfixed32_message_t { 49 | struct pbtools_message_base_t base; 50 | int32_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of sfixed32.Message. 55 | */ 56 | struct sfixed32_message_t * 57 | sfixed32_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int sfixed32_message_encode( 62 | struct sfixed32_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int sfixed32_message_decode( 67 | struct sfixed32_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void sfixed32_message_init( 74 | struct sfixed32_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void sfixed32_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct sfixed32_message_t *self_p); 80 | 81 | void sfixed32_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct sfixed32_message_t *self_p); 84 | 85 | void sfixed32_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct sfixed32_message_repeated_t *repeated_p); 89 | 90 | void sfixed32_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct sfixed32_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/sfixed64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef SFIXED64_H 32 | #define SFIXED64_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message sfixed64.Message. 42 | */ 43 | struct sfixed64_message_repeated_t { 44 | int length; 45 | struct sfixed64_message_t *items_p; 46 | }; 47 | 48 | struct sfixed64_message_t { 49 | struct pbtools_message_base_t base; 50 | int64_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of sfixed64.Message. 55 | */ 56 | struct sfixed64_message_t * 57 | sfixed64_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int sfixed64_message_encode( 62 | struct sfixed64_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int sfixed64_message_decode( 67 | struct sfixed64_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void sfixed64_message_init( 74 | struct sfixed64_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void sfixed64_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct sfixed64_message_t *self_p); 80 | 81 | void sfixed64_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct sfixed64_message_t *self_p); 84 | 85 | void sfixed64_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct sfixed64_message_repeated_t *repeated_p); 89 | 90 | void sfixed64_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct sfixed64_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/sint32.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #include 32 | #include "sint32.h" 33 | 34 | #if CHAR_BIT != 8 35 | # error "Number of bits in a char must be 8." 36 | #endif 37 | 38 | void sint32_message_init( 39 | struct sint32_message_t *self_p, 40 | struct pbtools_heap_t *heap_p) 41 | { 42 | self_p->base.heap_p = heap_p; 43 | self_p->value = 0; 44 | } 45 | 46 | void sint32_message_encode_inner( 47 | struct pbtools_encoder_t *encoder_p, 48 | struct sint32_message_t *self_p) 49 | { 50 | pbtools_encoder_write_sint32(encoder_p, 1, self_p->value); 51 | } 52 | 53 | void sint32_message_decode_inner( 54 | struct pbtools_decoder_t *decoder_p, 55 | struct sint32_message_t *self_p) 56 | { 57 | int wire_type; 58 | 59 | while (pbtools_decoder_available(decoder_p)) { 60 | switch (pbtools_decoder_read_tag(decoder_p, &wire_type)) { 61 | 62 | case 1: 63 | self_p->value = pbtools_decoder_read_sint32(decoder_p, wire_type); 64 | break; 65 | 66 | default: 67 | pbtools_decoder_skip_field(decoder_p, wire_type); 68 | break; 69 | } 70 | } 71 | } 72 | 73 | void sint32_message_encode_repeated_inner( 74 | struct pbtools_encoder_t *encoder_p, 75 | int field_number, 76 | struct sint32_message_repeated_t *repeated_p) 77 | { 78 | pbtools_encode_repeated_inner( 79 | encoder_p, 80 | field_number, 81 | (struct pbtools_repeated_message_t *)repeated_p, 82 | sizeof(struct sint32_message_t), 83 | (pbtools_message_encode_inner_t)sint32_message_encode_inner); 84 | } 85 | 86 | void sint32_message_decode_repeated_inner( 87 | struct pbtools_decoder_t *decoder_p, 88 | struct pbtools_repeated_info_t *repeated_info_p, 89 | struct sint32_message_repeated_t *repeated_p) 90 | { 91 | pbtools_decode_repeated_inner( 92 | decoder_p, 93 | repeated_info_p, 94 | (struct pbtools_repeated_message_t *)repeated_p, 95 | sizeof(struct sint32_message_t), 96 | (pbtools_message_init_t)sint32_message_init, 97 | (pbtools_message_decode_inner_t)sint32_message_decode_inner); 98 | } 99 | 100 | struct sint32_message_t * 101 | sint32_message_new( 102 | void *workspace_p, 103 | size_t size) 104 | { 105 | return (pbtools_message_new( 106 | workspace_p, 107 | size, 108 | sizeof(struct sint32_message_t), 109 | (pbtools_message_init_t)sint32_message_init)); 110 | } 111 | 112 | int sint32_message_encode( 113 | struct sint32_message_t *self_p, 114 | uint8_t *encoded_p, 115 | size_t size) 116 | { 117 | return (pbtools_message_encode( 118 | &self_p->base, 119 | encoded_p, 120 | size, 121 | (pbtools_message_encode_inner_t)sint32_message_encode_inner)); 122 | } 123 | 124 | int sint32_message_decode( 125 | struct sint32_message_t *self_p, 126 | const uint8_t *encoded_p, 127 | size_t size) 128 | { 129 | return (pbtools_message_decode( 130 | &self_p->base, 131 | encoded_p, 132 | size, 133 | (pbtools_message_decode_inner_t)sint32_message_decode_inner)); 134 | } 135 | -------------------------------------------------------------------------------- /tests/files/c_source/sint32.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef SINT32_H 32 | #define SINT32_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message sint32.Message. 42 | */ 43 | struct sint32_message_repeated_t { 44 | int length; 45 | struct sint32_message_t *items_p; 46 | }; 47 | 48 | struct sint32_message_t { 49 | struct pbtools_message_base_t base; 50 | int32_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of sint32.Message. 55 | */ 56 | struct sint32_message_t * 57 | sint32_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int sint32_message_encode( 62 | struct sint32_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int sint32_message_decode( 67 | struct sint32_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void sint32_message_init( 74 | struct sint32_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void sint32_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct sint32_message_t *self_p); 80 | 81 | void sint32_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct sint32_message_t *self_p); 84 | 85 | void sint32_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct sint32_message_repeated_t *repeated_p); 89 | 90 | void sint32_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct sint32_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/sint64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef SINT64_H 32 | #define SINT64_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message sint64.Message. 42 | */ 43 | struct sint64_message_repeated_t { 44 | int length; 45 | struct sint64_message_t *items_p; 46 | }; 47 | 48 | struct sint64_message_t { 49 | struct pbtools_message_base_t base; 50 | int64_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of sint64.Message. 55 | */ 56 | struct sint64_message_t * 57 | sint64_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int sint64_message_encode( 62 | struct sint64_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int sint64_message_decode( 67 | struct sint64_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void sint64_message_init( 74 | struct sint64_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void sint64_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct sint64_message_t *self_p); 80 | 81 | void sint64_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct sint64_message_t *self_p); 84 | 85 | void sint64_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct sint64_message_repeated_t *repeated_p); 89 | 90 | void sint64_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct sint64_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef STRING_H 32 | #define STRING_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message string.Message. 42 | */ 43 | struct string_message_repeated_t { 44 | int length; 45 | struct string_message_t *items_p; 46 | }; 47 | 48 | struct string_message_t { 49 | struct pbtools_message_base_t base; 50 | char *value_p; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of string.Message. 55 | */ 56 | struct string_message_t * 57 | string_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int string_message_encode( 62 | struct string_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int string_message_decode( 67 | struct string_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void string_message_init( 74 | struct string_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void string_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct string_message_t *self_p); 80 | 81 | void string_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct string_message_t *self_p); 84 | 85 | void string_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct string_message_repeated_t *repeated_p); 89 | 90 | void string_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct string_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/uint32.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef UINT32_H 32 | #define UINT32_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message uint32.Message. 42 | */ 43 | struct uint32_message_repeated_t { 44 | int length; 45 | struct uint32_message_t *items_p; 46 | }; 47 | 48 | struct uint32_message_t { 49 | struct pbtools_message_base_t base; 50 | uint32_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of uint32.Message. 55 | */ 56 | struct uint32_message_t * 57 | uint32_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int uint32_message_encode( 62 | struct uint32_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int uint32_message_decode( 67 | struct uint32_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void uint32_message_init( 74 | struct uint32_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void uint32_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct uint32_message_t *self_p); 80 | 81 | void uint32_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct uint32_message_t *self_p); 84 | 85 | void uint32_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct uint32_message_repeated_t *repeated_p); 89 | 90 | void uint32_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct uint32_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/c_source/uint64.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * This file was generated by pbtools. 29 | */ 30 | 31 | #ifndef UINT64_H 32 | #define UINT64_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #include "pbtools.h" 39 | 40 | /** 41 | * Message uint64.Message. 42 | */ 43 | struct uint64_message_repeated_t { 44 | int length; 45 | struct uint64_message_t *items_p; 46 | }; 47 | 48 | struct uint64_message_t { 49 | struct pbtools_message_base_t base; 50 | uint64_t value; 51 | }; 52 | 53 | /** 54 | * Encoding and decoding of uint64.Message. 55 | */ 56 | struct uint64_message_t * 57 | uint64_message_new( 58 | void *workspace_p, 59 | size_t size); 60 | 61 | int uint64_message_encode( 62 | struct uint64_message_t *self_p, 63 | uint8_t *encoded_p, 64 | size_t size); 65 | 66 | int uint64_message_decode( 67 | struct uint64_message_t *self_p, 68 | const uint8_t *encoded_p, 69 | size_t size); 70 | 71 | /* Internal functions. Do not use! */ 72 | 73 | void uint64_message_init( 74 | struct uint64_message_t *self_p, 75 | struct pbtools_heap_t *heap_p); 76 | 77 | void uint64_message_encode_inner( 78 | struct pbtools_encoder_t *encoder_p, 79 | struct uint64_message_t *self_p); 80 | 81 | void uint64_message_decode_inner( 82 | struct pbtools_decoder_t *decoder_p, 83 | struct uint64_message_t *self_p); 84 | 85 | void uint64_message_encode_repeated_inner( 86 | struct pbtools_encoder_t *encoder_p, 87 | int field_number, 88 | struct uint64_message_repeated_t *repeated_p); 89 | 90 | void uint64_message_decode_repeated_inner( 91 | struct pbtools_decoder_t *decoder_p, 92 | struct pbtools_repeated_info_t *repeated_info_p, 93 | struct uint64_message_repeated_t *repeated_p); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /tests/files/comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // A comment! 4 | 5 | package comments; 6 | 7 | /* 8 | message Message { 9 | int32 value = 1; // hej 10 | } 11 | */ 12 | 13 | message Message2 { 14 | int32 value = 16; 15 | } 16 | // ffff -------------------------------------------------------------------------------- /tests/files/comments_missing_multi_line_end.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package comments_missing_multi_line_end; 4 | 5 | /* 6 | message Message { 7 | int32 value = 1; 8 | } 9 | 10 | message Message2 { 11 | int32 value = 16; 12 | } 13 | -------------------------------------------------------------------------------- /tests/files/comments_nested_multi_line.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | /* 4 | package comments_nested_multi_line; 5 | 6 | message Message { 7 | int32 value = /*1*/; 8 | } 9 | */ 10 | message Message2 { 11 | int32 value = 16; 12 | } 13 | -------------------------------------------------------------------------------- /tests/files/double.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package double; 4 | 5 | message Message { 6 | double value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/enum.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package enum; 4 | 5 | enum Enum { 6 | C = 0; 7 | D = 1; 8 | } 9 | 10 | message Message { 11 | enum Enum { 12 | A = 0; 13 | B = 1 [deprecated=true]; 14 | } 15 | 16 | Enum value = 1; 17 | } 18 | 19 | message Message2 { 20 | enum InnerEnum { 21 | E = 0; 22 | F = 1; 23 | } 24 | 25 | Enum outer = 1; 26 | InnerEnum inner = 2; 27 | } 28 | 29 | message Limits { 30 | enum Enum { 31 | G = 0; 32 | H = -2147483648; 33 | I = 2147483647; 34 | } 35 | 36 | Enum value = 1; 37 | } 38 | 39 | message AllowAlias { 40 | enum Enum { 41 | // Always allow aliases for now. 42 | A = 0; 43 | B = 1; 44 | C = 1; 45 | } 46 | 47 | Enum value = 1; 48 | } 49 | -------------------------------------------------------------------------------- /tests/files/enum_provider.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package pkg; 4 | 5 | enum Enum { 6 | A = 0; 7 | B = 1; 8 | } 9 | -------------------------------------------------------------------------------- /tests/files/enum_user.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "enum_provider.proto"; 4 | 5 | package pkg; 6 | 7 | message Message { 8 | Enum v1 = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tests/files/field_names.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package field_names; 4 | 5 | enum Enum { 6 | A = 0; 7 | B = 1; 8 | } 9 | 10 | message Message { 11 | bool MyValue = 1; 12 | }; 13 | 14 | message MessageCamelCase { 15 | int32 myInt32 = 1; 16 | int64 myInt64 = 2; 17 | sint32 mySint32 = 3; 18 | sint64 mySint64 = 4; 19 | uint32 myUint32 = 5; 20 | uint64 myUint64 = 6; 21 | fixed32 myFixed32 = 7; 22 | fixed64 myFixed64 = 8; 23 | sfixed32 mySfixed32 = 9; 24 | sfixed64 mySfixed64 = 10; 25 | float myFloat = 11; 26 | double myDouble = 12; 27 | bool myBool = 13; 28 | string myString = 14; 29 | bytes myBytes = 15; 30 | Enum myEnum = 16; 31 | Message myMessage = 17; 32 | } 33 | 34 | message MessagePascalCase { 35 | int32 MyInt32 = 1; 36 | int64 MyInt64 = 2; 37 | sint32 MySint32 = 3; 38 | sint64 MySint64 = 4; 39 | uint32 MyUint32 = 5; 40 | uint64 MyUint64 = 6; 41 | fixed32 MyFixed32 = 7; 42 | fixed64 MyFixed64 = 8; 43 | sfixed32 MySfixed32 = 9; 44 | sfixed64 MySfixed64 = 10; 45 | float MyFloat = 11; 46 | double MyDouble = 12; 47 | bool MyBool = 13; 48 | string MyString = 14; 49 | bytes MyBytes = 15; 50 | Enum MyEnum = 16; 51 | Message MyMessage = 17; 52 | } 53 | 54 | message RepeatedMessageCamelCase { 55 | repeated int32 myInt32 = 1; 56 | repeated int64 myInt64 = 2; 57 | repeated sint32 mySint32 = 3; 58 | repeated sint64 mySint64 = 4; 59 | repeated uint32 myUint32 = 5; 60 | repeated uint64 myUint64 = 6; 61 | repeated fixed32 myFixed32 = 7; 62 | repeated fixed64 myFixed64 = 8; 63 | repeated sfixed32 mySfixed32 = 9; 64 | repeated sfixed64 mySfixed64 = 10; 65 | repeated float myFloat = 11; 66 | repeated double myDouble = 12; 67 | repeated bool myBool = 13; 68 | repeated string myString = 14; 69 | repeated bytes myBytes = 15; 70 | repeated Enum myEnum = 16; 71 | repeated Message myMessage = 17; 72 | } 73 | 74 | message RepeatedMessagePascalCase { 75 | repeated int32 MyInt32 = 1; 76 | repeated int64 MyInt64 = 2; 77 | repeated sint32 MySint32 = 3; 78 | repeated sint64 MySint64 = 4; 79 | repeated uint32 MyUint32 = 5; 80 | repeated uint64 MyUint64 = 6; 81 | repeated fixed32 MyFixed32 = 7; 82 | repeated fixed64 MyFixed64 = 8; 83 | repeated sfixed32 MySfixed32 = 9; 84 | repeated sfixed64 MySfixed64 = 10; 85 | repeated float MyFloat = 11; 86 | repeated double MyDouble = 12; 87 | repeated bool MyBool = 13; 88 | repeated string MyString = 14; 89 | repeated bytes MyBytes = 15; 90 | repeated Enum MyEnum = 16; 91 | repeated Message MyMessage = 17; 92 | } 93 | 94 | message MessageOneOf { 95 | oneof OneOf { 96 | MessageCamelCase camelCaseMessage = 1; 97 | MessagePascalCase PascalCaseMessage = 2; 98 | RepeatedMessageCamelCase camelCaseMessageRepeated = 3; 99 | RepeatedMessagePascalCase PascalCaseMessageRepeated = 4; 100 | int32 myInt32 = 5; 101 | string myString = 6; 102 | bytes myBytes = 7; 103 | }; 104 | } -------------------------------------------------------------------------------- /tests/files/fixed32.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package fixed32; 4 | 5 | message Message { 6 | fixed32 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/fixed64.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package fixed64; 4 | 5 | message Message { 6 | fixed64 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/float.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package float; 4 | 5 | message Message { 6 | float value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/fuzzer.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package fuzzer; 34 | 35 | message Everything { 36 | message NestedMessage { 37 | oneof oneof_field { 38 | int32 a = 1; 39 | string b = 10000; 40 | float c = 10001; 41 | } 42 | } 43 | 44 | enum NestedEnum { 45 | ZERO = 0; 46 | FOO = 1; 47 | BAR = 2; 48 | BAZ = 3; 49 | NEG = -1; // Intentionally negative. 50 | } 51 | 52 | // Singular 53 | int32 optional_int32 = 1; 54 | int64 optional_int64 = 2; 55 | uint32 optional_uint32 = 3; 56 | uint64 optional_uint64 = 4; 57 | sint32 optional_sint32 = 5; 58 | sint64 optional_sint64 = 6; 59 | fixed32 optional_fixed32 = 7; 60 | fixed64 optional_fixed64 = 8; 61 | sfixed32 optional_sfixed32 = 9; 62 | sfixed64 optional_sfixed64 = 10; 63 | float optional_float = 11; 64 | double optional_double = 12; 65 | bool optional_bool = 13; 66 | string optional_string = 14; 67 | bytes optional_bytes = 15; 68 | NestedMessage optional_nested_message = 18; 69 | NestedEnum optional_nested_enum = 21; 70 | string optional_string_piece = 24 [ctype=STRING_PIECE]; 71 | string optional_cord = 25 [ctype=CORD]; 72 | 73 | NestedMessage optional_lazy_message = 27 [lazy=true]; 74 | 75 | // Repeated 76 | repeated int32 repeated_int32 = 3100; 77 | repeated int64 repeated_int64 = 3200; 78 | repeated uint32 repeated_uint32 = 3300; 79 | repeated uint64 repeated_uint64 = 3400; 80 | repeated sint32 repeated_sint32 = 3500; 81 | repeated sint64 repeated_sint64 = 3600; 82 | repeated fixed32 repeated_fixed32 = 3700; 83 | repeated fixed64 repeated_fixed64 = 3800; 84 | repeated sfixed32 repeated_sfixed32 = 3900; 85 | repeated sfixed64 repeated_sfixed64 = 4000; 86 | repeated float repeated_float = 4100; 87 | repeated double repeated_double = 4200; 88 | repeated bool repeated_bool = 4300; 89 | repeated string repeated_string = 4400; 90 | repeated bytes repeated_bytes = 4500; 91 | repeated NestedMessage repeated_nested_message = 48; 92 | repeated NestedEnum repeated_nested_enum = 51; 93 | 94 | repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; 95 | repeated string repeated_cord = 55 [ctype=CORD]; 96 | 97 | repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; 98 | 99 | oneof oneof_field { 100 | uint32 oneof_uint32 = 111; 101 | NestedMessage oneof_nested_message = 112; 102 | string oneof_string = 113; 103 | bytes oneof_bytes = 114; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /tests/files/imported.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "ImportedDuplicatedPackage.proto"; 4 | 5 | package imported; 6 | 7 | enum ImportedEnum { 8 | A = 0; 9 | B = 1; 10 | } 11 | 12 | message ImportedMessage { 13 | bool v1 = 1; 14 | // From same package in imported_duplicated_package.proto. No 15 | // package prefix needed. 16 | ImportedDuplicatedPackageMessage v2 = 2; 17 | } 18 | -------------------------------------------------------------------------------- /tests/files/importing.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "imported.proto"; 4 | import "ImportedDuplicatedPackage.proto"; 5 | import "imported2.proto"; 6 | 7 | package importing; 8 | 9 | message Message { 10 | imported.ImportedEnum v1 = 1; 11 | imported.ImportedMessage v2 = 2; 12 | } 13 | 14 | message Message2 { 15 | importing.Message v1 = 1; 16 | imported2.foo.bar.Imported2Message v2 = 2; 17 | } 18 | 19 | message Message3 { 20 | imported.ImportedDuplicatedPackageEnum v1 = 1; 21 | imported.ImportedDuplicatedPackageMessage v2 = 2; 22 | } 23 | -------------------------------------------------------------------------------- /tests/files/imports/ImportedDuplicatedPackage.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package imported; 4 | 5 | message Imported2Message { 6 | int32 v1 = 902; 7 | } 8 | 9 | enum ImportedDuplicatedPackageEnum { 10 | E = 0; 11 | F = 1; 12 | } 13 | 14 | message ImportedDuplicatedPackageMessage { 15 | bool v1 = 99; 16 | } 17 | -------------------------------------------------------------------------------- /tests/files/imports/imported1.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package foo.bar; 4 | 5 | message Imported2Message { 6 | int32 v1 = 10; 7 | } 8 | 9 | message Imported3Message { 10 | enum Enum { 11 | A = 0; 12 | } 13 | 14 | int32 v1 = 20; 15 | } 16 | -------------------------------------------------------------------------------- /tests/files/imports/imported2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package imported2.foo.bar; 4 | 5 | import "imported3.proto"; 6 | import "imported1.proto"; 7 | import "ImportedDuplicatedPackage.proto"; 8 | 9 | enum Imported2Enum { 10 | A = 0; 11 | B = 1; 12 | } 13 | 14 | message Imported2Message { 15 | imported.ImportedDuplicatedPackageMessage v1 = 15; 16 | } 17 | 18 | message Imported3Message { 19 | message Imported2Message { 20 | imported.ImportedDuplicatedPackageMessage v1 = 16; 21 | } 22 | 23 | imported.ImportedDuplicatedPackageMessage v1 = 17; 24 | Imported2Message v2 = 2; 25 | // All three from this file. 26 | bar.Imported2Message v3 = 3; 27 | foo.bar.Imported2Message v4 = 4; 28 | imported2.foo.bar.Imported2Message v5 = 5; 29 | imported.Imported2Message v6 = 6; 30 | // From this file. 31 | repeated bar.Imported3Message v7 = 7; 32 | repeated foo.bar.Imported3Message v9 = 9; 33 | // From imported3.proto. 34 | repeated .bar.Imported3Message v8 = 8; 35 | // From imported1.proto. 36 | repeated .foo.bar.Imported3Message v10 = 10; 37 | } 38 | -------------------------------------------------------------------------------- /tests/files/imports/imported3.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package bar; 4 | 5 | import "imported1.proto"; 6 | 7 | message Imported2Message { 8 | int32 v1 = 2; 9 | } 10 | 11 | message Imported3Message { 12 | enum Enum { 13 | A = 0; 14 | } 15 | 16 | int32 v1 = 35; 17 | } 18 | 19 | message Imported4Message { 20 | // From this file. 21 | bar.Imported3Message v1 = 100; 22 | 23 | // From imported1.proto 24 | foo.bar.Imported3Message v2 = 200; 25 | } 26 | -------------------------------------------------------------------------------- /tests/files/int32.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package int32; 4 | 5 | message Message { 6 | int32 value = 1; 7 | } 8 | 9 | message Message2 { 10 | int32 value = 16; 11 | } 12 | -------------------------------------------------------------------------------- /tests/files/int64.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package int64; 4 | 5 | message Message { 6 | int64 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/map.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package map; 4 | 5 | message Value { 6 | bool v1 = 1; 7 | } 8 | 9 | message Message { 10 | map map1 = 1; 11 | map map2 = 2; 12 | map map3 = 3; 13 | } 14 | 15 | // Same as the maps above, but in the wire format. 16 | message Message2 { 17 | message Map1 { 18 | string key = 1; 19 | bool value = 2; 20 | }; 21 | 22 | message Map2 { 23 | int32 key = 1; 24 | Value value = 2; 25 | }; 26 | 27 | message Map3 { 28 | int32 key = 1; 29 | .map.Value value = 2; 30 | }; 31 | 32 | repeated Map1 map1 = 1; 33 | repeated Map2 map2 = 2; 34 | repeated Map3 map3 = 3; 35 | } 36 | -------------------------------------------------------------------------------- /tests/files/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package message; 4 | 5 | message Foo { 6 | }; 7 | 8 | message Bar { 9 | int32 fie = 333; 10 | }; 11 | 12 | message Message { 13 | enum Foo { 14 | A = 0; 15 | B = 1; 16 | } 17 | message Fie { 18 | message Foo { 19 | bool value = 5; 20 | Bar bar = 1; 21 | } 22 | Foo foo = 1; 23 | } 24 | Foo foo = 1; 25 | Bar bar = 832; 26 | Fie fie = 4; 27 | }; 28 | 29 | message UnusedInnerTypes { 30 | enum UnusedEnum { 31 | A = 0; 32 | } 33 | message UnusedMessage { 34 | bool v1 = 1; 35 | } 36 | bool v2 = 1; 37 | }; 38 | -------------------------------------------------------------------------------- /tests/files/missing_type.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package missing_type; 4 | 5 | message Message { 6 | MissingType value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/mys_source/address_book.mys: -------------------------------------------------------------------------------- 1 | # This file was generated by pbtools. 2 | 3 | from pbtools import Decoder 4 | from pbtools import Encoder 5 | 6 | @enum(i32) 7 | class PhoneType: 8 | MOBILE = 0 9 | HOME = 1 10 | WORK = 2 11 | 12 | class PhoneNumber: 13 | number: string 14 | type: PhoneType 15 | 16 | def clear(self): 17 | self.number = "" 18 | self.type = PhoneType(0) 19 | 20 | def to_bytes(self) -> bytes: 21 | encoder = Encoder() 22 | self.to_bytes_inner(encoder) 23 | 24 | return encoder.data() 25 | 26 | def from_bytes(self, data: bytes): 27 | self.clear() 28 | self.from_bytes_inner(Decoder(data, 0, i64(len(data)))) 29 | 30 | def to_bytes_inner(self, encoder: Encoder): 31 | encoder.write_enum(2, i32(self.type)) 32 | encoder.write(1, self.number) 33 | 34 | def from_bytes_inner(self, decoder: Decoder): 35 | while decoder.available(): 36 | field_number, wire_type = decoder.read_tag() 37 | 38 | match field_number: 39 | case 1: 40 | self.number = decoder.read_string(wire_type) 41 | case 2: 42 | self.type = PhoneType(decoder.read_i32(wire_type)) 43 | case _: 44 | decoder.skip_field(wire_type) 45 | 46 | class Person: 47 | name: string 48 | id: i32 49 | email: string 50 | phones: [PhoneNumber] 51 | 52 | def clear(self): 53 | self.name = "" 54 | self.id = 0 55 | self.email = "" 56 | self.phones.clear() 57 | 58 | def to_bytes(self) -> bytes: 59 | encoder = Encoder() 60 | self.to_bytes_inner(encoder) 61 | 62 | return encoder.data() 63 | 64 | def from_bytes(self, data: bytes): 65 | self.clear() 66 | self.from_bytes_inner(Decoder(data, 0, i64(len(data)))) 67 | 68 | def to_bytes_inner(self, encoder: Encoder): 69 | for item in reversed(self.phones): 70 | pos = encoder.pos 71 | item.to_bytes_inner(encoder) 72 | encoder.write_length_delimited(4, u64(pos - encoder.pos)) 73 | 74 | encoder.write(3, self.email) 75 | encoder.write(2, self.id) 76 | encoder.write(1, self.name) 77 | 78 | def from_bytes_inner(self, decoder: Decoder): 79 | while decoder.available(): 80 | field_number, wire_type = decoder.read_tag() 81 | 82 | match field_number: 83 | case 1: 84 | self.name = decoder.read_string(wire_type) 85 | case 2: 86 | self.id = decoder.read_i32(wire_type) 87 | case 3: 88 | self.email = decoder.read_string(wire_type) 89 | case 4: 90 | item = PhoneNumber("", PhoneType.Mobile) 91 | item.from_bytes_inner( 92 | decoder.slice(i64( 93 | decoder.read_length_delimited(WireType.LengthDelimited)))) 94 | self.phones.append(item) 95 | case _: 96 | decoder.skip_field(wire_type) 97 | 98 | class AddressBook: 99 | people: [Person] 100 | 101 | def clear(self): 102 | self.people.clear() 103 | 104 | def to_bytes(self) -> bytes: 105 | encoder = Encoder() 106 | self.to_bytes_inner(encoder) 107 | 108 | return encoder.data() 109 | 110 | def from_bytes(self, data: bytes): 111 | self.clear() 112 | self.from_bytes_inner(Decoder(data, 0, i64(len(data)))) 113 | 114 | def to_bytes_inner(self, encoder: Encoder): 115 | for item in reversed(self.people): 116 | pos = encoder.pos 117 | item.to_bytes_inner(encoder) 118 | encoder.write_length_delimited(1, u64(pos - encoder.pos)) 119 | 120 | def from_bytes_inner(self, decoder: Decoder): 121 | while decoder.available(): 122 | field_number, wire_type = decoder.read_tag() 123 | 124 | match field_number: 125 | case 1: 126 | item = Person("", 0, "", []) 127 | item.from_bytes_inner( 128 | decoder.slice(i64( 129 | decoder.read_length_delimited(WireType.LengthDelimited)))) 130 | self.people.append(item) 131 | case _: 132 | decoder.skip_field(wire_type) 133 | -------------------------------------------------------------------------------- /tests/files/no_package.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message M0 { 4 | enum E1 { 5 | B = 0; 6 | C = 1; 7 | } 8 | 9 | message M1 { 10 | E1 v1 = 1; 11 | } 12 | 13 | M1 v1 = 1; 14 | repeated M1 v2 = 2; 15 | E1 v3 = 3; 16 | } 17 | -------------------------------------------------------------------------------- /tests/files/no_package_imported.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message NoPackageImportedMessage { 4 | int32 value = 1; 5 | } 6 | -------------------------------------------------------------------------------- /tests/files/no_package_importing.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "no_package_imported.proto"; 4 | 5 | package npi; 6 | 7 | message Message2 { 8 | NoPackageImportedMessage v3 = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tests/files/oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package oneof; 4 | 5 | enum Enum { 6 | A = 0; 7 | B = 1; 8 | } 9 | 10 | message Message { 11 | oneof value { 12 | int32 v1 = 1; 13 | string v2 = 2; 14 | }; 15 | } 16 | 17 | message Message2 { 18 | message Foo { 19 | int32 bar = 55; 20 | } 21 | 22 | oneof oneof1 { 23 | Foo v4 = 4; 24 | bytes v5 = 5; 25 | Enum v6 = 6; 26 | }; 27 | 28 | oneof oneof2 { 29 | bool v1 = 1; 30 | Foo v2 = 2; 31 | Message v3 = 3; 32 | }; 33 | } 34 | 35 | message Message3 { 36 | message Foo { 37 | oneof inner_oneof { 38 | bool v1 = 1; 39 | bytes v2 = 2; 40 | }; 41 | } 42 | 43 | message Bar { 44 | repeated Foo foo = 1; 45 | } 46 | 47 | oneof oneof1 { 48 | Bar v1 = 1; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /tests/files/optional_fields.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package optional_fields; 4 | 5 | enum Enum { 6 | A = 0; 7 | B = 1; 8 | } 9 | 10 | message Message { 11 | optional int32 v1 = 1; 12 | optional bool v2 = 2; 13 | optional string v3 = 3; 14 | int32 v4 = 4; 15 | optional bytes v5 = 5; 16 | optional Enum v6 = 6; 17 | } -------------------------------------------------------------------------------- /tests/files/options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package options; 4 | 5 | option foo = true; 6 | option (bar).fie = true; 7 | 8 | message Message { 9 | bool value = 1 [deprecated=true]; 10 | bool value2 = 2 [(bar).fum = 5]; 11 | bool value3 = 3 [(bar).gam = 1, deprecated=true]; 12 | } 13 | -------------------------------------------------------------------------------- /tests/files/ordering.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package ordering; 4 | 5 | message Foo { 6 | Bar bar = 1; 7 | Fam fam = 2; 8 | } 9 | 10 | message Bar { 11 | bool value = 1; 12 | Fie fie = 2; 13 | Fum fum = 3; 14 | Gom gom = 4; 15 | 16 | message Gom { 17 | Fie v1 = 1; 18 | } 19 | 20 | message Fie { 21 | bool v1 = 1; 22 | Fam v2 = 2; 23 | } 24 | 25 | enum Fum { 26 | A = 0; 27 | } 28 | 29 | } 30 | 31 | enum Fam { 32 | A = 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/files/public_imported.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import public "imported.proto"; 4 | -------------------------------------------------------------------------------- /tests/files/public_importing.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "public_imported.proto"; 4 | 5 | package public_importing; 6 | 7 | // ToDo: Support for using public imports. 8 | // message Message { 9 | // imported.ImportedEnum v1 = 1; 10 | // imported.ImportedMessage v2 = 2; 11 | // } 12 | -------------------------------------------------------------------------------- /tests/files/repeated.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package repeated; 4 | 5 | enum Enum { 6 | A = 0; 7 | B = 1; 8 | } 9 | 10 | message Message { 11 | // Packed by default. 12 | repeated int32 int32s = 1; 13 | 14 | // Can not be packed. 15 | repeated Message messages = 2; 16 | 17 | repeated string strings = 3; 18 | repeated bytes bytes = 4; 19 | } 20 | 21 | message MessageScalarValueTypes { 22 | repeated int32 int32s = 1; 23 | repeated int64 int64s = 2; 24 | repeated sint32 sint32s = 3; 25 | repeated sint64 sint64s = 4; 26 | repeated uint32 uint32s = 5; 27 | repeated uint64 uint64s = 6; 28 | repeated fixed32 fixed32s = 7; 29 | repeated fixed64 fixed64s = 8; 30 | repeated sfixed32 sfixed32s = 9; 31 | repeated sfixed64 sfixed64s = 10; 32 | repeated float floats = 11; 33 | repeated double doubles = 12; 34 | repeated bool bools = 13; 35 | repeated string strings = 14; 36 | repeated bytes bytess = 15; 37 | } 38 | 39 | message MessageScalarValueTypesPacked { 40 | repeated int32 int32s = 1 [packed=true]; 41 | repeated int64 int64s = 2 [packed=true]; 42 | repeated sint32 sint32s = 3 [packed=true]; 43 | repeated sint64 sint64s = 4 [packed=true]; 44 | repeated uint32 uint32s = 5 [packed=true]; 45 | repeated uint64 uint64s = 6 [packed=true]; 46 | repeated fixed32 fixed32s = 7 [packed=true]; 47 | repeated fixed64 fixed64s = 8 [packed=true]; 48 | repeated sfixed32 sfixed32s = 9 [packed=true]; 49 | repeated sfixed64 sfixed64s = 10 [packed=true]; 50 | repeated float floats = 11 [packed=true]; 51 | repeated double doubles = 12 [packed=true]; 52 | repeated bool bools = 13 [packed=true]; 53 | repeated string strings = 14; 54 | repeated bytes bytess = 15; 55 | } 56 | 57 | message MessageScalarValueTypesNotPacked { 58 | repeated int32 int32s = 1 [packed=false]; 59 | repeated int64 int64s = 2 [packed=false]; 60 | repeated sint32 sint32s = 3 [packed=false]; 61 | repeated sint64 sint64s = 4 [packed=false]; 62 | repeated uint32 uint32s = 5 [packed=false]; 63 | repeated uint64 uint64s = 6 [packed=false]; 64 | repeated fixed32 fixed32s = 7 [packed=false]; 65 | repeated fixed64 fixed64s = 8 [packed=false]; 66 | repeated sfixed32 sfixed32s = 9 [packed=false]; 67 | repeated sfixed64 sfixed64s = 10 [packed=false]; 68 | repeated float floats = 11 [packed=false]; 69 | repeated double doubles = 12 [packed=false]; 70 | repeated bool bools = 13 [packed=false]; 71 | repeated string strings = 14; 72 | repeated bytes bytess = 15; 73 | } 74 | 75 | message Foo { 76 | repeated Message messages = 1; 77 | repeated Enum enums = 2; 78 | } 79 | 80 | message Bar { 81 | message Fie { 82 | repeated Foo inner_foos = 1; 83 | } 84 | 85 | repeated Foo foos = 1; 86 | repeated Fie fies = 2; 87 | } 88 | -------------------------------------------------------------------------------- /tests/files/reserved.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package reserved; 4 | 5 | message Message { 6 | int32 f1 = 1; 7 | reserved 2; 8 | bool f3 = 3; 9 | reserved 5, 8 to 10; 10 | int32 f11 = 11; 11 | reserved "f12", "f13"; 12 | bool f15 = 15; 13 | } 14 | -------------------------------------------------------------------------------- /tests/files/scalar_value_types.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package scalar_value_types; 4 | 5 | message Message { 6 | bool v1 = 1; 7 | bytes v2 = 2; 8 | double v3 = 3; 9 | fixed32 v4 = 4; 10 | fixed64 v5 = 5; 11 | float v6 = 6; 12 | int32 v7 = 7; 13 | int64 v8 = 8; 14 | sfixed32 v9 = 9; 15 | sfixed64 v10 = 10; 16 | sint32 v11 = 11; 17 | sint64 v12 = 12; 18 | string v13 = 13; 19 | uint32 v14 = 14; 20 | uint64 v15 = 15; 21 | } -------------------------------------------------------------------------------- /tests/files/service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package service; 4 | 5 | message Request { 6 | string value = 1; 7 | } 8 | 9 | message Response { 10 | string value = 1; 11 | } 12 | 13 | service MyService { 14 | rpc Foo (Request) returns (Response); 15 | rpc Bar (Request) returns (Response); 16 | rpc Fie (Request) returns (Response) {} 17 | rpc Fum (Request) returns (Response) {}; 18 | rpc Fam (stream Request) returns (stream Response) {}; 19 | rpc Fem (Request) returns (Response) { 20 | option foo = BAR; 21 | option bar = FIE; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /tests/files/sfixed32.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package sfixed32; 4 | 5 | message Message { 6 | sfixed32 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/sfixed64.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package sfixed64; 4 | 5 | message Message { 6 | sfixed64 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/sint32.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package sint32; 4 | 5 | message Message { 6 | sint32 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/sint64.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package sint64; 4 | 5 | message Message { 6 | sint64 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/string.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package string; 4 | 5 | message Message { 6 | string value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/tags.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tags; 4 | 5 | message Message1 { 6 | // 0801 7 | bool value = 1; 8 | } 9 | 10 | message Message2 { 11 | // 7801 12 | bool value = 15; 13 | } 14 | 15 | message Message3 { 16 | // 8001 01 17 | bool value = 16; 18 | } 19 | 20 | message Message4 { 21 | // f87f 01 22 | bool value = 2047; 23 | } 24 | 25 | message Message5 { 26 | // 8080 0101 27 | bool value = 2048; 28 | } 29 | 30 | message Message6 { 31 | // f8ff ffff 0f01 32 | bool value = 536870911; 33 | } 34 | -------------------------------------------------------------------------------- /tests/files/uint32.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package uint32; 4 | 5 | message Message { 6 | uint32 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/files/uint64.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package uint64; 4 | 5 | message Message { 6 | uint64 value = 1; 7 | } 8 | -------------------------------------------------------------------------------- /tests/main_fuzzer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018-2019 Erik Moqvist 5 | * 6 | * Permission is hereby granted, free of charge, to any person 7 | * obtaining a copy of this software and associated documentation 8 | * files (the "Software"), to deal in the Software without 9 | * restriction, including without limitation the rights to use, copy, 10 | * modify, merge, publish, distribute, sublicense, and/or sell copies 11 | * of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "files/c_source/fuzzer.h" 34 | 35 | static void assert_res(ssize_t res) 36 | { 37 | if (res < 0) { 38 | printf("First encode failed with %ld.\n", res); 39 | __builtin_trap(); 40 | } 41 | } 42 | 43 | static void test(const uint8_t *encoded_p, size_t size) 44 | { 45 | ssize_t res; 46 | ssize_t i; 47 | uint8_t encoded[4096]; 48 | uint8_t workspace[4096]; 49 | struct fuzzer_everything_t *decoded_p; 50 | 51 | decoded_p = fuzzer_everything_new(&workspace[0], sizeof(workspace)); 52 | 53 | if (decoded_p == NULL) { 54 | return; 55 | } 56 | 57 | res = fuzzer_everything_decode(decoded_p, encoded_p, size); 58 | 59 | if (res >= 0) { 60 | res = fuzzer_everything_encode(decoded_p, &encoded[0], sizeof(encoded)); 61 | assert_res(res); 62 | } 63 | } 64 | 65 | int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size) 66 | { 67 | test(data_p, size); 68 | 69 | return (0); 70 | } 71 | -------------------------------------------------------------------------------- /tests/test_c_source.py: -------------------------------------------------------------------------------- 1 | import os 2 | import unittest 3 | 4 | import pbtools.c_source 5 | 6 | from .utils import read_file 7 | from .utils import remove_directory 8 | from .utils import remove_files 9 | 10 | 11 | class CommandLineTest(unittest.TestCase): 12 | 13 | maxDiff = None 14 | 15 | def assert_files_equal(self, actual, expected): 16 | # open(expected, 'w').write(open(actual, 'r').read()) 17 | self.assertEqual(read_file(actual), read_file(expected)) 18 | 19 | def test_generate_files(self): 20 | spec = 'address_book' 21 | proto = f'tests/files/{spec}.proto' 22 | filename_h = f'{spec}.h' 23 | filename_c = f'{spec}.c' 24 | 25 | remove_files([filename_h, filename_c]) 26 | 27 | pbtools.c_source.generate_files([proto]) 28 | 29 | for filename in [filename_h, filename_c]: 30 | self.assert_files_equal(filename, 31 | f'tests/files/c_source/{filename}') 32 | 33 | 34 | if __name__ == '__main__': 35 | unittest.main() 36 | -------------------------------------------------------------------------------- /tests/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | 5 | def read_file(filename): 6 | with open(filename, 'r') as fin: 7 | return fin.read() 8 | 9 | 10 | def remove_directory(name): 11 | if os.path.exists(name): 12 | shutil.rmtree(name) 13 | 14 | 15 | def remove_files(filenames): 16 | for filename in filenames: 17 | if os.path.exists(filename): 18 | os.remove(filename) 19 | --------------------------------------------------------------------------------