├── .gitignore ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── README_PYPI.md ├── external └── nanopb-master │ ├── .gitignore │ ├── .travis.yml │ ├── AUTHORS.txt │ ├── BUILD │ ├── CHANGELOG.txt │ ├── CMakeLists.txt │ ├── CONTRIBUTING.md │ ├── LICENSE.txt │ ├── README.md │ ├── WORKSPACE │ ├── docs │ ├── Makefile │ ├── concepts.rst │ ├── generator_flow.svg │ ├── index.rst │ ├── logo │ │ ├── logo.png │ │ ├── logo.svg │ │ ├── logo16px.png │ │ └── logo48px.png │ ├── lsr.css │ ├── menu.rst │ ├── migration.rst │ ├── reference.rst │ └── security.rst │ ├── examples │ ├── cmake_relpath │ │ ├── CMakeLists.txt │ │ ├── README.txt │ │ ├── proto │ │ │ ├── simple.proto │ │ │ └── sub │ │ │ │ └── unlucky.proto │ │ └── simple.c │ ├── cmake_simple │ │ ├── CMakeLists.txt │ │ ├── README.txt │ │ ├── simple.c │ │ └── simple.proto │ ├── network_server │ │ ├── Makefile │ │ ├── README.txt │ │ ├── client.c │ │ ├── common.c │ │ ├── common.h │ │ ├── fileproto.options │ │ ├── fileproto.proto │ │ └── server.c │ ├── simple │ │ ├── Makefile │ │ ├── README.txt │ │ ├── simple.c │ │ └── simple.proto │ ├── using_double_on_avr │ │ ├── Makefile │ │ ├── README.txt │ │ ├── decode_double.c │ │ ├── double_conversion.c │ │ ├── double_conversion.h │ │ ├── doubleproto.proto │ │ ├── encode_double.c │ │ └── test_conversions.c │ └── using_union_messages │ │ ├── Makefile │ │ ├── README.txt │ │ ├── decode.c │ │ ├── encode.c │ │ └── unionproto.proto │ ├── extra │ ├── FindNanopb.cmake │ ├── nanopb-config-version.cmake.in │ ├── nanopb-config.cmake │ ├── nanopb.mk │ └── pb_syshdr.h │ ├── generator │ ├── nanopb │ │ └── options.proto │ ├── nanopb_generator.py │ ├── proto │ │ ├── Makefile │ │ ├── __init__.py │ │ ├── google │ │ │ └── protobuf │ │ │ │ └── descriptor.proto │ │ ├── nanopb.proto │ │ └── plugin.proto │ ├── protoc-gen-nanopb │ └── protoc-gen-nanopb.bat │ ├── library.json │ ├── pb.h │ ├── pb_common.c │ ├── pb_common.h │ ├── pb_decode.c │ ├── pb_decode.h │ ├── pb_encode.c │ ├── pb_encode.h │ ├── tests │ ├── Makefile │ ├── SConstruct │ ├── alltypes │ │ ├── SConscript │ │ ├── alltypes.options │ │ ├── alltypes.proto │ │ ├── decode_alltypes.c │ │ └── encode_alltypes.c │ ├── alltypes_callback │ │ ├── SConscript │ │ ├── alltypes.options │ │ ├── decode_alltypes_callback.c │ │ └── encode_alltypes_callback.c │ ├── alltypes_pointer │ │ ├── SConscript │ │ ├── alltypes.options │ │ ├── decode_alltypes_pointer.c │ │ └── encode_alltypes_pointer.c │ ├── alltypes_proto3 │ │ ├── SConscript │ │ ├── alltypes.options │ │ ├── alltypes.proto │ │ ├── decode_alltypes.c │ │ └── encode_alltypes.c │ ├── alltypes_proto3_callback │ │ ├── SConscript │ │ ├── alltypes.options │ │ ├── decode_alltypes_callback.c │ │ └── encode_alltypes_callback.c │ ├── anonymous_oneof │ │ ├── SConscript │ │ ├── decode_oneof.c │ │ └── oneof.proto │ ├── backwards_compatibility │ │ ├── SConscript │ │ ├── alltypes_legacy.c │ │ ├── alltypes_legacy.h │ │ ├── alltypes_legacy.options │ │ ├── alltypes_legacy.proto │ │ ├── decode_legacy.c │ │ └── encode_legacy.c │ ├── basic_buffer │ │ ├── SConscript │ │ ├── decode_buffer.c │ │ └── encode_buffer.c │ ├── basic_stream │ │ ├── SConscript │ │ ├── decode_stream.c │ │ └── encode_stream.c │ ├── buffer_only │ │ └── SConscript │ ├── callbacks │ │ ├── SConscript │ │ ├── callbacks.proto │ │ ├── decode_callbacks.c │ │ └── encode_callbacks.c │ ├── common │ │ ├── SConscript │ │ ├── malloc_wrappers.c │ │ ├── malloc_wrappers.h │ │ ├── malloc_wrappers_syshdr.h │ │ ├── person.proto │ │ ├── test_helpers.h │ │ ├── unittestproto.proto │ │ └── unittests.h │ ├── cxx_main_program │ │ └── SConscript │ ├── cyclic_messages │ │ ├── SConscript │ │ ├── cyclic.proto │ │ ├── cyclic_callback.options │ │ └── encode_cyclic_callback.c │ ├── decode_unittests │ │ ├── SConscript │ │ └── decode_unittests.c │ ├── encode_unittests │ │ ├── SConscript │ │ └── encode_unittests.c │ ├── enum_sizes │ │ ├── SConscript │ │ ├── enumsizes.proto │ │ └── enumsizes_unittests.c │ ├── enum_to_string │ │ ├── SConscript │ │ ├── enum.proto │ │ └── enum_to_string.c │ ├── extensions │ │ ├── SConscript │ │ ├── decode_extensions.c │ │ ├── encode_extensions.c │ │ ├── extensions.options │ │ └── extensions.proto │ ├── extra_fields │ │ ├── SConscript │ │ └── person_with_extra_field.expected │ ├── field_size_16 │ │ ├── SConscript │ │ ├── alltypes.options │ │ └── alltypes.proto │ ├── field_size_16_proto3 │ │ ├── SConscript │ │ ├── alltypes.options │ │ ├── alltypes.proto │ │ ├── decode_alltypes.c │ │ └── encode_alltypes.c │ ├── field_size_32 │ │ ├── SConscript │ │ ├── alltypes.options │ │ └── alltypes.proto │ ├── fixed_count │ │ ├── SConscript │ │ ├── fixed_count.proto │ │ └── fixed_count_unittests.c │ ├── fuzztest │ │ ├── SConscript │ │ ├── alltypes_pointer.options │ │ ├── alltypes_static.options │ │ ├── fuzzstub.c │ │ ├── fuzztest.c │ │ ├── generate_message.c │ │ └── run_radamsa.sh │ ├── inline │ │ ├── SConscript │ │ ├── inline.expected │ │ ├── inline.proto │ │ └── inline_unittests.c │ ├── intsizes │ │ ├── SConscript │ │ ├── intsizes.proto │ │ └── intsizes_unittests.c │ ├── io_errors │ │ ├── SConscript │ │ ├── alltypes.options │ │ └── io_errors.c │ ├── io_errors_pointers │ │ ├── SConscript │ │ └── alltypes.options │ ├── map │ │ ├── SConscript │ │ ├── decode_map.c │ │ ├── encode_map.c │ │ ├── map.options │ │ └── map.proto │ ├── mem_release │ │ ├── SConscript │ │ ├── mem_release.c │ │ └── mem_release.proto │ ├── message_sizes │ │ ├── SConscript │ │ ├── dummy.c │ │ ├── messages1.proto │ │ └── messages2.proto │ ├── missing_fields │ │ ├── SConscript │ │ ├── missing_fields.c │ │ └── missing_fields.proto │ ├── multiple_files │ │ ├── SConscript │ │ ├── multifile1.options │ │ ├── multifile1.proto │ │ ├── multifile2.proto │ │ ├── subdir │ │ │ └── multifile2.proto │ │ └── test_multiple_files.c │ ├── no_errmsg │ │ └── SConscript │ ├── no_messages │ │ ├── SConscript │ │ └── no_messages.proto │ ├── oneof │ │ ├── SConscript │ │ ├── decode_oneof.c │ │ ├── encode_oneof.c │ │ └── oneof.proto │ ├── options │ │ ├── SConscript │ │ ├── options.expected │ │ ├── options.proto │ │ ├── proto3_options.expected │ │ └── proto3_options.proto │ ├── package_name │ │ └── SConscript │ ├── regression │ │ ├── issue_118 │ │ │ ├── SConscript │ │ │ ├── enumdef.proto │ │ │ └── enumuse.proto │ │ ├── issue_125 │ │ │ ├── SConscript │ │ │ ├── extensionbug.expected │ │ │ ├── extensionbug.options │ │ │ └── extensionbug.proto │ │ ├── issue_141 │ │ │ ├── SConscript │ │ │ ├── testproto.expected │ │ │ └── testproto.proto │ │ ├── issue_145 │ │ │ ├── SConscript │ │ │ ├── comments.expected │ │ │ ├── comments.options │ │ │ └── comments.proto │ │ ├── issue_166 │ │ │ ├── SConscript │ │ │ ├── enum_encoded_size.c │ │ │ └── enums.proto │ │ ├── issue_172 │ │ │ ├── SConscript │ │ │ ├── msg_size.c │ │ │ ├── submessage │ │ │ │ ├── submessage.options │ │ │ │ └── submessage.proto │ │ │ └── test.proto │ │ ├── issue_188 │ │ │ ├── SConscript │ │ │ └── oneof.proto │ │ ├── issue_195 │ │ │ ├── SConscript │ │ │ ├── test.expected │ │ │ └── test.proto │ │ ├── issue_203 │ │ │ ├── SConscript │ │ │ ├── file1.proto │ │ │ └── file2.proto │ │ ├── issue_205 │ │ │ ├── SConscript │ │ │ ├── size_corruption.c │ │ │ └── size_corruption.proto │ │ ├── issue_227 │ │ │ ├── SConscript │ │ │ ├── unaligned_uint64.c │ │ │ └── unaligned_uint64.proto │ │ ├── issue_229 │ │ │ ├── SConscript │ │ │ ├── multiple_oneof.c │ │ │ └── multiple_oneof.proto │ │ ├── issue_242 │ │ │ ├── SConscript │ │ │ ├── zero_value.c │ │ │ └── zero_value.proto │ │ ├── issue_247 │ │ │ ├── SConscript │ │ │ ├── padding.c │ │ │ └── padding.proto │ │ ├── issue_249 │ │ │ ├── SConscript │ │ │ ├── test.c │ │ │ └── test.proto │ │ ├── issue_253 │ │ │ ├── SConscript │ │ │ ├── short_array.c │ │ │ └── short_array.proto │ │ ├── issue_256 │ │ │ ├── SConscript │ │ │ ├── submsg_array.c │ │ │ └── submsg_array.proto │ │ ├── issue_259 │ │ │ ├── SConscript │ │ │ ├── callback_pointer.c │ │ │ └── callback_pointer.proto │ │ ├── issue_306 │ │ │ ├── SConscript │ │ │ ├── large_extension.expected │ │ │ └── large_extension.proto │ │ ├── issue_322 │ │ │ ├── SConscript │ │ │ ├── defaults.c │ │ │ └── defaults.proto │ │ ├── issue_338 │ │ │ ├── SConscript │ │ │ └── bigvalue.proto │ │ └── issue_342 │ │ │ ├── SConscript │ │ │ ├── extensions.proto │ │ │ └── test_extensions.c │ ├── site_scons │ │ ├── site_init.py │ │ └── site_tools │ │ │ └── nanopb.py │ ├── special_characters │ │ ├── SConscript │ │ └── funny-proto+name has.characters.proto │ ├── splint │ │ ├── SConscript │ │ └── splint.rc │ ├── typename_mangling │ │ ├── SConscript │ │ ├── test_flatten.c │ │ ├── test_strip_package.c │ │ ├── with_package.options │ │ └── with_package.proto │ └── without_64bit │ │ ├── SConscript │ │ ├── alltypes.options │ │ ├── alltypes.proto │ │ ├── decode_alltypes.c │ │ ├── encode_alltypes.c │ │ └── no_64bit_syshdr.h │ └── tools │ ├── make_linux_package.sh │ ├── make_mac_package.sh │ ├── make_windows_package.sh │ └── set_version.sh ├── proto ├── zr.options └── zr.proto ├── setup.py └── zrna ├── __init__.py ├── __version__.py ├── api.py ├── update_firmware.py ├── util.py └── zr_pb2.py /.gitignore: -------------------------------------------------------------------------------- 1 | proto/python 2 | proto/cpp 3 | proto/java 4 | proto/js 5 | proto/golang 6 | proto/nanopb 7 | 8 | # Byte-compiled / optimized / DLL files 9 | __pycache__/ 10 | *.py[cod] 11 | *$py.class 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | env/ 19 | build/ 20 | develop-eggs/ 21 | dist/ 22 | downloads/ 23 | eggs/ 24 | .eggs/ 25 | lib/ 26 | lib64/ 27 | parts/ 28 | sdist/ 29 | var/ 30 | *.egg-info/ 31 | .installed.cfg 32 | *.egg 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *,cover 53 | .hypothesis/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | 63 | # Flask stuff: 64 | instance/ 65 | .webassets-cache 66 | 67 | # Scrapy stuff: 68 | .scrapy 69 | 70 | # Sphinx documentation 71 | docs/_build/ 72 | 73 | # PyBuilder 74 | target/ 75 | 76 | # IPython Notebook 77 | .ipynb_checkpoints 78 | 79 | # pyenv 80 | .python-version 81 | 82 | # celery beat schedule file 83 | celerybeat-schedule 84 | 85 | # dotenv 86 | .env 87 | 88 | # virtualenv 89 | venv/ 90 | ENV/ 91 | 92 | # Spyder project settings 93 | .spyderproject 94 | 95 | # Rope project settings 96 | .ropeproject 97 | *.npy 98 | *.pkl -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md LICENSE -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROTOC = protoc 2 | NANOPB_DIR := external/nanopb-master 3 | PB_DEF_DIR := proto 4 | PYTHON_API_CLIENT_DIR := zrna 5 | 6 | PROTOC_OPTS = --plugin=protoc-gen-nanopb=$(NANOPB_DIR)/generator/protoc-gen-nanopb 7 | PROTO_SOURCES := $(shell find $(PB_DEF_DIR) -type f -name *.proto) 8 | 9 | PROTO_PYTHON_OUT = proto/python 10 | PROTO_CPP_OUT = proto/cpp 11 | PROTO_JAVA_OUT = proto/java 12 | PROTO_JS_OUT = proto/js 13 | PROTO_GOLANG_OUT = proto/golang 14 | PROTO_NANOPB_OUT = proto/nanopb 15 | PROTO_OUTPUT_DIRS = $(PROTO_PYTHON_OUT) $(PROTO_CPP_OUT) $(PROTO_JAVA_OUT) \ 16 | $(PROTO_JS_OUT) $(PROTO_GOLANG_OUT) $(PROTO_NANOPB_OUT) 17 | 18 | all: $(PB_DEF_DIR)/zr.proto | output_directories 19 | $(PROTOC) -I$(PB_DEF_DIR) $(PROTOC_OPTS) '--nanopb_out=-I$(PB_DEF_DIR) -v:$(PROTO_NANOPB_OUT)' \ 20 | --python_out=$(PROTO_PYTHON_OUT) \ 21 | --cpp_out=$(PROTO_CPP_OUT) \ 22 | --java_out=$(PROTO_JAVA_OUT) \ 23 | --js_out=$(PROTO_JS_OUT) \ 24 | --go_out=$(PROTO_GOLANG_OUT) $< 25 | sed -i -E 's/^import.*_pb2/from . \0/' $(PROTO_PYTHON_OUT)/*.py 26 | cp $(PROTO_PYTHON_OUT)/zr_pb2.py $(PYTHON_API_CLIENT_DIR) 27 | 28 | output_directories: 29 | for output_directory in $(PROTO_OUTPUT_DIRS) ; do \ 30 | mkdir -p $$output_directory ; \ 31 | done 32 | 33 | clean: 34 | for output_directory in $(PROTO_OUTPUT_DIRS) ; do \ 35 | rm -f ./$$output_directory/* ; \ 36 | done 37 | 38 | .PHONY: clean 39 | .PHONY: all 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zrna - software-defined analog 2 | Protobuf definition and API clients for the Zrna software-defined analog platform. 3 | 4 | See [zrna.org/docs](https://zrna.org/docs) for the full documentation. 5 | 6 | Order [hardware](https://zrna.org/shop). 7 | 8 | ## The Protobuf Spec 9 | The `proto` directory contains the protobuf definition and also serves 10 | as the root output directory for generated sources. Issuing `make` from 11 | the root directory will compile everything and generate code with the `protoc` 12 | compiler. The assumption is that `protoc` is available on your `PATH` and also 13 | that Golang source generation is available (this requires setup beyond the default 14 | `protoc` installation. See [https://github.com/golang/protobuf](https://github.com/golang/protobuf). 15 | If you are interested in particular languages, simply disable the ones you don't need in the 16 | `Makefile`. 17 | 18 | By default, the build process generates bindings for Python, C++, Java, JavaScript, Golang 19 | and plain C via Nanopb. The generated sources for each of these end up in the following 20 | directories: 21 | ``` 22 | proto/python 23 | proto/cpp 24 | proto/java 25 | proto/js 26 | proto/golang 27 | proto/nanopb 28 | ``` 29 | Zrna hardware uses the nanopb binding natively which is usually the best choice for constrained embedded 30 | environments. As is normally the case with protobuf though, 31 | a common binary wire format is generated regardless of what language binding is used, i.e. your 32 | client is free to use any of the language bindings. If this is your first time working with protobuf, it's worth it to review the docs: [https://developers.google.com/protocol-buffers/](https://developers.google.com/protocol-buffers/). 33 | 34 | ## The Python Client 35 | The `zrna` directory contains the sources for the Python API client that is available on PyPI as `zrna`. It's built on the Python bindings generated in the previous step. See the [quickstart guide](https://zrna.org/docs/quickstart) for more information about how to use it. See the [demo applications](https://zrna.org/demos) for usage examples. 36 | -------------------------------------------------------------------------------- /README_PYPI.md: -------------------------------------------------------------------------------- 1 | # zrna - software-defined analog 2 | API client for the Zrna software-defined analog platform. 3 | 4 | See the [quickstart guide](https://zrna.org/docs/quickstart) for more information about how to use it. 5 | 6 | See the [demo applications](https://zrna.org/demos) for example usage. 7 | 8 | See [zrna.org/docs](https://zrna.org/docs) for the full documentation. 9 | 10 | Order [hardware](https://zrna.org/shop). 11 | 12 | Browse the [source code](https://github.com/zrna-research/zrna-api). 13 | -------------------------------------------------------------------------------- /external/nanopb-master/.gitignore: -------------------------------------------------------------------------------- 1 | *.gcda 2 | *.gcno 3 | *.gcov 4 | *.o 5 | *.pb.c 6 | *.pb.h 7 | *.pb 8 | *.pyc 9 | *_pb2.py 10 | *~ 11 | *.tar.gz 12 | .sconsign.dblite 13 | config.log 14 | .sconf_temp 15 | tests/build 16 | julkaisu.txt 17 | dist 18 | docs/*.html 19 | docs/generator_flow.png 20 | examples/simple/simple 21 | examples/network_server/client 22 | examples/network_server/server 23 | examples/using_double_on_avr/decode_double 24 | examples/using_double_on_avr/encode_double 25 | examples/using_double_on_avr/test_conversions 26 | examples/using_union_messages/decode 27 | examples/using_union_messages/encode 28 | generator/nanopb_pb2.pyc 29 | -------------------------------------------------------------------------------- /external/nanopb-master/.travis.yml: -------------------------------------------------------------------------------- 1 | # Travis CI has no ability to handle 3 langauges (c, c++, python) 2 | # and it overrides $CC/$CXX if language is set to c/c++ (only one, not both). 3 | # 4 | # Set language to python since at least the result of that is something useful. 5 | language: python 6 | 7 | python: 8 | - "2.7" 9 | - "3.4" 10 | 11 | # Manage the C/C++ compiler manually 12 | env: 13 | - CC=gcc CXX=g++ 14 | - CC=gcc-4.8 CXX=g++-4.8 15 | - CC=gcc-4.9 CXX=g++-4.9 16 | - CC=gcc-5 CXX=g++-5 17 | - CC=clang CXX=clang++ 18 | 19 | addons: 20 | apt: 21 | sources: 22 | - ubuntu-toolchain-r-test 23 | packages: 24 | - gcc-4.8 25 | - g++-4.8 26 | - gcc-4.9 27 | - g++-4.9 28 | - gcc-5 29 | - g++-5 30 | 31 | 32 | before_install: 33 | - export PATH=$HOME/.local/bin:$HOME/protobuf/bin:$PATH 34 | - export MAKEFLAGS=-j$(nproc) 35 | - $CC --version 36 | - $CXX --version 37 | - python --version 38 | - lsb_release -a 39 | 40 | # Seems to be issues with concurrent builds 41 | #cache: 42 | # directories: 43 | # - $HOME/protobuf 44 | 45 | # Rather then compile protobuf 3 from source, use the binaries now available 46 | # to speed up build time and reduce surprises until Ubuntu adds protobuf3 47 | # packages to the repository. 48 | install: 49 | - mkdir -p $HOME/protobuf && pushd $HOME/protobuf 50 | && curl -LO 'https://github.com/google/protobuf/releases/download/v3.4.0/protoc-3.4.0-linux-x86_64.zip' 51 | && unzip protoc-3.4.0-linux-x86_64.zip 52 | && popd 53 | - curl -L 'https://github.com/google/protobuf/releases/download/v3.4.0/protobuf-python-3.4.0.tar.gz' | tar xzf - 54 | && pushd protobuf-3.4.0/python 55 | && python setup.py build && python setup.py install 56 | && popd 57 | 58 | script: 59 | - pushd generator/proto && make && popd 60 | - pushd tests && scons CC=$CC CXX=$CXX && popd 61 | -------------------------------------------------------------------------------- /external/nanopb-master/AUTHORS.txt: -------------------------------------------------------------------------------- 1 | Petteri Aimonen 2 | Michael Poole 3 | Daniel Kan 4 | Stan Hu 5 | David Hotham 6 | Steffen Siering 7 | Jens Steinhauser 8 | Pavel Ilin 9 | Kent Ryhorchuk 10 | Martin Donath 11 | Oliver Lee 12 | Michael Haberler 13 | Nicolas Colomer 14 | Ivan Kravets 15 | Kyle Manna 16 | Benjamin Kamath 17 | Andrew Ruder 18 | Kenshi Kawaguchi 19 | isotes 20 | Maxim Khitrov 21 | Yaniv Mordekhay 22 | Ming Zhao 23 | Google, Inc. 24 | Tom Roeder 25 | Piotr Sikora 26 | Bernhard Krämer 27 | Konstantin Podsvirov 28 | William A. Kennington III 29 | Guillaume Lager 30 | Tobias Haegermarck 31 | Justin DeMartino 32 | Constantine Grantcharov 33 | Nick Ewalt 34 | Harald Fernengel 35 | Alice Wang 36 | Kevin Fitch 37 | Kamal Marhubi 38 | Elco Jacobs 39 | Sébastien Morin 40 | Dave Flogeras 41 | Edward Z. Yang 42 | Robbie Shade 43 | Andrew Ballinger 44 | Hamina, Juha-Pekka 45 | Jason Bishop 46 | matejcik 47 | Tobias Müller 48 | Jari Vetoniemi 49 | -------------------------------------------------------------------------------- /external/nanopb-master/BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["LICENSE.txt"]) 4 | 5 | package(default_visibility = ["//visibility:public"]) 6 | 7 | cc_library( 8 | name = "nanopb", 9 | visibility = ["//visibility:public"], 10 | hdrs = [ 11 | "pb.h", 12 | "pb_common.h", 13 | "pb_decode.h", 14 | "pb_encode.h", 15 | ], 16 | srcs = [ 17 | "pb_common.c", 18 | "pb_decode.c", 19 | "pb_encode.c", 20 | ], 21 | ) 22 | -------------------------------------------------------------------------------- /external/nanopb-master/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to Nanopb development 2 | ================================== 3 | 4 | Reporting issues and requesting features 5 | ---------------------------------------- 6 | 7 | Feel free to report any issues you see or features you would like 8 | to see in the future to the Github issue tracker. Using the templates 9 | below is preferred: 10 | 11 | * [Report a bug](https://github.com/nanopb/nanopb/issues/new?body=**Steps%20to%20reproduce%20the%20issue**%0a%0a1.%0a2.%0a3.%0a%0a**What%20happens?**%0A%0A**What%20should%20happen?**&labels=Type-Defect) 12 | * [Request a feature](https://github.com/nanopb/nanopb/issues/new?body=**What%20should%20the%20feature%20do?**%0A%0A**In%20what%20situation%20would%20the%20feature%20be%20useful?**&labels=Type-Enhancement) 13 | 14 | Requesting help 15 | --------------- 16 | 17 | If there is something strange going on, but you do not know if 18 | it is actually a bug in nanopb, try asking first on the 19 | [discussion forum](https://groups.google.com/forum/#!forum/nanopb). 20 | 21 | Pull requests 22 | ------------- 23 | 24 | Pull requests are welcome! 25 | 26 | If it is not obvious from the commit message, please indicate the 27 | same information as you would for an issue report: 28 | 29 | * What functionality it fixes/adds. 30 | * How can the problem be reproduced / when would the feature be useful. 31 | 32 | 33 | -------------------------------------------------------------------------------- /external/nanopb-master/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Petteri Aimonen 2 | 3 | This software is provided 'as-is', without any express or 4 | implied warranty. In no event will the authors be held liable 5 | for any damages arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any 8 | purpose, including commercial applications, and to alter it and 9 | redistribute it freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you 12 | must not claim that you wrote the original software. If you use 13 | this software in a product, an acknowledgment in the product 14 | documentation would be appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and 17 | must not be misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | -------------------------------------------------------------------------------- /external/nanopb-master/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name="com_github_nanopb_nanopb") 2 | -------------------------------------------------------------------------------- /external/nanopb-master/docs/Makefile: -------------------------------------------------------------------------------- 1 | all: index.html concepts.html reference.html security.html migration.html \ 2 | generator_flow.png 3 | 4 | %.png: %.svg 5 | rsvg $< $@ 6 | 7 | %.html: %.rst 8 | rst2html --stylesheet=lsr.css --link-stylesheet $< $@ 9 | sed -i 's!!\n!' $@ 10 | -------------------------------------------------------------------------------- /external/nanopb-master/docs/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrna-research/zrna-api/16a4fa981e5e21202a0ad78a9b18ffa298ef17d0/external/nanopb-master/docs/logo/logo.png -------------------------------------------------------------------------------- /external/nanopb-master/docs/logo/logo16px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrna-research/zrna-api/16a4fa981e5e21202a0ad78a9b18ffa298ef17d0/external/nanopb-master/docs/logo/logo16px.png -------------------------------------------------------------------------------- /external/nanopb-master/docs/logo/logo48px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrna-research/zrna-api/16a4fa981e5e21202a0ad78a9b18ffa298ef17d0/external/nanopb-master/docs/logo/logo48px.png -------------------------------------------------------------------------------- /external/nanopb-master/docs/menu.rst: -------------------------------------------------------------------------------- 1 | .. sidebar :: Documentation index 2 | 3 | 1) `Overview`_ 4 | 2) `Concepts`_ 5 | 3) `API reference`_ 6 | 4) `Security model`_ 7 | 5) `Migration from older versions`_ 8 | 9 | .. _`Overview`: index.html 10 | .. _`Concepts`: concepts.html 11 | .. _`API reference`: reference.html 12 | .. _`Security model`: security.html 13 | .. _`Migration from older versions`: migration.html 14 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_relpath/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(NANOPB_CMAKE_SIMPLE C) 3 | 4 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../extra) 5 | find_package(Nanopb REQUIRED) 6 | include_directories(${NANOPB_INCLUDE_DIRS}) 7 | 8 | nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH proto 9 | proto/simple.proto proto/sub/unlucky.proto) 10 | 11 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 12 | #add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS}) 13 | set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} 14 | PROPERTIES GENERATED TRUE) 15 | 16 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -g -O0") 17 | 18 | add_executable(simple simple.c ${PROTO_SRCS} ${PROTO_HDRS}) 19 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_relpath/README.txt: -------------------------------------------------------------------------------- 1 | Nanopb example "simple" using CMake 2 | ======================= 3 | 4 | This example is the same as the simple nanopb example but built using CMake. 5 | 6 | Example usage 7 | ------------- 8 | 9 | On Linux, create a build directory and then call cmake: 10 | 11 | nanopb/examples/cmake_simple$ mkdir build 12 | nanopb/examples/cmake_simple$ cd build/ 13 | nanopb/examples/cmake_simple/build$ cmake .. 14 | nanopb/examples/cmake_simple/build$ make 15 | 16 | After that, you can run it with the command: ./simple 17 | 18 | On other platforms supported by CMake, refer to CMake instructions. 19 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_relpath/proto/simple.proto: -------------------------------------------------------------------------------- 1 | // A very simple protocol definition, consisting of only 2 | // one message. 3 | syntax = "proto2"; 4 | 5 | import "sub/unlucky.proto"; 6 | 7 | message SimpleMessage { 8 | required int32 lucky_number = 1; 9 | required UnluckyNumber unlucky = 2; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_relpath/proto/sub/unlucky.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message UnluckyNumber { 4 | required uint32 number = 1; 5 | } 6 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_relpath/simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "simple.pb.h" 5 | 6 | int main() 7 | { 8 | /* This is the buffer where we will store our message. */ 9 | uint8_t buffer[128]; 10 | size_t message_length; 11 | bool status; 12 | 13 | /* Encode our message */ 14 | { 15 | /* Allocate space on the stack to store the message data. 16 | * 17 | * Nanopb generates simple struct definitions for all the messages. 18 | * - check out the contents of simple.pb.h! 19 | * It is a good idea to always initialize your structures 20 | * so that you do not have garbage data from RAM in there. 21 | */ 22 | SimpleMessage message = SimpleMessage_init_zero; 23 | 24 | /* Create a stream that will write to our buffer. */ 25 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 26 | 27 | /* Fill in the lucky number */ 28 | message.lucky_number = 13; 29 | message.unlucky.number = 42; 30 | 31 | /* Now we are ready to encode the message! */ 32 | status = pb_encode(&stream, SimpleMessage_fields, &message); 33 | message_length = stream.bytes_written; 34 | 35 | /* Then just check for any errors.. */ 36 | if (!status) 37 | { 38 | printf("Encoding failed: %s\n", PB_GET_ERROR(&stream)); 39 | return 1; 40 | } 41 | } 42 | 43 | /* Now we could transmit the message over network, store it in a file or 44 | * wrap it to a pigeon's leg. 45 | */ 46 | 47 | /* But because we are lazy, we will just decode it immediately. */ 48 | 49 | { 50 | /* Allocate space for the decoded message. */ 51 | SimpleMessage message = SimpleMessage_init_zero; 52 | 53 | /* Create a stream that reads from the buffer. */ 54 | pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); 55 | 56 | /* Now we are ready to decode the message. */ 57 | status = pb_decode(&stream, SimpleMessage_fields, &message); 58 | 59 | /* Check for errors... */ 60 | if (!status) 61 | { 62 | printf("Decoding failed: %s\n", PB_GET_ERROR(&stream)); 63 | return 1; 64 | } 65 | 66 | /* Print the data contained in the message. */ 67 | printf("Your lucky number was %d!\n", message.lucky_number); 68 | printf("Your unlucky number was %u!\n", message.unlucky.number); 69 | } 70 | 71 | return 0; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_simple/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(NANOPB_CMAKE_SIMPLE C) 3 | 4 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../extra) 5 | find_package(Nanopb REQUIRED) 6 | include_directories(${NANOPB_INCLUDE_DIRS}) 7 | 8 | nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS simple.proto) 9 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 10 | #add_custom_target(generate_proto_sources DEPENDS ${PROTO_SRCS} ${PROTO_HDRS}) 11 | set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} 12 | PROPERTIES GENERATED TRUE) 13 | 14 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -g -O0") 15 | 16 | add_executable(simple simple.c ${PROTO_SRCS} ${PROTO_HDRS}) 17 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_simple/README.txt: -------------------------------------------------------------------------------- 1 | Nanopb example "simple" using CMake 2 | ======================= 3 | 4 | This example is the same as the simple nanopb example but built using CMake. 5 | 6 | Example usage 7 | ------------- 8 | 9 | On Linux, create a build directory and then call cmake: 10 | 11 | nanopb/examples/cmake_simple$ mkdir build 12 | nanopb/examples/cmake_simple$ cd build/ 13 | nanopb/examples/cmake_simple/build$ cmake .. 14 | nanopb/examples/cmake_simple/build$ make 15 | 16 | After that, you can run it with the command: ./simple 17 | 18 | On other platforms supported by CMake, refer to CMake instructions. 19 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_simple/simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "simple.pb.h" 5 | 6 | int main() 7 | { 8 | /* This is the buffer where we will store our message. */ 9 | uint8_t buffer[128]; 10 | size_t message_length; 11 | bool status; 12 | 13 | /* Encode our message */ 14 | { 15 | /* Allocate space on the stack to store the message data. 16 | * 17 | * Nanopb generates simple struct definitions for all the messages. 18 | * - check out the contents of simple.pb.h! 19 | * It is a good idea to always initialize your structures 20 | * so that you do not have garbage data from RAM in there. 21 | */ 22 | SimpleMessage message = SimpleMessage_init_zero; 23 | 24 | /* Create a stream that will write to our buffer. */ 25 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 26 | 27 | /* Fill in the lucky number */ 28 | message.lucky_number = 13; 29 | 30 | /* Now we are ready to encode the message! */ 31 | status = pb_encode(&stream, SimpleMessage_fields, &message); 32 | message_length = stream.bytes_written; 33 | 34 | /* Then just check for any errors.. */ 35 | if (!status) 36 | { 37 | printf("Encoding failed: %s\n", PB_GET_ERROR(&stream)); 38 | return 1; 39 | } 40 | } 41 | 42 | /* Now we could transmit the message over network, store it in a file or 43 | * wrap it to a pigeon's leg. 44 | */ 45 | 46 | /* But because we are lazy, we will just decode it immediately. */ 47 | 48 | { 49 | /* Allocate space for the decoded message. */ 50 | SimpleMessage message = SimpleMessage_init_zero; 51 | 52 | /* Create a stream that reads from the buffer. */ 53 | pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); 54 | 55 | /* Now we are ready to decode the message. */ 56 | status = pb_decode(&stream, SimpleMessage_fields, &message); 57 | 58 | /* Check for errors... */ 59 | if (!status) 60 | { 61 | printf("Decoding failed: %s\n", PB_GET_ERROR(&stream)); 62 | return 1; 63 | } 64 | 65 | /* Print the data contained in the message. */ 66 | printf("Your lucky number was %d!\n", message.lucky_number); 67 | } 68 | 69 | return 0; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/cmake_simple/simple.proto: -------------------------------------------------------------------------------- 1 | // A very simple protocol definition, consisting of only 2 | // one message. 3 | 4 | syntax = "proto2"; 5 | 6 | message SimpleMessage { 7 | required int32 lucky_number = 1; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/network_server/Makefile: -------------------------------------------------------------------------------- 1 | # Include the nanopb provided Makefile rules 2 | include ../../extra/nanopb.mk 3 | 4 | # Compiler flags to enable all warnings & debug info 5 | CFLAGS = -ansi -Wall -Werror -g -O0 6 | CFLAGS += -I$(NANOPB_DIR) 7 | 8 | all: server client 9 | 10 | .SUFFIXES: 11 | 12 | clean: 13 | rm -f server client fileproto.pb.c fileproto.pb.h 14 | 15 | %: %.c common.c fileproto.pb.c 16 | $(CC) $(CFLAGS) -o $@ $^ $(NANOPB_CORE) 17 | 18 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/network_server/README.txt: -------------------------------------------------------------------------------- 1 | Nanopb example "network_server" 2 | =============================== 3 | 4 | This example demonstrates the use of nanopb to communicate over network 5 | connections. It consists of a server that sends file listings, and of 6 | a client that requests the file list from the server. 7 | 8 | Example usage 9 | ------------- 10 | 11 | user@host:~/nanopb/examples/network_server$ make # Build the example 12 | protoc -ofileproto.pb fileproto.proto 13 | python ../../generator/nanopb_generator.py fileproto.pb 14 | Writing to fileproto.pb.h and fileproto.pb.c 15 | cc -ansi -Wall -Werror -I .. -g -O0 -I../.. -o server server.c 16 | ../../pb_decode.c ../../pb_encode.c fileproto.pb.c common.c 17 | cc -ansi -Wall -Werror -I .. -g -O0 -I../.. -o client client.c 18 | ../../pb_decode.c ../../pb_encode.c fileproto.pb.c common.c 19 | 20 | user@host:~/nanopb/examples/network_server$ ./server & # Start the server on background 21 | [1] 24462 22 | 23 | petteri@oddish:~/nanopb/examples/network_server$ ./client /bin # Request the server to list /bin 24 | Got connection. 25 | Listing directory: /bin 26 | 1327119 bzdiff 27 | 1327126 bzless 28 | 1327147 ps 29 | 1327178 ntfsmove 30 | 1327271 mv 31 | 1327187 mount 32 | 1327259 false 33 | 1327266 tempfile 34 | 1327285 zfgrep 35 | 1327165 gzexe 36 | 1327204 nc.openbsd 37 | 1327260 uname 38 | 39 | 40 | Details of implementation 41 | ------------------------- 42 | fileproto.proto contains the portable Google Protocol Buffers protocol definition. 43 | It could be used as-is to implement a server or a client in any other language, for 44 | example Python or Java. 45 | 46 | fileproto.options contains the nanopb-specific options for the protocol file. This 47 | sets the amount of space allocated for file names when decoding messages. 48 | 49 | common.c/h contains functions that allow nanopb to read and write directly from 50 | network socket. This way there is no need to allocate a separate buffer to store 51 | the message. 52 | 53 | server.c contains the code to open a listening socket, to respond to clients and 54 | to list directory contents. 55 | 56 | client.c contains the code to connect to a server, to send a request and to print 57 | the response message. 58 | 59 | The code is implemented using the POSIX socket api, but it should be easy enough 60 | to port into any other socket api, such as lwip. 61 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/network_server/common.c: -------------------------------------------------------------------------------- 1 | /* Simple binding of nanopb streams to TCP sockets. 2 | */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "common.h" 10 | 11 | static bool write_callback(pb_ostream_t *stream, const uint8_t *buf, size_t count) 12 | { 13 | int fd = (intptr_t)stream->state; 14 | return send(fd, buf, count, 0) == count; 15 | } 16 | 17 | static bool read_callback(pb_istream_t *stream, uint8_t *buf, size_t count) 18 | { 19 | int fd = (intptr_t)stream->state; 20 | int result; 21 | 22 | result = recv(fd, buf, count, MSG_WAITALL); 23 | 24 | if (result == 0) 25 | stream->bytes_left = 0; /* EOF */ 26 | 27 | return result == count; 28 | } 29 | 30 | pb_ostream_t pb_ostream_from_socket(int fd) 31 | { 32 | pb_ostream_t stream = {&write_callback, (void*)(intptr_t)fd, SIZE_MAX, 0}; 33 | return stream; 34 | } 35 | 36 | pb_istream_t pb_istream_from_socket(int fd) 37 | { 38 | pb_istream_t stream = {&read_callback, (void*)(intptr_t)fd, SIZE_MAX}; 39 | return stream; 40 | } 41 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/network_server/common.h: -------------------------------------------------------------------------------- 1 | #ifndef _PB_EXAMPLE_COMMON_H_ 2 | #define _PB_EXAMPLE_COMMON_H_ 3 | 4 | #include 5 | 6 | pb_ostream_t pb_ostream_from_socket(int fd); 7 | pb_istream_t pb_istream_from_socket(int fd); 8 | 9 | #endif -------------------------------------------------------------------------------- /external/nanopb-master/examples/network_server/fileproto.options: -------------------------------------------------------------------------------- 1 | # This file defines the nanopb-specific options for the messages defined 2 | # in fileproto.proto. 3 | # 4 | # If you come from high-level programming background, the hardcoded 5 | # maximum lengths may disgust you. However, if your microcontroller only 6 | # has a few kB of ram to begin with, setting reasonable limits for 7 | # filenames is ok. 8 | # 9 | # On the other hand, using the callback interface, it is not necessary 10 | # to set a limit on the number of files in the response. 11 | 12 | ListFilesRequest.path max_size:128 13 | FileInfo.name max_size:128 14 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/network_server/fileproto.proto: -------------------------------------------------------------------------------- 1 | // This defines protocol for a simple server that lists files. 2 | // 3 | // See also the nanopb-specific options in fileproto.options. 4 | 5 | syntax = "proto2"; 6 | 7 | message ListFilesRequest { 8 | optional string path = 1 [default = "/"]; 9 | } 10 | 11 | message FileInfo { 12 | required uint64 inode = 1; 13 | required string name = 2; 14 | } 15 | 16 | message ListFilesResponse { 17 | optional bool path_error = 1 [default = false]; 18 | repeated FileInfo file = 2; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/simple/Makefile: -------------------------------------------------------------------------------- 1 | # Include the nanopb provided Makefile rules 2 | include ../../extra/nanopb.mk 3 | 4 | # Compiler flags to enable all warnings & debug info 5 | CFLAGS = -Wall -Werror -g -O0 6 | CFLAGS += -I$(NANOPB_DIR) 7 | 8 | # C source code files that are required 9 | CSRC = simple.c # The main program 10 | CSRC += simple.pb.c # The compiled protocol definition 11 | CSRC += $(NANOPB_DIR)/pb_encode.c # The nanopb encoder 12 | CSRC += $(NANOPB_DIR)/pb_decode.c # The nanopb decoder 13 | CSRC += $(NANOPB_DIR)/pb_common.c # The nanopb common parts 14 | 15 | # Build rule for the main program 16 | simple: $(CSRC) 17 | $(CC) $(CFLAGS) -osimple $(CSRC) 18 | 19 | # Build rule for the protocol 20 | simple.pb.c: simple.proto 21 | $(PROTOC) $(PROTOC_OPTS) --nanopb_out=. simple.proto 22 | 23 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/simple/README.txt: -------------------------------------------------------------------------------- 1 | Nanopb example "simple" 2 | ======================= 3 | 4 | This example demonstrates the very basic use of nanopb. It encodes and 5 | decodes a simple message. 6 | 7 | The code uses four different API functions: 8 | 9 | * pb_ostream_from_buffer() to declare the output buffer that is to be used 10 | * pb_encode() to encode a message 11 | * pb_istream_from_buffer() to declare the input buffer that is to be used 12 | * pb_decode() to decode a message 13 | 14 | Example usage 15 | ------------- 16 | 17 | On Linux, simply type "make" to build the example. After that, you can 18 | run it with the command: ./simple 19 | 20 | On other platforms, you first have to compile the protocol definition using 21 | the following command:: 22 | 23 | ../../generator-bin/protoc --nanopb_out=. simple.proto 24 | 25 | After that, add the following four files to your project and compile: 26 | 27 | simple.c simple.pb.c pb_encode.c pb_decode.c 28 | 29 | 30 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/simple/simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "simple.pb.h" 5 | 6 | int main() 7 | { 8 | /* This is the buffer where we will store our message. */ 9 | uint8_t buffer[128]; 10 | size_t message_length; 11 | bool status; 12 | 13 | /* Encode our message */ 14 | { 15 | /* Allocate space on the stack to store the message data. 16 | * 17 | * Nanopb generates simple struct definitions for all the messages. 18 | * - check out the contents of simple.pb.h! 19 | * It is a good idea to always initialize your structures 20 | * so that you do not have garbage data from RAM in there. 21 | */ 22 | SimpleMessage message = SimpleMessage_init_zero; 23 | 24 | /* Create a stream that will write to our buffer. */ 25 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 26 | 27 | /* Fill in the lucky number */ 28 | message.lucky_number = 13; 29 | 30 | /* Now we are ready to encode the message! */ 31 | status = pb_encode(&stream, SimpleMessage_fields, &message); 32 | message_length = stream.bytes_written; 33 | 34 | /* Then just check for any errors.. */ 35 | if (!status) 36 | { 37 | printf("Encoding failed: %s\n", PB_GET_ERROR(&stream)); 38 | return 1; 39 | } 40 | } 41 | 42 | /* Now we could transmit the message over network, store it in a file or 43 | * wrap it to a pigeon's leg. 44 | */ 45 | 46 | /* But because we are lazy, we will just decode it immediately. */ 47 | 48 | { 49 | /* Allocate space for the decoded message. */ 50 | SimpleMessage message = SimpleMessage_init_zero; 51 | 52 | /* Create a stream that reads from the buffer. */ 53 | pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); 54 | 55 | /* Now we are ready to decode the message. */ 56 | status = pb_decode(&stream, SimpleMessage_fields, &message); 57 | 58 | /* Check for errors... */ 59 | if (!status) 60 | { 61 | printf("Decoding failed: %s\n", PB_GET_ERROR(&stream)); 62 | return 1; 63 | } 64 | 65 | /* Print the data contained in the message. */ 66 | printf("Your lucky number was %d!\n", (int)message.lucky_number); 67 | } 68 | 69 | return 0; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/simple/simple.proto: -------------------------------------------------------------------------------- 1 | // A very simple protocol definition, consisting of only 2 | // one message. 3 | 4 | syntax = "proto2"; 5 | 6 | message SimpleMessage { 7 | required int32 lucky_number = 1; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_double_on_avr/Makefile: -------------------------------------------------------------------------------- 1 | # Include the nanopb provided Makefile rules 2 | include ../../extra/nanopb.mk 3 | 4 | # Compiler flags to enable all warnings & debug info 5 | CFLAGS = -Wall -Werror -g -O0 6 | CFLAGS += -I$(NANOPB_DIR) 7 | 8 | all: run_tests 9 | 10 | .SUFFIXES: 11 | 12 | clean: 13 | rm -f test_conversions encode_double decode_double doubleproto.pb.c doubleproto.pb.h 14 | 15 | test_conversions: test_conversions.c double_conversion.c 16 | $(CC) $(CFLAGS) -o $@ $^ 17 | 18 | %: %.c double_conversion.c doubleproto.pb.c 19 | $(CC) $(CFLAGS) -o $@ $^ $(NANOPB_CORE) 20 | 21 | run_tests: test_conversions encode_double decode_double 22 | ./test_conversions 23 | ./encode_double | ./decode_double 24 | 25 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_double_on_avr/README.txt: -------------------------------------------------------------------------------- 1 | Nanopb example "using_double_on_avr" 2 | ==================================== 3 | 4 | Some processors/compilers, such as AVR-GCC, do not support the double 5 | datatype. Instead, they have sizeof(double) == 4. Because protocol 6 | binary format uses the double encoding directly, this causes trouble 7 | if the protocol in .proto requires double fields. 8 | 9 | This directory contains a solution to this problem. It uses uint64_t 10 | to store the raw wire values, because its size is correct on all 11 | platforms. The file double_conversion.c provides functions that 12 | convert these values to/from floats, without relying on compiler 13 | support. 14 | 15 | To use this method, you need to make some modifications to your code: 16 | 17 | 1) Change all 'double' fields into 'fixed64' in the .proto. 18 | 19 | 2) Whenever writing to a 'double' field, use float_to_double(). 20 | 21 | 3) Whenever reading a 'double' field, use double_to_float(). 22 | 23 | The conversion routines are as accurate as the float datatype can 24 | be. Furthermore, they should handle all special values (NaN, inf, denormalized 25 | numbers) correctly. There are testcases in test_conversions.c. 26 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_double_on_avr/decode_double.c: -------------------------------------------------------------------------------- 1 | /* Decodes a double value into a float variable. 2 | * Used to read double values with AVR code, which doesn't support double directly. 3 | */ 4 | 5 | #include 6 | #include 7 | #include "double_conversion.h" 8 | #include "doubleproto.pb.h" 9 | 10 | int main() 11 | { 12 | uint8_t buffer[32]; 13 | size_t count = fread(buffer, 1, sizeof(buffer), stdin); 14 | pb_istream_t stream = pb_istream_from_buffer(buffer, count); 15 | 16 | AVRDoubleMessage message; 17 | pb_decode(&stream, AVRDoubleMessage_fields, &message); 18 | 19 | float v1 = double_to_float(message.field1); 20 | float v2 = double_to_float(message.field2); 21 | 22 | printf("Values: %f %f\n", v1, v2); 23 | 24 | if (v1 == 1234.5678f && 25 | v2 == 0.00001f) 26 | { 27 | return 0; 28 | } 29 | else 30 | { 31 | return 1; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_double_on_avr/double_conversion.h: -------------------------------------------------------------------------------- 1 | /* AVR-GCC does not have real double datatype. Instead its double 2 | * is equal to float, i.e. 32 bit value. If you need to communicate 3 | * with other systems that use double in their .proto files, you 4 | * need to do some conversion. 5 | * 6 | * These functions use bitwise operations to mangle floats into doubles 7 | * and then store them in uint64_t datatype. 8 | */ 9 | 10 | #ifndef DOUBLE_CONVERSION 11 | #define DOUBLE_CONVERSION 12 | 13 | #include 14 | 15 | /* Convert native 4-byte float into a 8-byte double. */ 16 | extern uint64_t float_to_double(float value); 17 | 18 | /* Convert 8-byte double into native 4-byte float. 19 | * Values are rounded to nearest, 0.5 away from zero. 20 | * Overflowing values are converted to Inf or -Inf. 21 | */ 22 | extern float double_to_float(uint64_t value); 23 | 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_double_on_avr/doubleproto.proto: -------------------------------------------------------------------------------- 1 | // A message containing doubles, as used by other applications. 2 | syntax = "proto2"; 3 | 4 | message DoubleMessage { 5 | required double field1 = 1; 6 | required double field2 = 2; 7 | } 8 | 9 | // A message containing doubles, but redefined using uint64_t. 10 | // For use in AVR code. 11 | message AVRDoubleMessage { 12 | required fixed64 field1 = 1; 13 | required fixed64 field2 = 2; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_double_on_avr/encode_double.c: -------------------------------------------------------------------------------- 1 | /* Encodes a float value into a double on the wire. 2 | * Used to emit doubles from AVR code, which doesn't support double directly. 3 | */ 4 | 5 | #include 6 | #include 7 | #include "double_conversion.h" 8 | #include "doubleproto.pb.h" 9 | 10 | int main() 11 | { 12 | AVRDoubleMessage message = { 13 | float_to_double(1234.5678f), 14 | float_to_double(0.00001f) 15 | }; 16 | 17 | uint8_t buffer[32]; 18 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 19 | 20 | pb_encode(&stream, AVRDoubleMessage_fields, &message); 21 | fwrite(buffer, 1, stream.bytes_written, stdout); 22 | 23 | return 0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_double_on_avr/test_conversions.c: -------------------------------------------------------------------------------- 1 | #include "double_conversion.h" 2 | #include 3 | #include 4 | 5 | static const double testvalues[] = { 6 | 0.0, -0.0, 0.1, -0.1, 7 | M_PI, -M_PI, 123456.789, -123456.789, 8 | INFINITY, -INFINITY, NAN, INFINITY - INFINITY, 9 | 1e38, -1e38, 1e39, -1e39, 10 | 1e-38, -1e-38, 1e-39, -1e-39, 11 | 3.14159e-37,-3.14159e-37, 3.14159e-43, -3.14159e-43, 12 | 1e-60, -1e-60, 1e-45, -1e-45, 13 | 0.99999999999999, -0.99999999999999, 127.999999999999, -127.999999999999 14 | }; 15 | 16 | #define TESTVALUES_COUNT (sizeof(testvalues)/sizeof(testvalues[0])) 17 | 18 | int main() 19 | { 20 | int status = 0; 21 | int i; 22 | for (i = 0; i < TESTVALUES_COUNT; i++) 23 | { 24 | double orig = testvalues[i]; 25 | float expected_float = (float)orig; 26 | double expected_double = (double)expected_float; 27 | 28 | float got_float = double_to_float(*(uint64_t*)&orig); 29 | uint64_t got_double = float_to_double(got_float); 30 | 31 | uint32_t e1 = *(uint32_t*)&expected_float; 32 | uint32_t g1 = *(uint32_t*)&got_float; 33 | uint64_t e2 = *(uint64_t*)&expected_double; 34 | uint64_t g2 = got_double; 35 | 36 | if (g1 != e1) 37 | { 38 | printf("%3d double_to_float fail: %08x != %08x\n", i, g1, e1); 39 | status = 1; 40 | } 41 | 42 | if (g2 != e2) 43 | { 44 | printf("%3d float_to_double fail: %016llx != %016llx\n", i, 45 | (unsigned long long)g2, 46 | (unsigned long long)e2); 47 | status = 1; 48 | } 49 | } 50 | 51 | return status; 52 | } 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_union_messages/Makefile: -------------------------------------------------------------------------------- 1 | # Include the nanopb provided Makefile rules 2 | include ../../extra/nanopb.mk 3 | 4 | # Compiler flags to enable all warnings & debug info 5 | CFLAGS = -ansi -Wall -Werror -g -O0 6 | CFLAGS += -I$(NANOPB_DIR) 7 | 8 | all: encode decode 9 | ./encode 1 | ./decode 10 | ./encode 2 | ./decode 11 | ./encode 3 | ./decode 12 | 13 | .SUFFIXES: 14 | 15 | clean: 16 | rm -f encode unionproto.pb.h unionproto.pb.c 17 | 18 | %: %.c unionproto.pb.c 19 | $(CC) $(CFLAGS) -o $@ $^ $(NANOPB_CORE) 20 | 21 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_union_messages/README.txt: -------------------------------------------------------------------------------- 1 | Nanopb example "using_union_messages" 2 | ===================================== 3 | 4 | Union messages is a common technique in Google Protocol Buffers used to 5 | represent a group of messages, only one of which is passed at a time. 6 | It is described in Google's documentation: 7 | https://developers.google.com/protocol-buffers/docs/techniques#union 8 | 9 | This directory contains an example on how to encode and decode union messages 10 | with minimal memory usage. Usually, nanopb would allocate space to store 11 | all of the possible messages at the same time, even though at most one of 12 | them will be used at a time. 13 | 14 | By using some of the lower level nanopb APIs, we can manually generate the 15 | top level message, so that we only need to allocate the one submessage that 16 | we actually want. Similarly when decoding, we can manually read the tag of 17 | the top level message, and only then allocate the memory for the submessage 18 | after we already know its type. 19 | 20 | NOTE: There is a newer protobuf feature called `oneof` that is also supported 21 | by nanopb. It might be a better option for new code. 22 | 23 | 24 | Example usage 25 | ------------- 26 | 27 | Type `make` to run the example. It will build it and run commands like 28 | following: 29 | 30 | ./encode 1 | ./decode 31 | Got MsgType1: 42 32 | ./encode 2 | ./decode 33 | Got MsgType2: true 34 | ./encode 3 | ./decode 35 | Got MsgType3: 3 1415 36 | 37 | This simply demonstrates that the "decode" program has correctly identified 38 | the type of the received message, and managed to decode it. 39 | 40 | 41 | Details of implementation 42 | ------------------------- 43 | 44 | unionproto.proto contains the protocol used in the example. It consists of 45 | three messages: MsgType1, MsgType2 and MsgType3, which are collected together 46 | into UnionMessage. 47 | 48 | encode.c takes one command line argument, which should be a number 1-3. It 49 | then fills in and encodes the corresponding message, and writes it to stdout. 50 | 51 | decode.c reads a UnionMessage from stdin. Then it calls the function 52 | decode_unionmessage_type() to determine the type of the message. After that, 53 | the corresponding message is decoded and the contents of it printed to the 54 | screen. 55 | 56 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_union_messages/decode.c: -------------------------------------------------------------------------------- 1 | /* This program reads a message from stdin, detects its type and decodes it. 2 | */ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include "unionproto.pb.h" 10 | 11 | /* This function reads manually the first tag from the stream and finds the 12 | * corresponding message type. It doesn't yet decode the actual message. 13 | * 14 | * Returns a pointer to the MsgType_fields array, as an identifier for the 15 | * message type. Returns null if the tag is of unknown type or an error occurs. 16 | */ 17 | const pb_field_t* decode_unionmessage_type(pb_istream_t *stream) 18 | { 19 | pb_wire_type_t wire_type; 20 | uint32_t tag; 21 | bool eof; 22 | 23 | while (pb_decode_tag(stream, &wire_type, &tag, &eof)) 24 | { 25 | if (wire_type == PB_WT_STRING) 26 | { 27 | const pb_field_t *field; 28 | for (field = UnionMessage_fields; field->tag != 0; field++) 29 | { 30 | if (field->tag == tag && (field->type & PB_LTYPE_SUBMESSAGE)) 31 | { 32 | /* Found our field. */ 33 | return field->ptr; 34 | } 35 | } 36 | } 37 | 38 | /* Wasn't our field.. */ 39 | pb_skip_field(stream, wire_type); 40 | } 41 | 42 | return NULL; 43 | } 44 | 45 | bool decode_unionmessage_contents(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct) 46 | { 47 | pb_istream_t substream; 48 | bool status; 49 | if (!pb_make_string_substream(stream, &substream)) 50 | return false; 51 | 52 | status = pb_decode(&substream, fields, dest_struct); 53 | pb_close_string_substream(stream, &substream); 54 | return status; 55 | } 56 | 57 | int main() 58 | { 59 | /* Read the data into buffer */ 60 | uint8_t buffer[512]; 61 | size_t count = fread(buffer, 1, sizeof(buffer), stdin); 62 | pb_istream_t stream = pb_istream_from_buffer(buffer, count); 63 | 64 | const pb_field_t *type = decode_unionmessage_type(&stream); 65 | bool status = false; 66 | 67 | if (type == MsgType1_fields) 68 | { 69 | MsgType1 msg = {}; 70 | status = decode_unionmessage_contents(&stream, MsgType1_fields, &msg); 71 | printf("Got MsgType1: %d\n", msg.value); 72 | } 73 | else if (type == MsgType2_fields) 74 | { 75 | MsgType2 msg = {}; 76 | status = decode_unionmessage_contents(&stream, MsgType2_fields, &msg); 77 | printf("Got MsgType2: %s\n", msg.value ? "true" : "false"); 78 | } 79 | else if (type == MsgType3_fields) 80 | { 81 | MsgType3 msg = {}; 82 | status = decode_unionmessage_contents(&stream, MsgType3_fields, &msg); 83 | printf("Got MsgType3: %d %d\n", msg.value1, msg.value2); 84 | } 85 | 86 | if (!status) 87 | { 88 | printf("Decode failed: %s\n", PB_GET_ERROR(&stream)); 89 | return 1; 90 | } 91 | 92 | return 0; 93 | } 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_union_messages/encode.c: -------------------------------------------------------------------------------- 1 | /* This program takes a command line argument and encodes a message in 2 | * one of MsgType1, MsgType2 or MsgType3. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include "unionproto.pb.h" 11 | 12 | /* This function is the core of the union encoding process. It handles 13 | * the top-level pb_field_t array manually, in order to encode a correct 14 | * field tag before the message. The pointer to MsgType_fields array is 15 | * used as an unique identifier for the message type. 16 | */ 17 | bool encode_unionmessage(pb_ostream_t *stream, const pb_field_t messagetype[], const void *message) 18 | { 19 | const pb_field_t *field; 20 | for (field = UnionMessage_fields; field->tag != 0; field++) 21 | { 22 | if (field->ptr == messagetype) 23 | { 24 | /* This is our field, encode the message using it. */ 25 | if (!pb_encode_tag_for_field(stream, field)) 26 | return false; 27 | 28 | return pb_encode_submessage(stream, messagetype, message); 29 | } 30 | } 31 | 32 | /* Didn't find the field for messagetype */ 33 | return false; 34 | } 35 | 36 | int main(int argc, char **argv) 37 | { 38 | if (argc != 2) 39 | { 40 | fprintf(stderr, "Usage: %s (1|2|3)\n", argv[0]); 41 | return 1; 42 | } 43 | 44 | uint8_t buffer[512]; 45 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 46 | 47 | bool status = false; 48 | int msgtype = atoi(argv[1]); 49 | if (msgtype == 1) 50 | { 51 | /* Send message of type 1 */ 52 | MsgType1 msg = {42}; 53 | status = encode_unionmessage(&stream, MsgType1_fields, &msg); 54 | } 55 | else if (msgtype == 2) 56 | { 57 | /* Send message of type 2 */ 58 | MsgType2 msg = {true}; 59 | status = encode_unionmessage(&stream, MsgType2_fields, &msg); 60 | } 61 | else if (msgtype == 3) 62 | { 63 | /* Send message of type 3 */ 64 | MsgType3 msg = {3, 1415}; 65 | status = encode_unionmessage(&stream, MsgType3_fields, &msg); 66 | } 67 | else 68 | { 69 | fprintf(stderr, "Unknown message type: %d\n", msgtype); 70 | return 2; 71 | } 72 | 73 | if (!status) 74 | { 75 | fprintf(stderr, "Encoding failed!\n"); 76 | return 3; 77 | } 78 | else 79 | { 80 | fwrite(buffer, 1, stream.bytes_written, stdout); 81 | return 0; /* Success */ 82 | } 83 | } 84 | 85 | 86 | -------------------------------------------------------------------------------- /external/nanopb-master/examples/using_union_messages/unionproto.proto: -------------------------------------------------------------------------------- 1 | // This is an example of how to handle 'union' style messages 2 | // with nanopb, without allocating memory for all the message types. 3 | // 4 | // There is no official type in Protocol Buffers for describing unions, 5 | // but they are commonly implemented by filling out exactly one of 6 | // several optional fields. 7 | 8 | syntax = "proto2"; 9 | 10 | message MsgType1 11 | { 12 | required int32 value = 1; 13 | } 14 | 15 | message MsgType2 16 | { 17 | required bool value = 1; 18 | } 19 | 20 | message MsgType3 21 | { 22 | required int32 value1 = 1; 23 | required int32 value2 = 2; 24 | } 25 | 26 | message UnionMessage 27 | { 28 | optional MsgType1 msg1 = 1; 29 | optional MsgType2 msg2 = 2; 30 | optional MsgType3 msg3 = 3; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /external/nanopb-master/extra/nanopb-config-version.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@nanopb_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /external/nanopb-master/extra/nanopb-config.cmake: -------------------------------------------------------------------------------- 1 | include(${CMAKE_CURRENT_LIST_DIR}/nanopb-targets.cmake) 2 | -------------------------------------------------------------------------------- /external/nanopb-master/extra/nanopb.mk: -------------------------------------------------------------------------------- 1 | # This is an include file for Makefiles. It provides rules for building 2 | # .pb.c and .pb.h files out of .proto, as well the path to nanopb core. 3 | 4 | # Path to the nanopb root directory 5 | NANOPB_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))../) 6 | 7 | # Files for the nanopb core 8 | NANOPB_CORE = $(NANOPB_DIR)/pb_encode.c $(NANOPB_DIR)/pb_decode.c $(NANOPB_DIR)/pb_common.c 9 | 10 | # Check if we are running on Windows 11 | ifdef windir 12 | WINDOWS = 1 13 | endif 14 | ifdef WINDIR 15 | WINDOWS = 1 16 | endif 17 | 18 | # Check whether to use binary version of nanopb_generator or the 19 | # system-supplied python interpreter. 20 | ifneq "$(wildcard $(NANOPB_DIR)/generator-bin)" "" 21 | # Binary package 22 | PROTOC = $(NANOPB_DIR)/generator-bin/protoc 23 | PROTOC_OPTS = 24 | else 25 | # Source only or git checkout 26 | PROTOC = protoc 27 | ifdef WINDOWS 28 | PROTOC_OPTS = --plugin=protoc-gen-nanopb=$(NANOPB_DIR)/generator/protoc-gen-nanopb.bat 29 | else 30 | PROTOC_OPTS = --plugin=protoc-gen-nanopb=$(NANOPB_DIR)/generator/protoc-gen-nanopb 31 | endif 32 | endif 33 | 34 | # Rule for building .pb.c and .pb.h 35 | %.pb.c %.pb.h: %.proto $(wildcard %.options) 36 | $(PROTOC) $(PROTOC_OPTS) --nanopb_out=. $< 37 | -------------------------------------------------------------------------------- /external/nanopb-master/extra/pb_syshdr.h: -------------------------------------------------------------------------------- 1 | /* This is an example of a header file for platforms/compilers that do 2 | * not come with stdint.h/stddef.h/stdbool.h/string.h. To use it, define 3 | * PB_SYSTEM_HEADER as "pb_syshdr.h", including the quotes, and add the 4 | * extra folder to your include path. 5 | * 6 | * It is very likely that you will need to customize this file to suit 7 | * your platform. For any compiler that supports C99, this file should 8 | * not be necessary. 9 | */ 10 | 11 | #ifndef _PB_SYSHDR_H_ 12 | #define _PB_SYSHDR_H_ 13 | 14 | /* stdint.h subset */ 15 | #ifdef HAVE_STDINT_H 16 | #include 17 | #else 18 | /* You will need to modify these to match the word size of your platform. */ 19 | typedef signed char int8_t; 20 | typedef unsigned char uint8_t; 21 | typedef signed short int16_t; 22 | typedef unsigned short uint16_t; 23 | typedef signed int int32_t; 24 | typedef unsigned int uint32_t; 25 | typedef signed long long int64_t; 26 | typedef unsigned long long uint64_t; 27 | 28 | /* These are ok for most platforms, unless uint8_t is actually not available, 29 | * in which case you should give the smallest available type. */ 30 | typedef int8_t int_least8_t; 31 | typedef uint8_t uint_least8_t; 32 | typedef uint8_t uint_fast8_t; 33 | typedef int16_t int_least16_t; 34 | typedef uint16_t uint_least16_t; 35 | #endif 36 | 37 | /* stddef.h subset */ 38 | #ifdef HAVE_STDDEF_H 39 | #include 40 | #else 41 | 42 | typedef uint32_t size_t; 43 | #define offsetof(st, m) ((size_t)(&((st *)0)->m)) 44 | 45 | #ifndef NULL 46 | #define NULL 0 47 | #endif 48 | 49 | #endif 50 | 51 | /* stdbool.h subset */ 52 | #ifdef HAVE_STDBOOL_H 53 | #include 54 | #else 55 | 56 | #ifndef __cplusplus 57 | typedef int bool; 58 | #define false 0 59 | #define true 1 60 | #endif 61 | 62 | #endif 63 | 64 | /* stdlib.h subset */ 65 | #ifdef PB_ENABLE_MALLOC 66 | #ifdef HAVE_STDLIB_H 67 | #include 68 | #else 69 | void *realloc(void *ptr, size_t size); 70 | void free(void *ptr); 71 | #endif 72 | #endif 73 | 74 | /* string.h subset */ 75 | #ifdef HAVE_STRING_H 76 | #include 77 | #else 78 | 79 | /* Implementations are from the Public Domain C Library (PDCLib). */ 80 | static size_t strlen( const char * s ) 81 | { 82 | size_t rc = 0; 83 | while ( s[rc] ) 84 | { 85 | ++rc; 86 | } 87 | return rc; 88 | } 89 | 90 | static void * memcpy( void *s1, const void *s2, size_t n ) 91 | { 92 | char * dest = (char *) s1; 93 | const char * src = (const char *) s2; 94 | while ( n-- ) 95 | { 96 | *dest++ = *src++; 97 | } 98 | return s1; 99 | } 100 | 101 | static void * memset( void * s, int c, size_t n ) 102 | { 103 | unsigned char * p = (unsigned char *) s; 104 | while ( n-- ) 105 | { 106 | *p++ = (unsigned char) c; 107 | } 108 | return s; 109 | } 110 | #endif 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /external/nanopb-master/generator/proto/Makefile: -------------------------------------------------------------------------------- 1 | all: nanopb_pb2.py plugin_pb2.py 2 | 3 | %_pb2.py: %.proto 4 | protoc --python_out=. $< 5 | -------------------------------------------------------------------------------- /external/nanopb-master/generator/proto/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zrna-research/zrna-api/16a4fa981e5e21202a0ad78a9b18ffa298ef17d0/external/nanopb-master/generator/proto/__init__.py -------------------------------------------------------------------------------- /external/nanopb-master/generator/protoc-gen-nanopb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This file is used to invoke nanopb_generator.py as a plugin 4 | # to protoc on Linux and other *nix-style systems. 5 | # Use it like this: 6 | # protoc --plugin=protoc-gen-nanopb=..../protoc-gen-nanopb --nanopb_out=dir foo.proto 7 | # 8 | # Note that if you use the binary package of nanopb, the protoc 9 | # path is already set up properly and there is no need to give 10 | # --plugin= on the command line. 11 | 12 | MYPATH=$(dirname "$0") 13 | exec "$MYPATH/nanopb_generator.py" --protoc-plugin 14 | -------------------------------------------------------------------------------- /external/nanopb-master/generator/protoc-gen-nanopb.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: This file is used to invoke nanopb_generator.py as a plugin 3 | :: to protoc on Windows. 4 | :: Use it like this: 5 | :: protoc --plugin=protoc-gen-nanopb=..../protoc-gen-nanopb.bat --nanopb_out=dir foo.proto 6 | :: 7 | :: Note that if you use the binary package of nanopb, the protoc 8 | :: path is already set up properly and there is no need to give 9 | :: --plugin= on the command line. 10 | 11 | set mydir=%~dp0 12 | python "%mydir%\nanopb_generator.py" --protoc-plugin 13 | -------------------------------------------------------------------------------- /external/nanopb-master/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Nanopb", 3 | "version": "0.3.9", 4 | "keywords": "protocol buffers, protobuf, google", 5 | "description": "Nanopb is a plain-C implementation of Google's Protocol Buffers data format. It is targeted at 32 bit microcontrollers, but is also fit for other embedded systems with tight (2-10 kB ROM, <1 kB RAM) memory constraints.", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/nanopb/nanopb.git" 9 | }, 10 | "authors": [{ 11 | "name": "Petteri Aimonen", 12 | "email": "jpa@nanopb.mail.kapsi.fi", 13 | "url": "http://koti.kapsi.fi/jpa/nanopb/" 14 | }], 15 | "export": { 16 | "include": [ 17 | "*.c", 18 | "*.cpp", 19 | "*.h", 20 | "examples" 21 | ] 22 | }, 23 | "examples": "examples/*/*.c", 24 | "frameworks": "*", 25 | "platforms": "*" 26 | } 27 | -------------------------------------------------------------------------------- /external/nanopb-master/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 | /* Iterator for pb_field_t list */ 15 | struct pb_field_iter_s { 16 | const pb_field_t *start; /* Start of the pb_field_t array */ 17 | const pb_field_t *pos; /* Current position of the iterator */ 18 | unsigned required_field_index; /* Zero-based index that counts only the required fields */ 19 | void *dest_struct; /* Pointer to start of the structure */ 20 | void *pData; /* Pointer to current field value */ 21 | void *pSize; /* Pointer to count/has field */ 22 | }; 23 | typedef struct pb_field_iter_s pb_field_iter_t; 24 | 25 | /* Initialize the field iterator structure to beginning. 26 | * Returns false if the message type is empty. */ 27 | bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_field_t *fields, void *dest_struct); 28 | 29 | /* Advance the iterator to the next field. 30 | * Returns false when the iterator wraps back to the first field. */ 31 | bool pb_field_iter_next(pb_field_iter_t *iter); 32 | 33 | /* Advance the iterator until it points at a field with the given tag. 34 | * Returns false if no such field exists. */ 35 | bool pb_field_iter_find(pb_field_iter_t *iter, uint32_t tag); 36 | 37 | #ifdef __cplusplus 38 | } /* extern "C" */ 39 | #endif 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | scons 3 | 4 | clean: 5 | scons -c 6 | 7 | coverage: 8 | rm -rf build coverage 9 | 10 | # LCOV does not like the newer gcov format 11 | scons CC=gcc-4.6 CXX=gcc-4.6 12 | 13 | # Collect the data 14 | mkdir build/coverage 15 | lcov --base-directory . --directory build/ --gcov-tool gcov-4.6 -c -o build/coverage/nanopb.info 16 | 17 | # Remove the test code from results 18 | lcov -r build/coverage/nanopb.info '*tests*' -o build/coverage/nanopb.info 19 | 20 | # Generate HTML 21 | genhtml -o build/coverage build/coverage/nanopb.info 22 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes/SConscript: -------------------------------------------------------------------------------- 1 | # Build and run a test that encodes and decodes a message that contains 2 | # all of the Protocol Buffers data types. 3 | 4 | Import("env") 5 | 6 | env.NanopbProto(["alltypes", "alltypes.options"]) 7 | enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 8 | dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 9 | 10 | # Test the round-trip from nanopb encoder to nanopb decoder 11 | env.RunTest(enc) 12 | env.RunTest([dec, "encode_alltypes.output"]) 13 | 14 | # Re-encode the data using protoc, and check that the results from nanopb 15 | # match byte-per-byte to the protoc output. 16 | env.Decode("encode_alltypes.output.decoded", 17 | ["encode_alltypes.output", "alltypes.proto"], 18 | MESSAGE='AllTypes') 19 | env.Encode("encode_alltypes.output.recoded", 20 | ["encode_alltypes.output.decoded", "alltypes.proto"], 21 | MESSAGE='AllTypes') 22 | env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"]) 23 | 24 | # Do the same checks with the optional fields present. 25 | env.RunTest("optionals.output", enc, ARGS = ['1']) 26 | env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) 27 | env.Decode("optionals.output.decoded", 28 | ["optionals.output", "alltypes.proto"], 29 | MESSAGE='AllTypes') 30 | env.Encode("optionals.output.recoded", 31 | ["optionals.output.decoded", "alltypes.proto"], 32 | MESSAGE='AllTypes') 33 | env.Compare(["optionals.output", "optionals.output.recoded"]) 34 | 35 | # And for the _zero initializer 36 | env.RunTest("zeroinit.output", enc, ARGS = ['2']) 37 | env.RunTest("zeroinit.decout", [dec, "zeroinit.output"], ARGS = ['2']) 38 | env.Decode("zeroinit.output.decoded", 39 | ["zeroinit.output", "alltypes.proto"], 40 | MESSAGE='AllTypes') 41 | env.Encode("zeroinit.output.recoded", 42 | ["zeroinit.output.decoded", "alltypes.proto"], 43 | MESSAGE='AllTypes') 44 | env.Compare(["zeroinit.output", "zeroinit.output.recoded"]) 45 | 46 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes/alltypes.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | *.*fbytes fixed_length:true max_size:4 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_callback/SConscript: -------------------------------------------------------------------------------- 1 | # Test the AllTypes encoding & decoding using callbacks for all fields. 2 | 3 | Import("env", "malloc_env") 4 | 5 | c = Copy("$TARGET", "$SOURCE") 6 | env.Command("alltypes.proto", "#alltypes/alltypes.proto", c) 7 | 8 | env.NanopbProto(["alltypes", "alltypes.options"]) 9 | enc = env.Program(["encode_alltypes_callback.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 10 | dec = env.Program(["decode_alltypes_callback.c", "alltypes.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 11 | 12 | refdec = "$BUILD/alltypes/decode_alltypes$PROGSUFFIX" 13 | 14 | # Encode and compare results 15 | env.RunTest(enc) 16 | env.RunTest("decode_alltypes.output", [refdec, "encode_alltypes_callback.output"]) 17 | env.RunTest("decode_alltypes_callback.output", [dec, "encode_alltypes_callback.output"]) 18 | 19 | # Do the same thing with the optional fields present 20 | env.RunTest("optionals.output", enc, ARGS = ['1']) 21 | env.RunTest("optionals.refdecout", [refdec, "optionals.output"], ARGS = ['1']) 22 | env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) 23 | 24 | # Try with malloc support also 25 | mallocbin1 = malloc_env.Object("decode_with_malloc.o", "decode_alltypes_callback.c") 26 | mallocbin2 = malloc_env.Object("alltypes_malloc.pb.o", "alltypes.pb.c") 27 | mallocdec = malloc_env.Program("decode_with_malloc", [mallocbin1, mallocbin2, "$COMMON/pb_decode_with_malloc.o", "$COMMON/pb_common_with_malloc.o", "$COMMON/malloc_wrappers.o"]) 28 | env.RunTest("decode_with_malloc.output", [mallocdec, "encode_alltypes_callback.output"]) 29 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_callback/alltypes.options: -------------------------------------------------------------------------------- 1 | # Generate all fields as callbacks. 2 | AllTypes.* type:FT_CALLBACK 3 | SubMessage.substuff1 max_size:16 4 | AllTypes.oneof no_unions:true 5 | 6 | # With FT_CALLBACK, these options should get ignored 7 | *.*fbytes fixed_length:true max_size:4 8 | 9 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_pointer/SConscript: -------------------------------------------------------------------------------- 1 | # Encode the AllTypes message using pointers for all fields, and verify the 2 | # output against the normal AllTypes test case. 3 | 4 | Import("env", "malloc_env") 5 | 6 | c = Copy("$TARGET", "$SOURCE") 7 | env.Command("alltypes.proto", "#alltypes/alltypes.proto", c) 8 | 9 | env.NanopbProto(["alltypes", "alltypes.options"]) 10 | enc = malloc_env.Program(["encode_alltypes_pointer.c", 11 | "alltypes.pb.c", 12 | "$COMMON/pb_encode_with_malloc.o", 13 | "$COMMON/pb_common_with_malloc.o", 14 | "$COMMON/malloc_wrappers.o"]) 15 | dec = malloc_env.Program(["decode_alltypes_pointer.c", 16 | "alltypes.pb.c", 17 | "$COMMON/pb_decode_with_malloc.o", 18 | "$COMMON/pb_common_with_malloc.o", 19 | "$COMMON/malloc_wrappers.o"]) 20 | 21 | # Encode and compare results to non-pointer alltypes test case 22 | env.RunTest(enc) 23 | env.Compare(["encode_alltypes_pointer.output", "$BUILD/alltypes/encode_alltypes.output"]) 24 | 25 | # Decode (under valgrind if available) 26 | valgrind = env.WhereIs('valgrind') 27 | kwargs = {} 28 | if valgrind: 29 | kwargs['COMMAND'] = valgrind 30 | kwargs['ARGS'] = ["-q", "--error-exitcode=99", dec[0].abspath] 31 | 32 | env.RunTest("decode_alltypes.output", [dec, "encode_alltypes_pointer.output"], **kwargs) 33 | 34 | # Do the same thing with the optional fields present 35 | env.RunTest("optionals.output", enc, ARGS = ['1']) 36 | env.Compare(["optionals.output", "$BUILD/alltypes/optionals.output"]) 37 | 38 | kwargs['ARGS'] = kwargs.get('ARGS', []) + ['1'] 39 | env.RunTest("optionals.decout", [dec, "optionals.output"], **kwargs) 40 | 41 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_pointer/alltypes.options: -------------------------------------------------------------------------------- 1 | # Generate all fields as pointers. 2 | * type:FT_POINTER 3 | *.*fbytes fixed_length:true max_size:4 4 | 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_proto3/SConscript: -------------------------------------------------------------------------------- 1 | # Version of AllTypes test case for protobuf 3 file format. 2 | 3 | Import("env") 4 | 5 | import re 6 | match = None 7 | if 'PROTOC_VERSION' in env: 8 | match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION']) 9 | 10 | if match: 11 | version = list(map(int, match.groups())) 12 | 13 | # proto3 syntax is supported by protoc >= 3.0.0 14 | if env.GetOption('clean') or (match and version[0] >= 3): 15 | 16 | env.NanopbProto(["alltypes", "alltypes.options"]) 17 | enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 18 | dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 19 | 20 | # Test the round-trip from nanopb encoder to nanopb decoder 21 | env.RunTest(enc) 22 | env.RunTest([dec, "encode_alltypes.output"]) 23 | 24 | # Re-encode the data using protoc, and check that the results from nanopb 25 | # match byte-per-byte to the protoc output. 26 | env.Decode("encode_alltypes.output.decoded", 27 | ["encode_alltypes.output", "alltypes.proto"], 28 | MESSAGE='AllTypes') 29 | env.Encode("encode_alltypes.output.recoded", 30 | ["encode_alltypes.output.decoded", "alltypes.proto"], 31 | MESSAGE='AllTypes') 32 | env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"]) 33 | 34 | # Do the same checks with the optional fields present. 35 | env.RunTest("optionals.output", enc, ARGS = ['1']) 36 | env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) 37 | env.Decode("optionals.output.decoded", 38 | ["optionals.output", "alltypes.proto"], 39 | MESSAGE='AllTypes') 40 | env.Encode("optionals.output.recoded", 41 | ["optionals.output.decoded", "alltypes.proto"], 42 | MESSAGE='AllTypes') 43 | env.Compare(["optionals.output", "optionals.output.recoded"]) 44 | 45 | 46 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_proto3/alltypes.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | *.*fbytes fixed_length:true max_size:4 4 | 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_proto3_callback/SConscript: -------------------------------------------------------------------------------- 1 | # Test the AllTypes encoding & decoding using callbacks for all fields. 2 | 3 | Import("env", "malloc_env") 4 | 5 | c = Copy("$TARGET", "$SOURCE") 6 | env.Command("alltypes.proto", "#alltypes_proto3/alltypes.proto", c) 7 | 8 | env.NanopbProto(["alltypes", "alltypes.options"]) 9 | enc = env.Program(["encode_alltypes_callback.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 10 | dec = env.Program(["decode_alltypes_callback.c", "alltypes.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 11 | 12 | refdec = "$BUILD/alltypes_proto3/decode_alltypes$PROGSUFFIX" 13 | 14 | # Encode and compare results 15 | env.RunTest(enc) 16 | env.RunTest("decode_alltypes.output", [refdec, "encode_alltypes_callback.output"]) 17 | env.RunTest("decode_alltypes_callback.output", [dec, "encode_alltypes_callback.output"]) 18 | 19 | # Do the same thing with the optional fields present 20 | env.RunTest("optionals.output", enc, ARGS = ['1']) 21 | env.RunTest("optionals.refdecout", [refdec, "optionals.output"], ARGS = ['1']) 22 | env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) 23 | 24 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/alltypes_proto3_callback/alltypes.options: -------------------------------------------------------------------------------- 1 | # Generate all fields as callbacks. 2 | AllTypes.* type:FT_CALLBACK 3 | SubMessage.substuff1 max_size:16 4 | AllTypes.oneof no_unions:true 5 | 6 | # With FT_CALLBACK, these options should get ignored 7 | *.*fbytes fixed_length:true max_size:4 8 | 9 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/anonymous_oneof/SConscript: -------------------------------------------------------------------------------- 1 | # Test anonymous_oneof generator option 2 | 3 | Import('env') 4 | 5 | import re 6 | 7 | match = None 8 | if 'PROTOC_VERSION' in env: 9 | match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION']) 10 | 11 | if match: 12 | version = list(map(int, match.groups())) 13 | 14 | # Oneof is supported by protoc >= 2.6.0 15 | if env.GetOption('clean') or (match and (version[0] > 2 or (version[0] == 2 and version[1] >= 6))): 16 | # Anonymous oneofs are supported by clang and gcc 17 | if 'clang' in env['CC'] or 'gcc' in env['CC']: 18 | env2 = env.Clone() 19 | if '-pedantic' in env2['CFLAGS']: 20 | env2['CFLAGS'].remove('-pedantic') 21 | env2.NanopbProto('oneof') 22 | 23 | dec = env2.Program(['decode_oneof.c', 24 | 'oneof.pb.c', 25 | '$COMMON/pb_decode.o', 26 | '$COMMON/pb_common.o']) 27 | 28 | env2.RunTest("message1.txt", [dec, '$BUILD/oneof/message1.pb'], ARGS = ['1']) 29 | env2.RunTest("message2.txt", [dec, '$BUILD/oneof/message2.pb'], ARGS = ['2']) 30 | env2.RunTest("message3.txt", [dec, '$BUILD/oneof/message3.pb'], ARGS = ['3']) 31 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/anonymous_oneof/decode_oneof.c: -------------------------------------------------------------------------------- 1 | /* Decode a message using oneof fields */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "oneof.pb.h" 8 | #include "test_helpers.h" 9 | #include "unittests.h" 10 | 11 | /* Test the 'AnonymousOneOfMessage' */ 12 | int test_oneof_1(pb_istream_t *stream, int option) 13 | { 14 | AnonymousOneOfMessage msg; 15 | int status = 0; 16 | 17 | /* To better catch initialization errors */ 18 | memset(&msg, 0xAA, sizeof(msg)); 19 | 20 | if (!pb_decode(stream, AnonymousOneOfMessage_fields, &msg)) 21 | { 22 | printf("Decoding failed: %s\n", PB_GET_ERROR(stream)); 23 | return 1; 24 | } 25 | 26 | /* Check that the basic fields work normally */ 27 | TEST(msg.prefix == 123); 28 | TEST(msg.suffix == 321); 29 | 30 | /* Check that we got the right oneof according to command line */ 31 | if (option == 1) 32 | { 33 | TEST(msg.which_values == AnonymousOneOfMessage_first_tag); 34 | TEST(msg.first == 999); 35 | } 36 | else if (option == 2) 37 | { 38 | TEST(msg.which_values == AnonymousOneOfMessage_second_tag); 39 | TEST(strcmp(msg.second, "abcd") == 0); 40 | } 41 | else if (option == 3) 42 | { 43 | TEST(msg.which_values == AnonymousOneOfMessage_third_tag); 44 | TEST(msg.third.array[0] == 1); 45 | TEST(msg.third.array[1] == 2); 46 | TEST(msg.third.array[2] == 3); 47 | TEST(msg.third.array[3] == 4); 48 | TEST(msg.third.array[4] == 5); 49 | } 50 | 51 | return status; 52 | } 53 | 54 | int main(int argc, char **argv) 55 | { 56 | uint8_t buffer[AnonymousOneOfMessage_size]; 57 | size_t count; 58 | int option; 59 | 60 | if (argc != 2) 61 | { 62 | fprintf(stderr, "Usage: decode_oneof [number]\n"); 63 | return 1; 64 | } 65 | option = atoi(argv[1]); 66 | 67 | SET_BINARY_MODE(stdin); 68 | count = fread(buffer, 1, sizeof(buffer), stdin); 69 | 70 | if (!feof(stdin)) 71 | { 72 | printf("Message does not fit in buffer\n"); 73 | return 1; 74 | } 75 | 76 | { 77 | int status = 0; 78 | pb_istream_t stream; 79 | 80 | stream = pb_istream_from_buffer(buffer, count); 81 | status = test_oneof_1(&stream, option); 82 | 83 | if (status != 0) 84 | return status; 85 | } 86 | 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/anonymous_oneof/oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'nanopb.proto'; 4 | 5 | message SubMessage 6 | { 7 | repeated int32 array = 1 [(nanopb).max_count = 8]; 8 | } 9 | 10 | /* Oneof in a message with other fields */ 11 | message AnonymousOneOfMessage 12 | { 13 | option (nanopb_msgopt).anonymous_oneof = true; 14 | required int32 prefix = 1; 15 | oneof values 16 | { 17 | int32 first = 5; 18 | string second = 6 [(nanopb).max_size = 8]; 19 | SubMessage third = 7; 20 | } 21 | required int32 suffix = 99; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/backwards_compatibility/SConscript: -------------------------------------------------------------------------------- 1 | # Check that the old generated .pb.c/.pb.h files are still compatible with the 2 | # current version of nanopb. 3 | 4 | Import("env") 5 | 6 | enc = env.Program(["encode_legacy.c", "alltypes_legacy.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 7 | dec = env.Program(["decode_legacy.c", "alltypes_legacy.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 8 | 9 | env.RunTest(enc) 10 | env.RunTest([dec, "encode_legacy.output"]) 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/backwards_compatibility/alltypes_legacy.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/basic_buffer/SConscript: -------------------------------------------------------------------------------- 1 | # Build and run a basic round-trip test using memory buffer encoding. 2 | 3 | Import("env") 4 | 5 | enc = env.Program(["encode_buffer.c", "$COMMON/person.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 6 | dec = env.Program(["decode_buffer.c", "$COMMON/person.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 7 | 8 | env.RunTest(enc) 9 | env.RunTest([dec, "encode_buffer.output"]) 10 | env.Decode(["encode_buffer.output", "$COMMON/person.proto"], MESSAGE = "Person") 11 | env.Compare(["decode_buffer.output", "encode_buffer.decoded"]) 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/basic_buffer/decode_buffer.c: -------------------------------------------------------------------------------- 1 | /* A very simple decoding test case, using person.proto. 2 | * Produces output compatible with protoc --decode. 3 | * Reads the encoded data from stdin and prints the values 4 | * to stdout as text. 5 | * 6 | * Run e.g. ./test_encode1 | ./test_decode1 7 | */ 8 | 9 | #include 10 | #include 11 | #include "person.pb.h" 12 | #include "test_helpers.h" 13 | 14 | /* This function is called once from main(), it handles 15 | the decoding and printing. */ 16 | bool print_person(pb_istream_t *stream) 17 | { 18 | int i; 19 | Person person = Person_init_zero; 20 | 21 | if (!pb_decode(stream, Person_fields, &person)) 22 | return false; 23 | 24 | /* Now the decoding is done, rest is just to print stuff out. */ 25 | 26 | printf("name: \"%s\"\n", person.name); 27 | printf("id: %ld\n", (long)person.id); 28 | 29 | if (person.has_email) 30 | printf("email: \"%s\"\n", person.email); 31 | 32 | for (i = 0; i < person.phone_count; i++) 33 | { 34 | Person_PhoneNumber *phone = &person.phone[i]; 35 | printf("phone {\n"); 36 | printf(" number: \"%s\"\n", phone->number); 37 | 38 | if (phone->has_type) 39 | { 40 | switch (phone->type) 41 | { 42 | case Person_PhoneType_WORK: 43 | printf(" type: WORK\n"); 44 | break; 45 | 46 | case Person_PhoneType_HOME: 47 | printf(" type: HOME\n"); 48 | break; 49 | 50 | case Person_PhoneType_MOBILE: 51 | printf(" type: MOBILE\n"); 52 | break; 53 | } 54 | } 55 | printf("}\n"); 56 | } 57 | 58 | return true; 59 | } 60 | 61 | int main() 62 | { 63 | uint8_t buffer[Person_size]; 64 | pb_istream_t stream; 65 | size_t count; 66 | 67 | /* Read the data into buffer */ 68 | SET_BINARY_MODE(stdin); 69 | count = fread(buffer, 1, sizeof(buffer), stdin); 70 | 71 | if (!feof(stdin)) 72 | { 73 | printf("Message does not fit in buffer\n"); 74 | return 1; 75 | } 76 | 77 | /* Construct a pb_istream_t for reading from the buffer */ 78 | stream = pb_istream_from_buffer(buffer, count); 79 | 80 | /* Decode and print out the stuff */ 81 | if (!print_person(&stream)) 82 | { 83 | printf("Parsing failed: %s\n", PB_GET_ERROR(&stream)); 84 | return 1; 85 | } else { 86 | return 0; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/basic_buffer/encode_buffer.c: -------------------------------------------------------------------------------- 1 | /* A very simple encoding test case using person.proto. 2 | * Just puts constant data in the fields and encodes into 3 | * buffer, which is then written to stdout. 4 | */ 5 | 6 | #include 7 | #include 8 | #include "person.pb.h" 9 | #include "test_helpers.h" 10 | 11 | int main() 12 | { 13 | uint8_t buffer[Person_size]; 14 | pb_ostream_t stream; 15 | 16 | /* Initialize the structure with constants */ 17 | Person person = {"Test Person 99", 99, true, "test@person.com", 18 | 3, {{"555-12345678", true, Person_PhoneType_MOBILE}, 19 | {"99-2342", false, 0}, 20 | {"1234-5678", true, Person_PhoneType_WORK}, 21 | }}; 22 | 23 | stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 24 | 25 | /* Now encode it and check if we succeeded. */ 26 | if (pb_encode(&stream, Person_fields, &person)) 27 | { 28 | /* Write the result data to stdout */ 29 | SET_BINARY_MODE(stdout); 30 | fwrite(buffer, 1, stream.bytes_written, stdout); 31 | return 0; /* Success */ 32 | } 33 | else 34 | { 35 | fprintf(stderr, "Encoding failed: %s\n", PB_GET_ERROR(&stream)); 36 | return 1; /* Failure */ 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/basic_stream/SConscript: -------------------------------------------------------------------------------- 1 | # Build and run a basic round-trip test using direct stream encoding. 2 | 3 | Import("env") 4 | 5 | enc = env.Program(["encode_stream.c", "$COMMON/person.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 6 | dec = env.Program(["decode_stream.c", "$COMMON/person.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 7 | 8 | env.RunTest(enc) 9 | env.RunTest([dec, "encode_stream.output"]) 10 | env.Decode(["encode_stream.output", "$COMMON/person.proto"], MESSAGE = "Person") 11 | env.Compare(["decode_stream.output", "encode_stream.decoded"]) 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/basic_stream/decode_stream.c: -------------------------------------------------------------------------------- 1 | /* Same as test_decode1 but reads from stdin directly. 2 | */ 3 | 4 | #include 5 | #include 6 | #include "person.pb.h" 7 | #include "test_helpers.h" 8 | 9 | /* This function is called once from main(), it handles 10 | the decoding and printing. 11 | Ugly copy-paste from test_decode1.c. */ 12 | bool print_person(pb_istream_t *stream) 13 | { 14 | int i; 15 | Person person = Person_init_zero; 16 | 17 | if (!pb_decode(stream, Person_fields, &person)) 18 | return false; 19 | 20 | /* Now the decoding is done, rest is just to print stuff out. */ 21 | 22 | printf("name: \"%s\"\n", person.name); 23 | printf("id: %ld\n", (long)person.id); 24 | 25 | if (person.has_email) 26 | printf("email: \"%s\"\n", person.email); 27 | 28 | for (i = 0; i < person.phone_count; i++) 29 | { 30 | Person_PhoneNumber *phone = &person.phone[i]; 31 | printf("phone {\n"); 32 | printf(" number: \"%s\"\n", phone->number); 33 | 34 | if (phone->has_type) 35 | { 36 | switch (phone->type) 37 | { 38 | case Person_PhoneType_WORK: 39 | printf(" type: WORK\n"); 40 | break; 41 | 42 | case Person_PhoneType_HOME: 43 | printf(" type: HOME\n"); 44 | break; 45 | 46 | case Person_PhoneType_MOBILE: 47 | printf(" type: MOBILE\n"); 48 | break; 49 | } 50 | } 51 | printf("}\n"); 52 | } 53 | 54 | return true; 55 | } 56 | 57 | /* This binds the pb_istream_t to stdin */ 58 | bool callback(pb_istream_t *stream, uint8_t *buf, size_t count) 59 | { 60 | FILE *file = (FILE*)stream->state; 61 | bool status; 62 | 63 | status = (fread(buf, 1, count, file) == count); 64 | 65 | if (feof(file)) 66 | stream->bytes_left = 0; 67 | 68 | return status; 69 | } 70 | 71 | int main() 72 | { 73 | pb_istream_t stream = {&callback, NULL, SIZE_MAX}; 74 | stream.state = stdin; 75 | SET_BINARY_MODE(stdin); 76 | 77 | if (!print_person(&stream)) 78 | { 79 | printf("Parsing failed: %s\n", PB_GET_ERROR(&stream)); 80 | return 1; 81 | } else { 82 | return 0; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/basic_stream/encode_stream.c: -------------------------------------------------------------------------------- 1 | /* Same as test_encode1.c, except writes directly to stdout. 2 | */ 3 | 4 | #include 5 | #include 6 | #include "person.pb.h" 7 | #include "test_helpers.h" 8 | 9 | /* This binds the pb_ostream_t into the stdout stream */ 10 | bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count) 11 | { 12 | FILE *file = (FILE*) stream->state; 13 | return fwrite(buf, 1, count, file) == count; 14 | } 15 | 16 | int main() 17 | { 18 | /* Initialize the structure with constants */ 19 | Person person = {"Test Person 99", 99, true, "test@person.com", 20 | 3, {{"555-12345678", true, Person_PhoneType_MOBILE}, 21 | {"99-2342", false, 0}, 22 | {"1234-5678", true, Person_PhoneType_WORK}, 23 | }}; 24 | 25 | /* Prepare the stream, output goes directly to stdout */ 26 | pb_ostream_t stream = {&streamcallback, NULL, SIZE_MAX, 0}; 27 | stream.state = stdout; 28 | SET_BINARY_MODE(stdout); 29 | 30 | /* Now encode it and check if we succeeded. */ 31 | if (pb_encode(&stream, Person_fields, &person)) 32 | { 33 | return 0; /* Success */ 34 | } 35 | else 36 | { 37 | fprintf(stderr, "Encoding failed: %s\n", PB_GET_ERROR(&stream)); 38 | return 1; /* Failure */ 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/buffer_only/SConscript: -------------------------------------------------------------------------------- 1 | # Run the alltypes test case, but compile with PB_BUFFER_ONLY=1 2 | 3 | Import("env") 4 | 5 | # Take copy of the files for custom build. 6 | c = Copy("$TARGET", "$SOURCE") 7 | env.Command("alltypes.pb.h", "$BUILD/alltypes/alltypes.pb.h", c) 8 | env.Command("alltypes.pb.c", "$BUILD/alltypes/alltypes.pb.c", c) 9 | env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c) 10 | env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c) 11 | 12 | # Define the compilation options 13 | opts = env.Clone() 14 | opts.Append(CPPDEFINES = {'PB_BUFFER_ONLY': 1}) 15 | 16 | # Build new version of core 17 | strict = opts.Clone() 18 | strict.Append(CFLAGS = strict['CORECFLAGS']) 19 | strict.Object("pb_decode_bufonly.o", "$NANOPB/pb_decode.c") 20 | strict.Object("pb_encode_bufonly.o", "$NANOPB/pb_encode.c") 21 | strict.Object("pb_common_bufonly.o", "$NANOPB/pb_common.c") 22 | 23 | # Now build and run the test normally. 24 | enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_bufonly.o", "pb_common_bufonly.o"]) 25 | dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_bufonly.o", "pb_common_bufonly.o"]) 26 | 27 | env.RunTest(enc) 28 | env.RunTest([dec, "encode_alltypes.output"]) 29 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/callbacks/SConscript: -------------------------------------------------------------------------------- 1 | # Test the functionality of the callback fields. 2 | 3 | Import("env") 4 | 5 | env.NanopbProto("callbacks") 6 | enc = env.Program(["encode_callbacks.c", "callbacks.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 7 | dec = env.Program(["decode_callbacks.c", "callbacks.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 8 | 9 | env.RunTest(enc) 10 | env.RunTest([dec, "encode_callbacks.output"]) 11 | 12 | env.Decode(["encode_callbacks.output", "callbacks.proto"], MESSAGE = "TestMessage") 13 | env.Compare(["decode_callbacks.output", "encode_callbacks.decoded"]) 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/callbacks/callbacks.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message SubMessage { 4 | optional string stringvalue = 1; 5 | repeated int32 int32value = 2; 6 | repeated fixed32 fixed32value = 3; 7 | repeated fixed64 fixed64value = 4; 8 | } 9 | 10 | message TestMessage { 11 | optional string stringvalue = 1; 12 | repeated int32 int32value = 2; 13 | repeated fixed32 fixed32value = 3; 14 | repeated fixed64 fixed64value = 4; 15 | optional SubMessage submsg = 5; 16 | repeated string repeatedstring = 6; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/callbacks/encode_callbacks.c: -------------------------------------------------------------------------------- 1 | /* Encoding testcase for callback fields */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include "callbacks.pb.h" 7 | #include "test_helpers.h" 8 | 9 | bool encode_string(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) 10 | { 11 | char *str = "Hello world!"; 12 | 13 | if (!pb_encode_tag_for_field(stream, field)) 14 | return false; 15 | 16 | return pb_encode_string(stream, (uint8_t*)str, strlen(str)); 17 | } 18 | 19 | bool encode_int32(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) 20 | { 21 | if (!pb_encode_tag_for_field(stream, field)) 22 | return false; 23 | 24 | return pb_encode_varint(stream, 42); 25 | } 26 | 27 | bool encode_fixed32(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) 28 | { 29 | uint32_t value = 42; 30 | 31 | if (!pb_encode_tag_for_field(stream, field)) 32 | return false; 33 | 34 | return pb_encode_fixed32(stream, &value); 35 | } 36 | 37 | bool encode_fixed64(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) 38 | { 39 | uint64_t value = 42; 40 | 41 | if (!pb_encode_tag_for_field(stream, field)) 42 | return false; 43 | 44 | return pb_encode_fixed64(stream, &value); 45 | } 46 | 47 | bool encode_repeatedstring(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) 48 | { 49 | char *str[4] = {"Hello world!", "", "Test", "Test2"}; 50 | int i; 51 | 52 | for (i = 0; i < 4; i++) 53 | { 54 | if (!pb_encode_tag_for_field(stream, field)) 55 | return false; 56 | 57 | if (!pb_encode_string(stream, (uint8_t*)str[i], strlen(str[i]))) 58 | return false; 59 | } 60 | return true; 61 | } 62 | 63 | int main() 64 | { 65 | uint8_t buffer[1024]; 66 | pb_ostream_t stream; 67 | TestMessage testmessage = {{{NULL}}}; 68 | 69 | stream = pb_ostream_from_buffer(buffer, 1024); 70 | 71 | testmessage.stringvalue.funcs.encode = &encode_string; 72 | testmessage.int32value.funcs.encode = &encode_int32; 73 | testmessage.fixed32value.funcs.encode = &encode_fixed32; 74 | testmessage.fixed64value.funcs.encode = &encode_fixed64; 75 | 76 | testmessage.has_submsg = true; 77 | testmessage.submsg.stringvalue.funcs.encode = &encode_string; 78 | testmessage.submsg.int32value.funcs.encode = &encode_int32; 79 | testmessage.submsg.fixed32value.funcs.encode = &encode_fixed32; 80 | testmessage.submsg.fixed64value.funcs.encode = &encode_fixed64; 81 | 82 | testmessage.repeatedstring.funcs.encode = &encode_repeatedstring; 83 | 84 | if (!pb_encode(&stream, TestMessage_fields, &testmessage)) 85 | return 1; 86 | 87 | SET_BINARY_MODE(stdout); 88 | if (fwrite(buffer, stream.bytes_written, 1, stdout) != 1) 89 | return 2; 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/SConscript: -------------------------------------------------------------------------------- 1 | # Build the common files needed by multiple test cases 2 | 3 | Import('env') 4 | 5 | # Protocol definitions for the encode/decode_unittests 6 | env.NanopbProto("unittestproto") 7 | 8 | # Protocol definitions for basic_buffer/stream tests 9 | env.NanopbProto("person") 10 | 11 | #-------------------------------------------- 12 | # Binaries of the pb_decode.c and pb_encode.c 13 | # These are built using more strict warning flags. 14 | strict = env.Clone() 15 | strict.Append(CFLAGS = strict['CORECFLAGS']) 16 | strict.Object("pb_decode.o", "$NANOPB/pb_decode.c") 17 | strict.Object("pb_encode.o", "$NANOPB/pb_encode.c") 18 | strict.Object("pb_common.o", "$NANOPB/pb_common.c") 19 | 20 | #----------------------------------------------- 21 | # Binaries of pb_decode etc. with malloc support 22 | # Uses malloc_wrappers.c to count allocations. 23 | malloc_env = env.Clone() 24 | malloc_env.Append(CPPDEFINES = {'PB_ENABLE_MALLOC': 1, 25 | 'PB_SYSTEM_HEADER': '\\"malloc_wrappers_syshdr.h\\"'}) 26 | malloc_env.Append(CPPPATH = ["$COMMON"]) 27 | 28 | if 'SYSHDR' in malloc_env: 29 | malloc_env.Append(CPPDEFINES = {'PB_OLD_SYSHDR': malloc_env['SYSHDR']}) 30 | 31 | # Disable libmudflap, because it will confuse valgrind 32 | # and other memory leak detection tools. 33 | if '-fmudflap' in env["CCFLAGS"]: 34 | malloc_env["CCFLAGS"].remove("-fmudflap") 35 | malloc_env["LINKFLAGS"].remove("-fmudflap") 36 | malloc_env["LIBS"].remove("mudflap") 37 | 38 | malloc_strict = malloc_env.Clone() 39 | malloc_strict.Append(CFLAGS = malloc_strict['CORECFLAGS']) 40 | malloc_strict.Object("pb_decode_with_malloc.o", "$NANOPB/pb_decode.c") 41 | malloc_strict.Object("pb_encode_with_malloc.o", "$NANOPB/pb_encode.c") 42 | malloc_strict.Object("pb_common_with_malloc.o", "$NANOPB/pb_common.c") 43 | 44 | malloc_env.Object("malloc_wrappers.o", "malloc_wrappers.c") 45 | malloc_env.Depends("$NANOPB/pb.h", ["malloc_wrappers_syshdr.h", "malloc_wrappers.h"]) 46 | 47 | Export("malloc_env") 48 | 49 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/malloc_wrappers.c: -------------------------------------------------------------------------------- 1 | #include "malloc_wrappers.h" 2 | #include 3 | #include 4 | #include 5 | 6 | static size_t alloc_count = 0; 7 | 8 | /* Allocate memory and place check values before and after. */ 9 | void* malloc_with_check(size_t size) 10 | { 11 | size_t size32 = (size + 3) / 4 + 3; 12 | uint32_t *buf = malloc(size32 * sizeof(uint32_t)); 13 | buf[0] = size32; 14 | buf[1] = 0xDEADBEEF; 15 | buf[size32 - 1] = 0xBADBAD; 16 | return buf + 2; 17 | } 18 | 19 | /* Free memory allocated with malloc_with_check() and do the checks. */ 20 | void free_with_check(void *mem) 21 | { 22 | uint32_t *buf = (uint32_t*)mem - 2; 23 | assert(buf[1] == 0xDEADBEEF); 24 | assert(buf[buf[0] - 1] == 0xBADBAD); 25 | free(buf); 26 | } 27 | 28 | /* Track memory usage */ 29 | void* counting_realloc(void *ptr, size_t size) 30 | { 31 | /* Don't allocate crazy amounts of RAM when fuzzing */ 32 | if (size > 1000000) 33 | return NULL; 34 | 35 | if (!ptr && size) 36 | alloc_count++; 37 | 38 | return realloc(ptr, size); 39 | } 40 | 41 | void counting_free(void *ptr) 42 | { 43 | if (ptr) 44 | { 45 | assert(alloc_count > 0); 46 | alloc_count--; 47 | free(ptr); 48 | } 49 | } 50 | 51 | size_t get_alloc_count() 52 | { 53 | return alloc_count; 54 | } 55 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/malloc_wrappers.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void* malloc_with_check(size_t size); 4 | void free_with_check(void *mem); 5 | void* counting_realloc(void *ptr, size_t size); 6 | void counting_free(void *ptr); 7 | size_t get_alloc_count(); 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/malloc_wrappers_syshdr.h: -------------------------------------------------------------------------------- 1 | /* This is just a wrapper in order to get our own malloc wrappers into nanopb core. */ 2 | 3 | #define pb_realloc(ptr,size) counting_realloc(ptr,size) 4 | #define pb_free(ptr) counting_free(ptr) 5 | 6 | #ifdef PB_OLD_SYSHDR 7 | #include PB_OLD_SYSHDR 8 | #else 9 | #include 10 | #include 11 | #include 12 | #include 13 | #endif 14 | 15 | #include 16 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "nanopb.proto"; 4 | 5 | message Person { 6 | required string name = 1 [(nanopb).max_size = 40]; 7 | required int32 id = 2; 8 | optional string email = 3 [(nanopb).max_size = 40]; 9 | 10 | enum PhoneType { 11 | MOBILE = 0; 12 | HOME = 1; 13 | WORK = 2; 14 | } 15 | 16 | message PhoneNumber { 17 | required string number = 1 [(nanopb).max_size = 40]; 18 | optional PhoneType type = 2 [default = HOME]; 19 | } 20 | 21 | repeated PhoneNumber phone = 4 [(nanopb).max_count = 5]; 22 | } 23 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/test_helpers.h: -------------------------------------------------------------------------------- 1 | /* Compatibility helpers for the test programs. */ 2 | 3 | #ifndef _TEST_HELPERS_H_ 4 | #define _TEST_HELPERS_H_ 5 | 6 | #ifdef _WIN32 7 | #include 8 | #include 9 | #define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 10 | 11 | #else 12 | #define SET_BINARY_MODE(file) 13 | 14 | #endif 15 | 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/unittestproto.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'nanopb.proto'; 4 | 5 | message IntegerArray { 6 | repeated int32 data = 1 [(nanopb).max_count = 10]; 7 | } 8 | 9 | message FloatArray { 10 | repeated float data = 1 [(nanopb).max_count = 10]; 11 | } 12 | 13 | message StringMessage { 14 | required string data = 1 [(nanopb).max_size = 10]; 15 | } 16 | 17 | message BytesMessage { 18 | required bytes data = 1 [(nanopb).max_size = 16]; 19 | } 20 | 21 | message CallbackArray { 22 | // We cheat a bit and use this message for testing other types, too. 23 | // Nanopb does not care about the actual defined data type for callback 24 | // fields. 25 | repeated int32 data = 1; 26 | } 27 | 28 | message IntegerContainer { 29 | required IntegerArray submsg = 1; 30 | } 31 | 32 | message CallbackContainer { 33 | required CallbackArray submsg = 1; 34 | } 35 | 36 | message CallbackContainerContainer { 37 | required CallbackContainer submsg = 1; 38 | } 39 | 40 | message StringPointerContainer { 41 | repeated string rep_str = 1 [(nanopb).type = FT_POINTER]; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/common/unittests.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define COMMENT(x) printf("\n----" x "----\n"); 4 | #define STR(x) #x 5 | #define STR2(x) STR(x) 6 | #define TEST(x) \ 7 | if (!(x)) { \ 8 | fprintf(stderr, "\033[31;1mFAILED:\033[22;39m " __FILE__ ":" STR2(__LINE__) " " #x "\n"); \ 9 | status = 1; \ 10 | } else { \ 11 | printf("\033[32;1mOK:\033[22;39m " #x "\n"); \ 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/cxx_main_program/SConscript: -------------------------------------------------------------------------------- 1 | # Run the alltypes test case, but compile it as C++ instead. 2 | # In fact, compile the entire nanopb using C++ compiler. 3 | 4 | Import("env") 5 | 6 | # This is needed to get INT32_MIN etc. macros defined 7 | env = env.Clone() 8 | env.Append(CPPDEFINES = ['__STDC_LIMIT_MACROS']) 9 | 10 | # Copy the files to .cxx extension in order to force C++ build. 11 | c = Copy("$TARGET", "$SOURCE") 12 | env.Command("pb_encode.cxx", "#../pb_encode.c", c) 13 | env.Command("pb_decode.cxx", "#../pb_decode.c", c) 14 | env.Command("pb_common.cxx", "#../pb_common.c", c) 15 | env.Command("alltypes.pb.h", "$BUILD/alltypes/alltypes.pb.h", c) 16 | env.Command("alltypes.pb.cxx", "$BUILD/alltypes/alltypes.pb.c", c) 17 | env.Command("encode_alltypes.cxx", "$BUILD/alltypes/encode_alltypes.c", c) 18 | env.Command("decode_alltypes.cxx", "$BUILD/alltypes/decode_alltypes.c", c) 19 | 20 | # Now build and run the test normally. 21 | enc = env.Program(["encode_alltypes.cxx", "alltypes.pb.cxx", "pb_encode.cxx", "pb_common.cxx"]) 22 | dec = env.Program(["decode_alltypes.cxx", "alltypes.pb.cxx", "pb_decode.cxx", "pb_common.cxx"]) 23 | 24 | env.RunTest(enc) 25 | env.RunTest([dec, "encode_alltypes.output"]) 26 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/cyclic_messages/SConscript: -------------------------------------------------------------------------------- 1 | Import("env") 2 | 3 | # Encode cyclic messages with callback fields 4 | 5 | c = Copy("$TARGET", "$SOURCE") 6 | env.Command("cyclic_callback.proto", "cyclic.proto", c) 7 | env.NanopbProto(["cyclic_callback", "cyclic_callback.options"]) 8 | 9 | enc_callback = env.Program(["encode_cyclic_callback.c", "cyclic_callback.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 10 | 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/cyclic_messages/cyclic.proto: -------------------------------------------------------------------------------- 1 | // Test structures with cyclic references. 2 | // These can only be handled in pointer/callback mode, 3 | // see associated .options files. 4 | 5 | syntax = "proto2"; 6 | 7 | message TreeNode 8 | { 9 | optional int32 leaf = 1; 10 | optional TreeNode left = 2; 11 | optional TreeNode right = 3; 12 | } 13 | 14 | message Dictionary 15 | { 16 | repeated KeyValuePair dictItem = 1; 17 | } 18 | 19 | message KeyValuePair 20 | { 21 | required string key = 1; 22 | optional string stringValue = 2; 23 | optional int32 intValue = 3; 24 | optional Dictionary dictValue = 4; 25 | optional TreeNode treeValue = 5; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/cyclic_messages/cyclic_callback.options: -------------------------------------------------------------------------------- 1 | TreeNode.left type:FT_CALLBACK 2 | TreeNode.right type:FT_CALLBACK 3 | 4 | Dictionary.data type:FT_CALLBACK 5 | KeyValuePair.key max_size:8 6 | KeyValuePair.stringValue max_size:8 7 | KeyValuePair.treeValue type:FT_CALLBACK 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/decode_unittests/SConscript: -------------------------------------------------------------------------------- 1 | Import('env') 2 | p = env.Program(["decode_unittests.c", "$COMMON/unittestproto.pb.c"]) 3 | env.RunTest(p) 4 | 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/encode_unittests/SConscript: -------------------------------------------------------------------------------- 1 | # Build and run the stand-alone unit tests for the nanopb encoder part. 2 | 3 | Import('env') 4 | p = env.Program(["encode_unittests.c", "$COMMON/unittestproto.pb.c"]) 5 | env.RunTest(p) 6 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/enum_sizes/SConscript: -------------------------------------------------------------------------------- 1 | # Test that different sizes of enum fields are properly encoded and decoded. 2 | 3 | Import('env') 4 | 5 | env.NanopbProto('enumsizes') 6 | 7 | p = env.Program(["enumsizes_unittests.c", 8 | "enumsizes.pb.c", 9 | "$COMMON/pb_encode.o", 10 | "$COMMON/pb_decode.o", 11 | "$COMMON/pb_common.o"]) 12 | env.RunTest(p) 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/enum_sizes/enumsizes.proto: -------------------------------------------------------------------------------- 1 | /* Test handling of enums with different value ranges. 2 | * Depending on compiler and the packed_enum setting, the datatypes 3 | * for enums can be either signed or unsigned. In past this has caused 4 | * a bit of a problem for the encoder/decoder (issue #164). 5 | */ 6 | 7 | syntax = "proto2"; 8 | 9 | import 'nanopb.proto'; 10 | 11 | option (nanopb_fileopt).long_names = false; 12 | 13 | enum UnpackedUint8 { 14 | option (nanopb_enumopt).packed_enum = false; 15 | UU8_MIN = 0; 16 | UU8_MAX = 255; 17 | } 18 | 19 | enum PackedUint8 { 20 | option (nanopb_enumopt).packed_enum = true; 21 | PU8_MIN = 0; 22 | PU8_MAX = 255; 23 | } 24 | 25 | enum UnpackedInt8 { 26 | option (nanopb_enumopt).packed_enum = false; 27 | UI8_MIN = -128; 28 | UI8_MAX = 127; 29 | } 30 | 31 | enum PackedInt8 { 32 | option (nanopb_enumopt).packed_enum = true; 33 | PI8_MIN = -128; 34 | PI8_MAX = 127; 35 | } 36 | 37 | enum UnpackedUint16 { 38 | option (nanopb_enumopt).packed_enum = false; 39 | UU16_MIN = 0; 40 | UU16_MAX = 65535; 41 | } 42 | 43 | enum PackedUint16 { 44 | option (nanopb_enumopt).packed_enum = true; 45 | PU16_MIN = 0; 46 | PU16_MAX = 65535; 47 | } 48 | 49 | enum UnpackedInt16 { 50 | option (nanopb_enumopt).packed_enum = false; 51 | UI16_MIN = -32768; 52 | UI16_MAX = 32767; 53 | } 54 | 55 | enum PackedInt16 { 56 | option (nanopb_enumopt).packed_enum = true; 57 | PI16_MIN = -32768; 58 | PI16_MAX = 32767; 59 | } 60 | 61 | /* Protobuf supports enums up to 32 bits. 62 | * The 32 bit case is covered by HugeEnum in the alltypes test. 63 | */ 64 | 65 | message PackedEnums { 66 | required PackedUint8 u8_min = 1; 67 | required PackedUint8 u8_max = 2; 68 | required PackedInt8 i8_min = 3; 69 | required PackedInt8 i8_max = 4; 70 | required PackedUint16 u16_min = 5; 71 | required PackedUint16 u16_max = 6; 72 | required PackedInt16 i16_min = 7; 73 | required PackedInt16 i16_max = 8; 74 | } 75 | 76 | message UnpackedEnums { 77 | required UnpackedUint8 u8_min = 1; 78 | required UnpackedUint8 u8_max = 2; 79 | required UnpackedInt8 i8_min = 3; 80 | required UnpackedInt8 i8_max = 4; 81 | required UnpackedUint16 u16_min = 5; 82 | required UnpackedUint16 u16_max = 6; 83 | required UnpackedInt16 i16_min = 7; 84 | required UnpackedInt16 i16_max = 8; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/enum_sizes/enumsizes_unittests.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "unittests.h" 6 | #include "enumsizes.pb.h" 7 | 8 | int main() 9 | { 10 | int status = 0; 11 | 12 | UnpackedEnums msg1 = { 13 | UU8_MIN, UU8_MAX, 14 | UI8_MIN, UI8_MAX, 15 | UU16_MIN, UU16_MAX, 16 | UI16_MIN, UI16_MAX, 17 | }; 18 | 19 | PackedEnums msg2; 20 | UnpackedEnums msg3; 21 | uint8_t buf[256]; 22 | size_t msgsize; 23 | 24 | COMMENT("Step 1: unpacked enums -> protobuf"); 25 | { 26 | pb_ostream_t s = pb_ostream_from_buffer(buf, sizeof(buf)); 27 | TEST(pb_encode(&s, UnpackedEnums_fields, &msg1)); 28 | msgsize = s.bytes_written; 29 | } 30 | 31 | COMMENT("Step 2: protobuf -> packed enums"); 32 | { 33 | pb_istream_t s = pb_istream_from_buffer(buf, msgsize); 34 | TEST(pb_decode(&s, PackedEnums_fields, &msg2)); 35 | 36 | TEST(msg1.u8_min == (int)msg2.u8_min); 37 | TEST(msg1.u8_max == (int)msg2.u8_max); 38 | TEST(msg1.i8_min == (int)msg2.i8_min); 39 | TEST(msg1.i8_max == (int)msg2.i8_max); 40 | TEST(msg1.u16_min == (int)msg2.u16_min); 41 | TEST(msg1.u16_max == (int)msg2.u16_max); 42 | TEST(msg1.i16_min == (int)msg2.i16_min); 43 | TEST(msg1.i16_max == (int)msg2.i16_max); 44 | } 45 | 46 | COMMENT("Step 3: packed enums -> protobuf"); 47 | { 48 | pb_ostream_t s = pb_ostream_from_buffer(buf, sizeof(buf)); 49 | TEST(pb_encode(&s, PackedEnums_fields, &msg2)); 50 | msgsize = s.bytes_written; 51 | } 52 | 53 | COMMENT("Step 4: protobuf -> unpacked enums"); 54 | { 55 | pb_istream_t s = pb_istream_from_buffer(buf, msgsize); 56 | TEST(pb_decode(&s, UnpackedEnums_fields, &msg3)); 57 | 58 | TEST(msg1.u8_min == (int)msg3.u8_min); 59 | TEST(msg1.u8_max == (int)msg3.u8_max); 60 | TEST(msg1.i8_min == (int)msg3.i8_min); 61 | TEST(msg1.i8_max == (int)msg3.i8_max); 62 | TEST(msg1.u16_min == (int)msg2.u16_min); 63 | TEST(msg1.u16_max == (int)msg2.u16_max); 64 | TEST(msg1.i16_min == (int)msg2.i16_min); 65 | TEST(msg1.i16_max == (int)msg2.i16_max); 66 | } 67 | 68 | if (status != 0) 69 | fprintf(stdout, "\n\nSome tests FAILED!\n"); 70 | 71 | return status; 72 | } 73 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/enum_to_string/SConscript: -------------------------------------------------------------------------------- 1 | # Test enum to string functionality 2 | 3 | Import('env') 4 | env.NanopbProto("enum.proto") 5 | p = env.Program(["enum_to_string.c", "enum.pb.c"]) 6 | env.RunTest(p) 7 | 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/enum_to_string/enum.proto: -------------------------------------------------------------------------------- 1 | /* Test enum to string function generation */ 2 | 3 | syntax = "proto2"; 4 | 5 | import "nanopb.proto"; 6 | 7 | option (nanopb_fileopt).enum_to_string = true; 8 | 9 | enum MyEnum { 10 | VALUE1 = 1; 11 | VALUE2 = 2; 12 | VALUE15 = 15; 13 | } 14 | 15 | enum MyShortNameEnum { 16 | option (nanopb_enumopt).long_names = false; 17 | MSNE_VALUE256 = 256; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/enum_to_string/enum_to_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "unittests.h" 3 | #include "enum.pb.h" 4 | 5 | int main() 6 | { 7 | int status = 0; 8 | TEST(strcmp(MyEnum_name(MyEnum_VALUE1), "VALUE1") == 0); 9 | TEST(strcmp(MyEnum_name(MyEnum_VALUE2), "VALUE2") == 0); 10 | TEST(strcmp(MyEnum_name(MyEnum_VALUE15), "VALUE15") == 0); 11 | TEST(strcmp(MyShortNameEnum_name(MSNE_VALUE256), "MSNE_VALUE256") == 0); 12 | TEST(strcmp(MyShortNameEnum_name(9999), "unknown") == 0); 13 | 14 | if (status != 0) 15 | fprintf(stdout, "\n\nSome tests FAILED!\n"); 16 | 17 | return status; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/extensions/SConscript: -------------------------------------------------------------------------------- 1 | # Test the support for extension fields. 2 | 3 | Import("env") 4 | 5 | # We use the files from the alltypes test case 6 | incpath = env.Clone() 7 | incpath.Append(PROTOCPATH = '$BUILD/alltypes') 8 | incpath.Append(CPPPATH = '$BUILD/alltypes') 9 | 10 | incpath.NanopbProto(["extensions", "extensions.options"]) 11 | enc = incpath.Program(["encode_extensions.c", "extensions.pb.c", "$BUILD/alltypes/alltypes.pb$OBJSUFFIX", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 12 | dec = incpath.Program(["decode_extensions.c", "extensions.pb.c", "$BUILD/alltypes/alltypes.pb$OBJSUFFIX", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 13 | 14 | env.RunTest(enc) 15 | env.RunTest([dec, "encode_extensions.output"]) 16 | 17 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/extensions/decode_extensions.c: -------------------------------------------------------------------------------- 1 | /* Test decoding of extension fields. */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "alltypes.pb.h" 8 | #include "extensions.pb.h" 9 | #include "test_helpers.h" 10 | 11 | #define TEST(x) if (!(x)) { \ 12 | printf("Test " #x " failed.\n"); \ 13 | return 2; \ 14 | } 15 | 16 | int main(int argc, char **argv) 17 | { 18 | uint8_t buffer[1024]; 19 | size_t count; 20 | pb_istream_t stream; 21 | 22 | AllTypes alltypes = {0}; 23 | int32_t extensionfield1; 24 | pb_extension_t ext1; 25 | ExtensionMessage extensionfield2; 26 | pb_extension_t ext2; 27 | 28 | /* Read the message data */ 29 | SET_BINARY_MODE(stdin); 30 | count = fread(buffer, 1, sizeof(buffer), stdin); 31 | stream = pb_istream_from_buffer(buffer, count); 32 | 33 | /* Add the extensions */ 34 | alltypes.extensions = &ext1; 35 | 36 | ext1.type = &AllTypes_extensionfield1; 37 | ext1.dest = &extensionfield1; 38 | ext1.next = &ext2; 39 | 40 | ext2.type = &ExtensionMessage_AllTypes_extensionfield2; 41 | ext2.dest = &extensionfield2; 42 | ext2.next = NULL; 43 | 44 | /* Decode the message */ 45 | if (!pb_decode(&stream, AllTypes_fields, &alltypes)) 46 | { 47 | printf("Parsing failed: %s\n", PB_GET_ERROR(&stream)); 48 | return 1; 49 | } 50 | 51 | /* Check that the extensions decoded properly */ 52 | TEST(ext1.found) 53 | TEST(extensionfield1 == 12345) 54 | TEST(ext2.found) 55 | TEST(strcmp(extensionfield2.test1, "test") == 0) 56 | TEST(extensionfield2.test2 == 54321) 57 | 58 | return 0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/extensions/encode_extensions.c: -------------------------------------------------------------------------------- 1 | /* Tests extension fields. 2 | */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "alltypes.pb.h" 9 | #include "extensions.pb.h" 10 | #include "test_helpers.h" 11 | 12 | int main(int argc, char **argv) 13 | { 14 | uint8_t buffer[1024]; 15 | pb_ostream_t stream; 16 | 17 | AllTypes alltypes = {0}; 18 | int32_t extensionfield1 = 12345; 19 | pb_extension_t ext1; 20 | ExtensionMessage extensionfield2 = {"test", 54321}; 21 | pb_extension_t ext2; 22 | 23 | /* Set up the extensions */ 24 | alltypes.extensions = &ext1; 25 | 26 | ext1.type = &AllTypes_extensionfield1; 27 | ext1.dest = &extensionfield1; 28 | ext1.next = &ext2; 29 | 30 | ext2.type = &ExtensionMessage_AllTypes_extensionfield2; 31 | ext2.dest = &extensionfield2; 32 | ext2.next = NULL; 33 | 34 | /* Set up the output stream */ 35 | stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 36 | 37 | /* Now encode the message and check if we succeeded. */ 38 | if (pb_encode(&stream, AllTypes_fields, &alltypes)) 39 | { 40 | SET_BINARY_MODE(stdout); 41 | fwrite(buffer, 1, stream.bytes_written, stdout); 42 | return 0; /* Success */ 43 | } 44 | else 45 | { 46 | fprintf(stderr, "Encoding failed: %s\n", PB_GET_ERROR(&stream)); 47 | return 1; /* Failure */ 48 | } 49 | 50 | /* Check that the field tags are properly generated */ 51 | (void)AllTypes_extensionfield1_tag; 52 | (void)ExtensionMessage_AllTypes_extensionfield2_tag; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/extensions/extensions.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/extensions/extensions.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'alltypes.proto'; 4 | 5 | extend AllTypes { 6 | optional int32 AllTypes_extensionfield1 = 255 [default = 5]; 7 | } 8 | 9 | message ExtensionMessage { 10 | extend AllTypes { 11 | optional ExtensionMessage AllTypes_extensionfield2 = 254; 12 | // required ExtensionMessage AllTypes_extensionfield3 = 253; // No longer allowed by protobuf 3 13 | repeated ExtensionMessage AllTypes_extensionfield4 = 252; 14 | } 15 | 16 | required string test1 = 1; 17 | required int32 test2 = 2; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/extra_fields/SConscript: -------------------------------------------------------------------------------- 1 | # Test that the decoder properly handles unknown fields in the input. 2 | 3 | Import("env") 4 | 5 | dec = env.GetBuildPath('$BUILD/basic_buffer/${PROGPREFIX}decode_buffer${PROGSUFFIX}') 6 | env.RunTest('person_with_extra_field.output', [dec, "person_with_extra_field.pb"]) 7 | env.Compare(["person_with_extra_field.output", "person_with_extra_field.expected"]) 8 | 9 | dec = env.GetBuildPath('$BUILD/basic_stream/${PROGPREFIX}decode_stream${PROGSUFFIX}') 10 | env.RunTest('person_with_extra_field_stream.output', [dec, "person_with_extra_field.pb"]) 11 | env.Compare(["person_with_extra_field_stream.output", "person_with_extra_field.expected"]) 12 | 13 | # This uses the backwards compatibility alltypes test, so that 14 | # alltypes_with_extra_fields.pb doesn't have to be remade so often. 15 | dec2 = env.GetBuildPath('$BUILD/backwards_compatibility/${PROGPREFIX}decode_legacy${PROGSUFFIX}') 16 | env.RunTest('alltypes_with_extra_fields.output', [dec2, 'alltypes_with_extra_fields.pb']) 17 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/extra_fields/person_with_extra_field.expected: -------------------------------------------------------------------------------- 1 | name: "Test Person 99" 2 | id: 99 3 | email: "test@person.com" 4 | phone { 5 | number: "555-12345678" 6 | type: MOBILE 7 | } 8 | phone { 9 | number: "99-2342" 10 | } 11 | phone { 12 | number: "1234-5678" 13 | type: WORK 14 | } 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/field_size_16/SConscript: -------------------------------------------------------------------------------- 1 | # Run the alltypes test case, but compile with PB_FIELD_16BIT=1. 2 | # Also the .proto file has been modified to have high indexes. 3 | 4 | Import("env") 5 | 6 | # Take copy of the files for custom build. 7 | c = Copy("$TARGET", "$SOURCE") 8 | env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c) 9 | env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c) 10 | 11 | env.NanopbProto(["alltypes", "alltypes.options"]) 12 | 13 | # Define the compilation options 14 | opts = env.Clone() 15 | opts.Append(CPPDEFINES = {'PB_FIELD_16BIT': 1}) 16 | 17 | # Build new version of core 18 | strict = opts.Clone() 19 | strict.Append(CFLAGS = strict['CORECFLAGS']) 20 | strict.Object("pb_decode_fields16.o", "$NANOPB/pb_decode.c") 21 | strict.Object("pb_encode_fields16.o", "$NANOPB/pb_encode.c") 22 | strict.Object("pb_common_fields16.o", "$NANOPB/pb_common.c") 23 | 24 | # Now build and run the test normally. 25 | enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_fields16.o", "pb_common_fields16.o"]) 26 | dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_fields16.o", "pb_common_fields16.o"]) 27 | 28 | env.RunTest(enc) 29 | env.RunTest([dec, "encode_alltypes.output"]) 30 | 31 | env.RunTest("optionals.output", enc, ARGS = ['1']) 32 | env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) 33 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/field_size_16/alltypes.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | *.*fbytes fixed_length:true max_size:4 4 | 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/field_size_16_proto3/SConscript: -------------------------------------------------------------------------------- 1 | # Version of AllTypes test case for protobuf 3 file format. 2 | 3 | Import("env") 4 | 5 | import re 6 | match = None 7 | if 'PROTOC_VERSION' in env: 8 | match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION']) 9 | 10 | if match: 11 | version = list(map(int, match.groups())) 12 | 13 | # proto3 syntax is supported by protoc >= 3.0.0 14 | if env.GetOption('clean') or (match and version[0] >= 3): 15 | 16 | env.NanopbProto(["alltypes", "alltypes.options"]) 17 | 18 | # Define the compilation options 19 | opts = env.Clone() 20 | opts.Append(CPPDEFINES = {'PB_FIELD_16BIT': 1}) 21 | 22 | # Build new version of core 23 | strict = opts.Clone() 24 | strict.Append(CFLAGS = strict['CORECFLAGS']) 25 | strict.Object("pb_decode_fields16.o", "$NANOPB/pb_decode.c") 26 | strict.Object("pb_encode_fields16.o", "$NANOPB/pb_encode.c") 27 | strict.Object("pb_common_fields16.o", "$NANOPB/pb_common.c") 28 | 29 | # Now build and run the test normally. 30 | enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_fields16.o", "pb_common_fields16.o"]) 31 | dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_fields16.o", "pb_common_fields16.o"]) 32 | 33 | env.RunTest(enc) 34 | env.RunTest([dec, "encode_alltypes.output"]) 35 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/field_size_16_proto3/alltypes.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | *.*fbytes fixed_length:true max_size:4 4 | SubMessage.substuff1 max_size:256 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/field_size_32/SConscript: -------------------------------------------------------------------------------- 1 | # Run the alltypes test case, but compile with PB_FIELD_32BIT=1. 2 | # Also the .proto file has been modified to have high indexes. 3 | 4 | Import("env") 5 | 6 | # Take copy of the files for custom build. 7 | c = Copy("$TARGET", "$SOURCE") 8 | env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c) 9 | env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c) 10 | 11 | env.NanopbProto(["alltypes", "alltypes.options"]) 12 | 13 | # Define the compilation options 14 | opts = env.Clone() 15 | opts.Append(CPPDEFINES = {'PB_FIELD_32BIT': 1}) 16 | 17 | # Build new version of core 18 | strict = opts.Clone() 19 | strict.Append(CFLAGS = strict['CORECFLAGS']) 20 | strict.Object("pb_decode_fields32.o", "$NANOPB/pb_decode.c") 21 | strict.Object("pb_encode_fields32.o", "$NANOPB/pb_encode.c") 22 | strict.Object("pb_common_fields32.o", "$NANOPB/pb_common.c") 23 | 24 | # Now build and run the test normally. 25 | enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_fields32.o", "pb_common_fields32.o"]) 26 | dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_fields32.o", "pb_common_fields32.o"]) 27 | 28 | env.RunTest(enc) 29 | env.RunTest([dec, "encode_alltypes.output"]) 30 | 31 | env.RunTest("optionals.output", enc, ARGS = ['1']) 32 | env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) 33 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/field_size_32/alltypes.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | *.*fbytes fixed_length:true max_size:4 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/fixed_count/SConscript: -------------------------------------------------------------------------------- 1 | # Test that fixed count option works. 2 | 3 | Import("env") 4 | 5 | env.NanopbProto("fixed_count") 6 | env.Object("fixed_count.pb.c") 7 | 8 | p = env.Program(["fixed_count_unittests.c", 9 | "fixed_count.pb.c", 10 | "$COMMON/pb_encode.o", 11 | "$COMMON/pb_decode.o", 12 | "$COMMON/pb_common.o"]) 13 | 14 | env.RunTest(p) 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/fixed_count/fixed_count.proto: -------------------------------------------------------------------------------- 1 | /* Test nanopb fixed count option. */ 2 | 3 | syntax = "proto2"; 4 | 5 | import "nanopb.proto"; 6 | 7 | message Message1 8 | { 9 | repeated int32 data = 1 [(nanopb).max_count = 3, (nanopb).fixed_count = true]; 10 | } 11 | 12 | message Message2 13 | { 14 | repeated Message1 data = 1 [(nanopb).max_count = 2, (nanopb).fixed_count = true]; 15 | } 16 | 17 | message Message3 18 | { 19 | repeated Message2 data1 = 1 [(nanopb).max_count = 2, (nanopb).fixed_count = true]; 20 | repeated Message2 data2 = 2 [(nanopb).max_count = 2, (nanopb).fixed_count = true]; 21 | } 22 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/fuzztest/SConscript: -------------------------------------------------------------------------------- 1 | # Run a fuzz test to verify robustness against corrupted/malicious data. 2 | 3 | Import("env", "malloc_env") 4 | 5 | def set_pkgname(src, dst, pkgname): 6 | data = open(str(src)).read() 7 | placeholder = '// package name placeholder' 8 | assert placeholder in data 9 | data = data.replace(placeholder, 'package %s;' % pkgname) 10 | open(str(dst), 'w').write(data) 11 | 12 | # We want both pointer and static versions of the AllTypes message 13 | # Prefix them with package name. 14 | env.Command("alltypes_static.proto", "#alltypes/alltypes.proto", 15 | lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_static')) 16 | env.Command("alltypes_pointer.proto", "#alltypes/alltypes.proto", 17 | lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_pointer')) 18 | 19 | p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"]) 20 | p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"]) 21 | fuzz = malloc_env.Program(["fuzztest.c", 22 | "alltypes_pointer.pb.c", 23 | "alltypes_static.pb.c", 24 | "$COMMON/pb_encode_with_malloc.o", 25 | "$COMMON/pb_decode_with_malloc.o", 26 | "$COMMON/pb_common_with_malloc.o", 27 | "$COMMON/malloc_wrappers.o"]) 28 | 29 | env.RunTest(fuzz) 30 | 31 | fuzzstub = malloc_env.Program(["fuzzstub.c", 32 | "alltypes_pointer.pb.c", 33 | "alltypes_static.pb.c", 34 | "$COMMON/pb_encode_with_malloc.o", 35 | "$COMMON/pb_decode_with_malloc.o", 36 | "$COMMON/pb_common_with_malloc.o", 37 | "$COMMON/malloc_wrappers.o"]) 38 | 39 | generate_message = malloc_env.Program(["generate_message.c", 40 | "alltypes_static.pb.c", 41 | "$COMMON/pb_encode.o", 42 | "$COMMON/pb_common.o"]) 43 | 44 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/fuzztest/alltypes_pointer.options: -------------------------------------------------------------------------------- 1 | # Generate all fields as pointers. 2 | * type:FT_POINTER 3 | *.*fbytes fixed_length:true max_size:4 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/fuzztest/alltypes_static.options: -------------------------------------------------------------------------------- 1 | * max_size:32 2 | * max_count:8 3 | *.extensions type:FT_IGNORE 4 | *.*fbytes fixed_length:true max_size:4 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/fuzztest/run_radamsa.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TMP=`tempfile` 4 | 5 | echo $TMP 6 | while true 7 | do 8 | radamsa sample_data/* > $TMP 9 | $1 < $TMP 10 | test $? -gt 127 && break 11 | done 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/inline/SConscript: -------------------------------------------------------------------------------- 1 | # Test that inlined bytes fields work. 2 | 3 | Import("env") 4 | 5 | env.NanopbProto("inline") 6 | env.Object("inline.pb.c") 7 | 8 | env.Match(["inline.pb.h", "inline.expected"]) 9 | 10 | p = env.Program(["inline_unittests.c", 11 | "inline.pb.c", 12 | "$COMMON/pb_encode.o", 13 | "$COMMON/pb_decode.o", 14 | "$COMMON/pb_common.o"]) 15 | 16 | env.RunTest(p) 17 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/inline/inline.expected: -------------------------------------------------------------------------------- 1 | pb_byte_t data\[32\]; 2 | bool has_data; 3 | pb_byte_t data\[64\]; 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/inline/inline.proto: -------------------------------------------------------------------------------- 1 | /* Test nanopb option parsing. 2 | * options.expected lists the patterns that are searched for in the output. 3 | */ 4 | 5 | syntax = "proto2"; 6 | 7 | import "nanopb.proto"; 8 | 9 | message Message1 10 | { 11 | required bytes data = 1 [(nanopb).type = FT_INLINE, (nanopb).max_size = 32]; 12 | } 13 | 14 | message Message2 15 | { 16 | optional bytes data = 1 [(nanopb).type = FT_INLINE, (nanopb).max_size = 64]; 17 | } 18 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/inline/inline_unittests.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "unittests.h" 6 | #include "inline.pb.h" 7 | 8 | int main() 9 | { 10 | int status = 0; 11 | int i = 0; 12 | COMMENT("Test inline byte fields"); 13 | 14 | { 15 | Message1 msg1 = Message1_init_zero; 16 | TEST(sizeof(msg1.data) == 32); 17 | } 18 | 19 | { 20 | Message1 msg1 = Message1_init_zero; 21 | pb_byte_t msg1_buffer[Message1_size]; 22 | pb_ostream_t ostream = pb_ostream_from_buffer(msg1_buffer, Message1_size); 23 | Message1 msg1_deserialized = Message1_init_zero; 24 | pb_istream_t istream = pb_istream_from_buffer(msg1_buffer, Message1_size); 25 | 26 | for (i = 0; i < 32; i++) { 27 | msg1.data[i] = i; 28 | } 29 | 30 | TEST(pb_encode(&ostream, Message1_fields, &msg1)); 31 | TEST(ostream.bytes_written == Message1_size); 32 | 33 | TEST(pb_decode(&istream, Message1_fields, &msg1_deserialized)); 34 | 35 | TEST(istream.bytes_left == 0); 36 | TEST(memcmp(&msg1_deserialized, &msg1, sizeof(msg1)) == 0); 37 | } 38 | 39 | { 40 | Message2 msg2 = {true, {0}}; 41 | Message2 msg2_no_data = {false, {1}}; 42 | pb_byte_t msg2_buffer[Message2_size]; 43 | pb_ostream_t ostream = pb_ostream_from_buffer(msg2_buffer, Message2_size); 44 | Message2 msg2_deserialized = Message2_init_zero; 45 | pb_istream_t istream = pb_istream_from_buffer(msg2_buffer, Message2_size); 46 | 47 | for (i = 0; i < 64; i++) { 48 | msg2.data[i] = i; 49 | } 50 | 51 | TEST(pb_encode(&ostream, Message2_fields, &msg2)); 52 | TEST(ostream.bytes_written == Message2_size); 53 | 54 | TEST(pb_decode(&istream, Message2_fields, &msg2_deserialized)); 55 | 56 | TEST(istream.bytes_left == 0); 57 | TEST(memcmp(&msg2_deserialized, &msg2, sizeof(msg2)) == 0); 58 | TEST(msg2_deserialized.has_data); 59 | 60 | memset(msg2_buffer, 0, sizeof(msg2_buffer)); 61 | ostream = pb_ostream_from_buffer(msg2_buffer, Message2_size); 62 | TEST(pb_encode(&ostream, Message2_fields, &msg2_no_data)); 63 | istream = pb_istream_from_buffer(msg2_buffer, Message2_size); 64 | TEST(pb_decode(&istream, Message2_fields, &msg2_deserialized)); 65 | TEST(!msg2_deserialized.has_data); 66 | TEST(memcmp(&msg2_deserialized, &msg2, sizeof(msg2)) != 0); 67 | } 68 | 69 | if (status != 0) 70 | fprintf(stdout, "\n\nSome tests FAILED!\n"); 71 | 72 | return status; 73 | } 74 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/intsizes/SConscript: -------------------------------------------------------------------------------- 1 | # Test that the int_size option in .proto works. 2 | 3 | Import('env') 4 | 5 | env.NanopbProto('intsizes') 6 | 7 | p = env.Program(["intsizes_unittests.c", 8 | "intsizes.pb.c", 9 | "$COMMON/pb_encode.o", 10 | "$COMMON/pb_decode.o", 11 | "$COMMON/pb_common.o"]) 12 | env.RunTest(p) 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/intsizes/intsizes.proto: -------------------------------------------------------------------------------- 1 | /* Test the integer size overriding in nanopb options. 2 | * This allows to use 8- and 16-bit integer variables, which are not supported 3 | * directly by Google Protobuf. 4 | * 5 | * The int_size setting will override the number of bits, but keep the type 6 | * otherwise. E.g. uint32 + IS_8 => uint8_t 7 | */ 8 | 9 | syntax = "proto2"; 10 | 11 | import 'nanopb.proto'; 12 | 13 | message IntSizes { 14 | required int32 req_int8 = 1 [(nanopb).int_size = IS_8]; 15 | required uint32 req_uint8 = 2 [(nanopb).int_size = IS_8]; 16 | required sint32 req_sint8 = 3 [(nanopb).int_size = IS_8]; 17 | required int32 req_int16 = 4 [(nanopb).int_size = IS_16]; 18 | required uint32 req_uint16 = 5 [(nanopb).int_size = IS_16]; 19 | required sint32 req_sint16 = 6 [(nanopb).int_size = IS_16]; 20 | required int32 req_int32 = 7 [(nanopb).int_size = IS_32]; 21 | required uint32 req_uint32 = 8 [(nanopb).int_size = IS_32]; 22 | required sint32 req_sint32 = 9 [(nanopb).int_size = IS_32]; 23 | required int32 req_int64 = 10 [(nanopb).int_size = IS_64]; 24 | required uint32 req_uint64 = 11 [(nanopb).int_size = IS_64]; 25 | required sint32 req_sint64 = 12 [(nanopb).int_size = IS_64]; 26 | } 27 | 28 | message DefaultSizes { 29 | required int32 req_int8 = 1 ; 30 | required uint32 req_uint8 = 2 ; 31 | required sint32 req_sint8 = 3 ; 32 | required int32 req_int16 = 4 ; 33 | required uint32 req_uint16 = 5 ; 34 | required sint32 req_sint16 = 6 ; 35 | required int32 req_int32 = 7 ; 36 | required uint32 req_uint32 = 8 ; 37 | required sint32 req_sint32 = 9 ; 38 | required int64 req_int64 = 10; 39 | required uint64 req_uint64 = 11; 40 | required sint64 req_sint64 = 12; 41 | } 42 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/io_errors/SConscript: -------------------------------------------------------------------------------- 1 | # Simulate io errors when encoding and decoding 2 | 3 | Import("env") 4 | 5 | c = Copy("$TARGET", "$SOURCE") 6 | env.Command("alltypes.proto", "#alltypes/alltypes.proto", c) 7 | 8 | env.NanopbProto(["alltypes", "alltypes.options"]) 9 | 10 | ioerr = env.Program(["io_errors.c", "alltypes.pb.c", 11 | "$COMMON/pb_encode.o", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 12 | 13 | env.RunTest("io_errors.output", [ioerr, "$BUILD/alltypes/encode_alltypes.output"]) 14 | 15 | 16 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/io_errors/alltypes.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | *.*fbytes fixed_length:true max_size:4 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/io_errors_pointers/SConscript: -------------------------------------------------------------------------------- 1 | # Simulate io errors when encoding and decoding 2 | 3 | Import("env", "malloc_env") 4 | 5 | c = Copy("$TARGET", "$SOURCE") 6 | env.Command("alltypes.proto", "#alltypes/alltypes.proto", c) 7 | env.Command("io_errors.c", "#io_errors/io_errors.c", c) 8 | 9 | env.NanopbProto(["alltypes", "alltypes.options"]) 10 | 11 | ioerr = env.Program(["io_errors.c", "alltypes.pb.c", 12 | "$COMMON/pb_encode_with_malloc.o", 13 | "$COMMON/pb_decode_with_malloc.o", 14 | "$COMMON/pb_common_with_malloc.o", 15 | "$COMMON/malloc_wrappers.o"]) 16 | 17 | # Run tests under valgrind if available 18 | valgrind = env.WhereIs('valgrind') 19 | kwargs = {} 20 | if valgrind: 21 | kwargs['COMMAND'] = valgrind 22 | kwargs['ARGS'] = ["-q", "--error-exitcode=99", ioerr[0].abspath] 23 | 24 | env.RunTest("io_errors.output", [ioerr, "$BUILD/alltypes/encode_alltypes.output"], **kwargs) 25 | 26 | 27 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/io_errors_pointers/alltypes.options: -------------------------------------------------------------------------------- 1 | # Generate all fields as pointers. 2 | * type:FT_POINTER 3 | *.*fbytes fixed_length:true max_size:4 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/map/SConscript: -------------------------------------------------------------------------------- 1 | # Example / test for handling 'map' type using the backwards compatibility 2 | # in protobuf specification: 3 | # https://developers.google.com/protocol-buffers/docs/proto3#maps 4 | 5 | Import('env') 6 | 7 | env.NanopbProto(['map', 'map.options']) 8 | 9 | enc = env.Program(['encode_map.c', 10 | 'map.pb.c', 11 | '$COMMON/pb_encode.o', 12 | '$COMMON/pb_common.o']) 13 | 14 | dec = env.Program(['decode_map.c', 15 | 'map.pb.c', 16 | '$COMMON/pb_decode.o', 17 | '$COMMON/pb_common.o']) 18 | 19 | env.RunTest("message.pb", enc) 20 | env.RunTest("message.txt", [dec, 'message.pb']) 21 | 22 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/map/decode_map.c: -------------------------------------------------------------------------------- 1 | /* Decode a message using map field */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "map.pb.h" 8 | #include "test_helpers.h" 9 | #include "unittests.h" 10 | 11 | /* Helper function to find an entry in the list. Not as efficient as a real 12 | * hashmap or similar would be, but suitable for small arrays. */ 13 | MyMessage_NumbersEntry *find_entry(MyMessage *msg, const char *key) 14 | { 15 | int i; 16 | for (i = 0; i < msg->numbers_count; i++) 17 | { 18 | if (strcmp(msg->numbers[i].key, key) == 0) 19 | { 20 | return &msg->numbers[i]; 21 | } 22 | } 23 | return NULL; 24 | } 25 | 26 | int main(int argc, char **argv) 27 | { 28 | uint8_t buffer[MyMessage_size]; 29 | size_t count; 30 | 31 | SET_BINARY_MODE(stdin); 32 | count = fread(buffer, 1, sizeof(buffer), stdin); 33 | 34 | if (!feof(stdin)) 35 | { 36 | printf("Message does not fit in buffer\n"); 37 | return 1; 38 | } 39 | 40 | { 41 | int status = 0; 42 | MyMessage msg = MyMessage_init_zero; 43 | MyMessage_NumbersEntry *e; 44 | pb_istream_t stream = pb_istream_from_buffer(buffer, count); 45 | 46 | if (!pb_decode(&stream, MyMessage_fields, &msg)) 47 | { 48 | fprintf(stderr, "Decoding failed\n"); 49 | return 2; 50 | } 51 | 52 | TEST((e = find_entry(&msg, "one")) && e->value == 1); 53 | TEST((e = find_entry(&msg, "two")) && e->value == 2); 54 | TEST((e = find_entry(&msg, "seven")) && e->value == 7); 55 | TEST(!find_entry(&msg, "zero")); 56 | 57 | return status; 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/map/encode_map.c: -------------------------------------------------------------------------------- 1 | /* Encode a message using map field */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include "map.pb.h" 7 | #include "test_helpers.h" 8 | 9 | int main(int argc, char **argv) 10 | { 11 | uint8_t buffer[MyMessage_size]; 12 | MyMessage msg = MyMessage_init_zero; 13 | pb_ostream_t stream; 14 | 15 | /* Fill in the map entries */ 16 | msg.numbers_count = 3; 17 | strncpy(msg.numbers[0].key, "one", sizeof(msg.numbers[0].key)); 18 | strncpy(msg.numbers[1].key, "two", sizeof(msg.numbers[1].key)); 19 | strncpy(msg.numbers[2].key, "seven", sizeof(msg.numbers[2].key)); 20 | msg.numbers[0].value = 1; 21 | msg.numbers[1].value = 2; 22 | msg.numbers[2].value = 7; 23 | 24 | stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 25 | 26 | if (pb_encode(&stream, MyMessage_fields, &msg)) 27 | { 28 | SET_BINARY_MODE(stdout); 29 | fwrite(buffer, 1, stream.bytes_written, stdout); 30 | return 0; 31 | } 32 | else 33 | { 34 | fprintf(stderr, "Encoding failed: %s\n", PB_GET_ERROR(&stream)); 35 | return 1; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/map/map.options: -------------------------------------------------------------------------------- 1 | MyMessage.numbers max_count:10 2 | MyMessage.NumbersEntry.key max_size:16 3 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/map/map.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message MyMessage { 4 | map numbers = 1; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/mem_release/SConscript: -------------------------------------------------------------------------------- 1 | Import("env", "malloc_env") 2 | 3 | env.NanopbProto("mem_release.proto") 4 | 5 | test = malloc_env.Program(["mem_release.c", 6 | "mem_release.pb.c", 7 | "$COMMON/pb_encode_with_malloc.o", 8 | "$COMMON/pb_decode_with_malloc.o", 9 | "$COMMON/pb_common_with_malloc.o", 10 | "$COMMON/malloc_wrappers.o"]) 11 | 12 | env.RunTest(test) 13 | 14 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/mem_release/mem_release.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "nanopb.proto"; 3 | 4 | message SubMessage 5 | { 6 | optional string dynamic_str = 1 [(nanopb).type = FT_POINTER]; 7 | repeated string dynamic_str_arr = 2 [(nanopb).type = FT_POINTER]; 8 | repeated SubMessage dynamic_submsg = 3 [(nanopb).type = FT_POINTER]; 9 | } 10 | 11 | message TestMessage 12 | { 13 | required SubMessage static_req_submsg = 1 [(nanopb).type = FT_STATIC]; 14 | optional SubMessage dynamic_submsg = 2 [(nanopb).type = FT_POINTER]; 15 | optional SubMessage static_opt_submsg = 3 [(nanopb).type = FT_STATIC]; 16 | repeated SubMessage static_rep_submsg = 4 [(nanopb).type = FT_STATIC, (nanopb).max_count=2]; 17 | extensions 100 to 200; 18 | } 19 | 20 | extend TestMessage 21 | { 22 | optional SubMessage dynamic_ext = 100 [(nanopb).type = FT_POINTER]; 23 | optional SubMessage static_ext = 101 [(nanopb).type = FT_STATIC]; 24 | } 25 | 26 | message OneofMessage 27 | { 28 | required int32 first = 1; 29 | oneof msgs 30 | { 31 | TestMessage msg1 = 2; 32 | SubMessage msg2 = 3; 33 | } 34 | required int32 last = 4; 35 | } 36 | 37 | message RepeatedMessage 38 | { 39 | required int32 first = 1; 40 | repeated SubMessage subs = 2; 41 | } 42 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/message_sizes/SConscript: -------------------------------------------------------------------------------- 1 | # Test the generation of message size #defines 2 | 3 | Import('env') 4 | 5 | incpath = env.Clone() 6 | incpath.Append(PROTOCPATH = '#message_sizes') 7 | 8 | incpath.NanopbProto("messages1") 9 | incpath.NanopbProto("messages2") 10 | 11 | incpath.Program(['dummy.c', 'messages1.pb.c', 'messages2.pb.c']) 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/message_sizes/dummy.c: -------------------------------------------------------------------------------- 1 | /* Just test that the file can be compiled successfully. */ 2 | 3 | #include "messages2.pb.h" 4 | 5 | int main() 6 | { 7 | return xmit_size; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/message_sizes/messages1.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | enum MessageStatus { 4 | FAIL = 0; 5 | OK = 1; 6 | }; 7 | 8 | message MessageInfo { 9 | required fixed32 msg_id = 1; 10 | optional fixed32 interface_id = 2; 11 | } 12 | 13 | message MessageResponseInfo { 14 | required fixed64 interface_id = 1; 15 | required fixed32 seq = 2; 16 | required fixed32 msg_id = 3; 17 | } 18 | 19 | message MessageHeader { 20 | required MessageInfo info = 1; 21 | optional MessageResponseInfo response_info = 2; 22 | optional MessageResponse response = 3; 23 | } 24 | 25 | message MessageResponse { 26 | required MessageStatus status = 1; 27 | required fixed32 seq = 2; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/message_sizes/messages2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'nanopb.proto'; 4 | import 'messages1.proto'; 5 | 6 | message xmit { 7 | required MessageHeader header = 1; 8 | required bytes data = 2 [(nanopb).max_size = 128]; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/missing_fields/SConscript: -------------------------------------------------------------------------------- 1 | # Check that the decoder properly detects when required fields are missing. 2 | 3 | Import("env") 4 | 5 | env.NanopbProto("missing_fields") 6 | test = env.Program(["missing_fields.c", "missing_fields.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"]) 7 | env.RunTest(test) 8 | 9 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/missing_fields/missing_fields.c: -------------------------------------------------------------------------------- 1 | /* Checks that missing required fields are detected properly */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include "missing_fields.pb.h" 7 | 8 | int main() 9 | { 10 | uint8_t buffer[512]; 11 | size_t size; 12 | 13 | /* Create a message with one missing field */ 14 | { 15 | MissingField msg = {0}; 16 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 17 | 18 | if (!pb_encode(&stream, MissingField_fields, &msg)) 19 | { 20 | printf("Encode failed.\n"); 21 | return 1; 22 | } 23 | 24 | size = stream.bytes_written; 25 | } 26 | 27 | /* Test that it decodes properly if we don't require that field */ 28 | { 29 | MissingField msg = {0}; 30 | pb_istream_t stream = pb_istream_from_buffer(buffer, size); 31 | 32 | if (!pb_decode(&stream, MissingField_fields, &msg)) 33 | { 34 | printf("Decode failed: %s\n", PB_GET_ERROR(&stream)); 35 | return 2; 36 | } 37 | } 38 | 39 | /* Test that it does *not* decode properly if we require the field */ 40 | { 41 | AllFields msg = {0}; 42 | pb_istream_t stream = pb_istream_from_buffer(buffer, size); 43 | 44 | if (pb_decode(&stream, AllFields_fields, &msg)) 45 | { 46 | printf("Decode didn't detect missing field.\n"); 47 | return 3; 48 | } 49 | } 50 | 51 | return 0; /* All ok */ 52 | } 53 | 54 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/multiple_files/SConscript: -------------------------------------------------------------------------------- 1 | # Test that multiple .proto files don't cause name collisions. 2 | 3 | Import("env") 4 | 5 | incpath = env.Clone() 6 | incpath.Append(PROTOCPATH = '#multiple_files') 7 | incpath.Append(CPPPATH = '$BUILD/multiple_files') 8 | 9 | incpath.NanopbProto(["multifile1", "multifile1.options"]) 10 | incpath.NanopbProto("multifile2") 11 | incpath.NanopbProto("subdir/multifile2") 12 | test = incpath.Program(["test_multiple_files.c", "multifile1.pb.c", 13 | "multifile2.pb.c", "subdir/multifile2.pb.c"]) 14 | 15 | env.RunTest(test) 16 | 17 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/multiple_files/multifile1.options: -------------------------------------------------------------------------------- 1 | StaticMessage.repint32 max_count:5 2 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/multiple_files/multifile1.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message SubMessage { 4 | optional string stringvalue = 1; 5 | repeated int32 int32value = 2; 6 | repeated fixed32 fixed32value = 3; 7 | repeated fixed64 fixed64value = 4; 8 | } 9 | 10 | message TestMessage { 11 | optional string stringvalue = 1; 12 | repeated int32 int32value = 2; 13 | repeated fixed32 fixed32value = 3; 14 | repeated fixed64 fixed64value = 4; 15 | optional SubMessage submsg = 5; 16 | repeated string repeatedstring = 6; 17 | } 18 | 19 | message StaticMessage { 20 | repeated fixed32 repint32 = 1; 21 | } 22 | 23 | enum SignedEnum { 24 | SE_MIN = -128; 25 | SE_MAX = 127; 26 | } 27 | 28 | enum UnsignedEnum { 29 | UE_MIN = 0; 30 | UE_MAX = 255; 31 | } 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/multiple_files/multifile2.proto: -------------------------------------------------------------------------------- 1 | // Test if including generated header file for this file + implicit include of 2 | // multifile2.pb.h still compiles. Used with test_compiles.c. 3 | syntax = "proto2"; 4 | 5 | import "multifile1.proto"; 6 | 7 | message Callback2Message { 8 | required TestMessage tstmsg = 1; 9 | required SubMessage submsg = 2; 10 | } 11 | 12 | message OneofMessage { 13 | oneof msgs { 14 | StaticMessage tstmsg = 1; 15 | } 16 | } 17 | 18 | message Enums { 19 | required SignedEnum senum = 1; 20 | required UnsignedEnum uenum = 2; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/multiple_files/subdir/multifile2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package subdir; 4 | 5 | import "multifile1.proto"; 6 | 7 | message Callback2Message { 8 | required TestMessage tstmsg = 1; 9 | required SubMessage submsg = 2; 10 | } 11 | 12 | message SmallMessage { 13 | required bool dummy = 1; 14 | } 15 | 16 | message OneofMessage { 17 | oneof msgs { 18 | StaticMessage tstmsg = 1; 19 | SmallMessage msg2 = 2; 20 | } 21 | } 22 | 23 | message Enums { 24 | required SignedEnum senum = 1; 25 | required UnsignedEnum uenum = 2; 26 | } 27 | 28 | message SubdirMessage { 29 | required int32 foo = 1 [default = 15]; 30 | } 31 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/multiple_files/test_multiple_files.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tests if this still compiles when multiple .proto files are involved. 3 | */ 4 | 5 | #include 6 | #include 7 | #include "unittests.h" 8 | #include "multifile2.pb.h" 9 | #include "subdir/multifile2.pb.h" 10 | 11 | int main() 12 | { 13 | int status = 0; 14 | 15 | /* Test that included file options are properly loaded */ 16 | TEST(OneofMessage_size == 27); 17 | 18 | /* Check that enum signedness is detected properly */ 19 | TEST(PB_LTYPE(Enums_fields[0].type) == PB_LTYPE_VARINT); 20 | TEST(PB_LTYPE(Enums_fields[1].type) == PB_LTYPE_UVARINT); 21 | 22 | /* Test that subdir file is correctly included */ 23 | { 24 | subdir_SubdirMessage foo = subdir_SubdirMessage_init_default; 25 | TEST(foo.foo == 15); 26 | TEST(subdir_OneofMessage_size >= 27); /* Note: not perfectly accurate due to issue 172 */ 27 | TEST(subdir_OneofMessage_size <= 30); 28 | } 29 | 30 | return status; 31 | } 32 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/no_errmsg/SConscript: -------------------------------------------------------------------------------- 1 | # Run the alltypes test case, but compile with PB_NO_ERRMSG=1 2 | 3 | Import("env") 4 | 5 | # Take copy of the files for custom build. 6 | c = Copy("$TARGET", "$SOURCE") 7 | env.Command("alltypes.pb.h", "$BUILD/alltypes/alltypes.pb.h", c) 8 | env.Command("alltypes.pb.c", "$BUILD/alltypes/alltypes.pb.c", c) 9 | env.Command("encode_alltypes.c", "$BUILD/alltypes/encode_alltypes.c", c) 10 | env.Command("decode_alltypes.c", "$BUILD/alltypes/decode_alltypes.c", c) 11 | 12 | # Define the compilation options 13 | opts = env.Clone() 14 | opts.Append(CPPDEFINES = {'PB_NO_ERRMSG': 1}) 15 | 16 | # Build new version of core 17 | strict = opts.Clone() 18 | strict.Append(CFLAGS = strict['CORECFLAGS']) 19 | strict.Object("pb_decode_noerr.o", "$NANOPB/pb_decode.c") 20 | strict.Object("pb_encode_noerr.o", "$NANOPB/pb_encode.c") 21 | strict.Object("pb_common_noerr.o", "$NANOPB/pb_common.c") 22 | 23 | # Now build and run the test normally. 24 | enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_noerr.o", "pb_common_noerr.o"]) 25 | dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_noerr.o", "pb_common_noerr.o"]) 26 | 27 | env.RunTest(enc) 28 | env.RunTest([dec, "encode_alltypes.output"]) 29 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/no_messages/SConscript: -------------------------------------------------------------------------------- 1 | # Test that a .proto file without any messages compiles fine. 2 | 3 | Import("env") 4 | 5 | env.NanopbProto("no_messages") 6 | env.Object('no_messages.pb.c') 7 | 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/no_messages/no_messages.proto: -------------------------------------------------------------------------------- 1 | /* Test that a file without any messages works. */ 2 | 3 | syntax = "proto2"; 4 | 5 | enum Test { 6 | First = 1; 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/oneof/SConscript: -------------------------------------------------------------------------------- 1 | # Test the 'oneof' feature for generating C unions. 2 | 3 | Import('env') 4 | 5 | import re 6 | 7 | match = None 8 | if 'PROTOC_VERSION' in env: 9 | match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION']) 10 | 11 | if match: 12 | version = list(map(int, match.groups())) 13 | 14 | # Oneof is supported by protoc >= 2.6.0 15 | if env.GetOption('clean') or (match and (version[0] > 2 or (version[0] == 2 and version[1] >= 6))): 16 | env.NanopbProto('oneof') 17 | 18 | enc = env.Program(['encode_oneof.c', 19 | 'oneof.pb.c', 20 | '$COMMON/pb_encode.o', 21 | '$COMMON/pb_common.o']) 22 | 23 | dec = env.Program(['decode_oneof.c', 24 | 'oneof.pb.c', 25 | '$COMMON/pb_decode.o', 26 | '$COMMON/pb_common.o']) 27 | 28 | env.RunTest("message1.pb", enc, ARGS = ['1']) 29 | env.RunTest("message1.txt", [dec, 'message1.pb'], ARGS = ['1']) 30 | env.RunTest("message2.pb", enc, ARGS = ['2']) 31 | env.RunTest("message2.txt", [dec, 'message2.pb'], ARGS = ['2']) 32 | env.RunTest("message3.pb", enc, ARGS = ['3']) 33 | env.RunTest("message3.txt", [dec, 'message3.pb'], ARGS = ['3']) 34 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/oneof/encode_oneof.c: -------------------------------------------------------------------------------- 1 | /* Encode a message using oneof fields */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include "oneof.pb.h" 7 | #include "test_helpers.h" 8 | 9 | int main(int argc, char **argv) 10 | { 11 | uint8_t buffer[OneOfMessage_size]; 12 | OneOfMessage msg = OneOfMessage_init_zero; 13 | pb_ostream_t stream; 14 | int option; 15 | 16 | if (argc != 2) 17 | { 18 | fprintf(stderr, "Usage: encode_oneof [number]\n"); 19 | return 1; 20 | } 21 | option = atoi(argv[1]); 22 | 23 | /* Prefix and suffix are used to test that the union does not disturb 24 | * other fields in the same message. */ 25 | msg.prefix = 123; 26 | 27 | /* We encode one of the 'values' fields based on command line argument */ 28 | if (option == 1) 29 | { 30 | msg.which_values = OneOfMessage_first_tag; 31 | msg.values.first = 999; 32 | } 33 | else if (option == 2) 34 | { 35 | msg.which_values = OneOfMessage_second_tag; 36 | strcpy(msg.values.second, "abcd"); 37 | } 38 | else if (option == 3) 39 | { 40 | msg.which_values = OneOfMessage_third_tag; 41 | msg.values.third.array_count = 5; 42 | msg.values.third.array[0] = 1; 43 | msg.values.third.array[1] = 2; 44 | msg.values.third.array[2] = 3; 45 | msg.values.third.array[3] = 4; 46 | msg.values.third.array[4] = 5; 47 | } 48 | 49 | msg.suffix = 321; 50 | 51 | stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 52 | 53 | if (pb_encode(&stream, OneOfMessage_fields, &msg)) 54 | { 55 | SET_BINARY_MODE(stdout); 56 | fwrite(buffer, 1, stream.bytes_written, stdout); 57 | return 0; 58 | } 59 | else 60 | { 61 | fprintf(stderr, "Encoding failed: %s\n", PB_GET_ERROR(&stream)); 62 | return 1; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/oneof/oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'nanopb.proto'; 4 | 5 | message SubMessage 6 | { 7 | repeated int32 array = 1 [(nanopb).max_count = 8]; 8 | } 9 | 10 | /* Oneof in a message with other fields */ 11 | message OneOfMessage 12 | { 13 | required int32 prefix = 1; 14 | oneof values 15 | { 16 | int32 first = 5; 17 | string second = 6 [(nanopb).max_size = 8]; 18 | SubMessage third = 7; 19 | } 20 | required int32 suffix = 99; 21 | } 22 | 23 | /* Oneof in a message by itself */ 24 | message PlainOneOfMessage 25 | { 26 | oneof values 27 | { 28 | int32 first = 5; 29 | string second = 6 [(nanopb).max_size = 8]; 30 | SubMessage third = 7; 31 | } 32 | } -------------------------------------------------------------------------------- /external/nanopb-master/tests/options/SConscript: -------------------------------------------------------------------------------- 1 | # Test that the generator options work as expected. 2 | 3 | Import("env") 4 | 5 | env.NanopbProto("options") 6 | env.Object('options.pb.c') 7 | env.Match(['options.pb.h', 'options.expected']) 8 | 9 | env.NanopbProto("proto3_options") 10 | env.Object('proto3_options.pb.c') 11 | env.Match(['proto3_options.pb.h', 'proto3_options.expected']) 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/options/options.expected: -------------------------------------------------------------------------------- 1 | char filesize\[20\]; 2 | char msgsize\[30\]; 3 | char fieldsize\[40\]; 4 | char fieldlen\[41\]; 5 | pb_callback_t int32_callback; 6 | \sEnumValue1 = 1 7 | Message5_EnumValue1 8 | } pb_packed my_packed_struct; 9 | ! skipped_field 10 | ! SkippedMessage 11 | #define PB_MSG_103 Message3 12 | #define PB_MSG_104 Message4 13 | #define PB_MSG_105 Message5 14 | #define OPTIONS_MESSAGES \\ 15 | \s+PB_MSG\(103,[0-9]*,Message3\) \\ 16 | \s+PB_MSG\(104,-1,Message4\) \\ 17 | \s+PB_MSG\(105,[0-9]*,Message5\) \\ 18 | #define Message5_msgid 105 19 | ! has_proto3field 20 | 21 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/options/options.proto: -------------------------------------------------------------------------------- 1 | /* Test nanopb option parsing. 2 | * options.expected lists the patterns that are searched for in the output. 3 | */ 4 | 5 | syntax = "proto2"; 6 | 7 | import "nanopb.proto"; 8 | 9 | // File level options 10 | option (nanopb_fileopt).max_size = 20; 11 | 12 | message Message1 13 | { 14 | required string filesize = 1; 15 | } 16 | 17 | // Message level options 18 | message Message2 19 | { 20 | option (nanopb_msgopt).max_size = 30; 21 | required string msgsize = 1; 22 | } 23 | 24 | // Field level options 25 | message Message3 26 | { 27 | option (nanopb_msgopt).msgid = 103; 28 | required string fieldsize = 1 [(nanopb).max_size = 40]; 29 | required string fieldlen = 2 [(nanopb).max_length = 40]; 30 | } 31 | 32 | // Forced callback field 33 | message Message4 34 | { 35 | option (nanopb_msgopt).msgid = 104; 36 | required int32 int32_callback = 1 [(nanopb).type = FT_CALLBACK]; 37 | } 38 | 39 | // Short enum names 40 | enum Enum1 41 | { 42 | option (nanopb_enumopt).long_names = false; 43 | EnumValue1 = 1; 44 | EnumValue2 = 2; 45 | } 46 | 47 | message EnumTest 48 | { 49 | required Enum1 field = 1 [default = EnumValue2]; 50 | } 51 | 52 | // Short enum names inside message 53 | message Message5 54 | { 55 | option (nanopb_msgopt).msgid = 105; 56 | enum Enum2 57 | { 58 | option (nanopb_enumopt).long_names = false; 59 | EnumValue1 = 1; 60 | } 61 | required Enum2 field = 1 [default = EnumValue1]; 62 | } 63 | 64 | // Packed structure 65 | message my_packed_struct 66 | { 67 | option (nanopb_msgopt).packed_struct = true; 68 | optional int32 myfield = 1; 69 | } 70 | 71 | // Message with ignored field 72 | message Message6 73 | { 74 | required int32 field1 = 1; 75 | optional int32 skipped_field = 2 [(nanopb).type = FT_IGNORE]; 76 | } 77 | 78 | // Message that is skipped 79 | message SkippedMessage 80 | { 81 | option (nanopb_msgopt).skip_message = true; 82 | required int32 foo = 1; 83 | } 84 | 85 | // Message with oneof field 86 | message OneofMessage 87 | { 88 | oneof foo { 89 | int32 bar = 1; 90 | } 91 | } 92 | 93 | // Proto3-style optional field in proto2 file 94 | message Proto3Field 95 | { 96 | optional int32 proto3field = 1 [(nanopb).proto3 = true]; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/options/proto3_options.expected: -------------------------------------------------------------------------------- 1 | ! bool has_proto3_default 2 | bool has_proto3_off 3 | ! bool has_proto3_on 4 | 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/options/proto3_options.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "nanopb.proto"; 4 | 5 | message Message1 6 | { 7 | int32 proto3_default = 1; 8 | int32 proto3_off = 2 [(nanopb).proto3 = false]; 9 | int32 proto3_on = 3 [(nanopb).proto3 = true]; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/package_name/SConscript: -------------------------------------------------------------------------------- 1 | # Check that alltypes test case works also when the .proto file defines 2 | # a package name. 3 | 4 | Import("env") 5 | 6 | def set_pkgname(src, dst, pkgname): 7 | data = open(str(src)).read() 8 | placeholder = '// package name placeholder' 9 | assert placeholder in data 10 | data = data.replace(placeholder, 'package %s;' % pkgname) 11 | open(str(dst), 'w').write(data) 12 | 13 | # Build a modified alltypes.proto 14 | env.Command("alltypes.proto", "#alltypes/alltypes.proto", 15 | lambda target, source, env: set_pkgname(source[0], target[0], 'test.package')) 16 | env.Command("alltypes.options", "#alltypes/alltypes.options", Copy("$TARGET", "$SOURCE")) 17 | env.NanopbProto(["alltypes", "alltypes.options"]) 18 | 19 | # Build a modified encode_alltypes.c 20 | def modify_c(target, source, env): 21 | '''Add package name to type names in .c file.''' 22 | 23 | data = open(str(source[0]), 'r').read() 24 | 25 | type_names = ['AllTypes', 'MyEnum', 'HugeEnum'] 26 | for name in type_names: 27 | data = data.replace(name, 'test_package_' + name) 28 | 29 | open(str(target[0]), 'w').write(data) 30 | return 0 31 | env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", modify_c) 32 | 33 | # Encode and compare results to original alltypes testcase 34 | enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) 35 | refdec = "$BUILD/alltypes/decode_alltypes$PROGSUFFIX" 36 | env.RunTest(enc) 37 | env.Compare(["encode_alltypes.output", "$BUILD/alltypes/encode_alltypes.output"]) 38 | 39 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_118/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 118: Short enum names in imported proto files are not honoured 2 | 3 | Import("env") 4 | env = env.Clone() 5 | env.Append(PROTOCPATH = "#regression/issue_118") 6 | 7 | env.NanopbProto("enumdef") 8 | env.Object('enumdef.pb.c') 9 | 10 | env.NanopbProto(["enumuse", "enumdef.proto"]) 11 | env.Object('enumuse.pb.c') 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_118/enumdef.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'nanopb.proto'; 4 | 5 | enum MyEnum { 6 | option (nanopb_enumopt).long_names = false; 7 | FOOBAR = 1; 8 | } 9 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_118/enumuse.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'enumdef.proto'; 4 | 5 | message MyMessage { 6 | required MyEnum myenum = 1 [default = FOOBAR]; 7 | } 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_125/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 125: Wrong identifier name for extension fields 2 | 3 | Import("env") 4 | 5 | env.NanopbProto(["extensionbug", "extensionbug.options"]) 6 | env.Object('extensionbug.pb.c') 7 | 8 | env.Match(['extensionbug.pb.h', 'extensionbug.expected']) 9 | 10 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_125/extensionbug.expected: -------------------------------------------------------------------------------- 1 | pb_extension_type_t Message2_extras 2 | uint32_t field2 3 | 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_125/extensionbug.options: -------------------------------------------------------------------------------- 1 | * type:FT_IGNORE 2 | 3 | Message2.extras type:FT_STATIC 4 | Message2.field2 type:FT_STATIC 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_125/extensionbug.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message Message1 4 | { 5 | optional uint32 fieldA = 1; 6 | extensions 30 to max; 7 | } 8 | 9 | message Message2 10 | { 11 | extend Message1 12 | { 13 | optional Message2 extras = 30; 14 | } 15 | 16 | optional uint32 field1 = 1; 17 | optional uint32 field2 = 2; 18 | } 19 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_141/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for issue 141: wrong encoded size #define for oneof messages 2 | 3 | Import("env") 4 | 5 | env.NanopbProto("testproto") 6 | env.Object('testproto.pb.c') 7 | env.Match(['testproto.pb.h', 'testproto.expected']) 8 | 9 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_141/testproto.expected: -------------------------------------------------------------------------------- 1 | define SubMessage_size \s* 88 2 | define OneOfMessage_size \s* 113 3 | define topMessage_size \s* 70 4 | define MyMessage1_size \s* 46 5 | define MyMessage2_size \s* 8 6 | define MyMessage3_size \s* 5 7 | define MyMessage4_size \s* 18 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_141/testproto.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import 'nanopb.proto'; 4 | 5 | message SubMessage 6 | { 7 | repeated int32 array = 1 [(nanopb).max_count = 8]; 8 | } 9 | 10 | message OneOfMessage 11 | { 12 | required int32 prefix = 1; 13 | oneof values 14 | { 15 | int32 first = 5; 16 | string second = 6 [(nanopb).max_size = 8]; 17 | SubMessage third = 7; 18 | } 19 | required int32 suffix = 99; 20 | } 21 | 22 | message topMessage { 23 | required int32 start = 1; 24 | oneof msg { 25 | MyMessage1 msg1 = 2; 26 | MyMessage2 msg2 = 3; 27 | } 28 | required int32 end = 4; 29 | } 30 | 31 | message MyMessage1 { 32 | required uint32 n1 = 1; 33 | required uint32 n2 = 2; 34 | required string s = 3 [(nanopb).max_size = 32]; 35 | } 36 | 37 | message MyMessage2 { 38 | required uint32 num = 1; 39 | required bool b = 2; 40 | } 41 | 42 | message MyMessage3 { 43 | required bool bbb = 1; 44 | required string ss = 2 [(nanopb).max_size = 1]; 45 | } 46 | 47 | message MyMessage4 { 48 | required bool bbbb = 1; 49 | required string sss = 2 [(nanopb).max_size = 2]; 50 | required uint32 num = 3; 51 | required uint32 num2 = 4; 52 | } 53 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_145/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 145: Allow /* */ and // comments in .options files 2 | 3 | Import("env") 4 | 5 | env.NanopbProto(["comments", "comments.options"]) 6 | env.Object('comments.pb.c') 7 | 8 | env.Match(['comments.pb.h', 'comments.expected']) 9 | 10 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_145/comments.expected: -------------------------------------------------------------------------------- 1 | char foo\[5\]; 2 | char bar\[16\]; 3 | 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_145/comments.options: -------------------------------------------------------------------------------- 1 | /* Block comment */ 2 | # Line comment 3 | // Line comment 4 | DummyMessage.foo /* Block comment */ max_size:5 5 | DummyMessage.bar max_size:16 # Line comment ### 6 | 7 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_145/comments.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message DummyMessage { 4 | required string foo = 1; 5 | required string bar = 2; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_166/SConscript: -------------------------------------------------------------------------------- 1 | # Verify that the maximum encoded size is calculated properly 2 | # for enums. 3 | 4 | Import('env') 5 | 6 | env.NanopbProto('enums') 7 | 8 | p = env.Program(["enum_encoded_size.c", 9 | "enums.pb.c", 10 | "$COMMON/pb_encode.o", 11 | "$COMMON/pb_common.o"]) 12 | env.RunTest(p) 13 | 14 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_166/enum_encoded_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "unittests.h" 5 | #include "enums.pb.h" 6 | 7 | int main() 8 | { 9 | int status = 0; 10 | 11 | uint8_t buf[256]; 12 | SignedMsg msg1; 13 | UnsignedMsg msg2; 14 | pb_ostream_t s; 15 | 16 | { 17 | COMMENT("Test negative value of signed enum"); 18 | /* Negative value should take up the maximum size */ 19 | msg1.value = SignedEnum_SE_MIN; 20 | s = pb_ostream_from_buffer(buf, sizeof(buf)); 21 | TEST(pb_encode(&s, SignedMsg_fields, &msg1)); 22 | TEST(s.bytes_written == SignedMsg_size); 23 | 24 | COMMENT("Test positive value of signed enum"); 25 | /* Positive value should be smaller */ 26 | msg1.value = SignedEnum_SE_MAX; 27 | s = pb_ostream_from_buffer(buf, sizeof(buf)); 28 | TEST(pb_encode(&s, SignedMsg_fields, &msg1)); 29 | TEST(s.bytes_written < SignedMsg_size); 30 | } 31 | 32 | { 33 | COMMENT("Test positive value of unsigned enum"); 34 | /* This should take up the maximum size */ 35 | msg2.value = UnsignedEnum_UE_MAX; 36 | s = pb_ostream_from_buffer(buf, sizeof(buf)); 37 | TEST(pb_encode(&s, UnsignedMsg_fields, &msg2)); 38 | TEST(s.bytes_written == UnsignedMsg_size); 39 | } 40 | 41 | return status; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_166/enums.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | enum SignedEnum { 4 | SE_MIN = -1; 5 | SE_MAX = 255; 6 | } 7 | 8 | enum UnsignedEnum { 9 | UE_MAX = 65536; 10 | } 11 | 12 | message SignedMsg { 13 | required SignedEnum value = 1; 14 | } 15 | 16 | message UnsignedMsg { 17 | required UnsignedEnum value = 1; 18 | } 19 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_172/SConscript: -------------------------------------------------------------------------------- 1 | # Verify that _size define is generated for messages that have 2 | # includes from another directory. 3 | 4 | Import('env') 5 | 6 | incpath = env.Clone() 7 | incpath.Append(PROTOCPATH="#regression/issue_172/submessage") 8 | incpath.Append(CPPPATH="$BUILD/regression/issue_172/submessage") 9 | incpath.NanopbProto('test') 10 | incpath.NanopbProto(['submessage/submessage', 'submessage/submessage.options']) 11 | 12 | p = incpath.Program(["msg_size.c", 13 | "test.pb.c", 14 | "submessage/submessage.pb.c"]) 15 | 16 | 17 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_172/msg_size.c: -------------------------------------------------------------------------------- 1 | #include "test.pb.h" 2 | 3 | PB_STATIC_ASSERT(testmessage_size >= 1+1+1+1+16, TESTMESSAGE_SIZE_IS_WRONG) 4 | 5 | int main() 6 | { 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_172/submessage/submessage.options: -------------------------------------------------------------------------------- 1 | submessage.data max_size: 16 2 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_172/submessage/submessage.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | message submessage { 3 | required bytes data = 1; 4 | } 5 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_172/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "submessage.proto"; 3 | 4 | message testmessage { 5 | optional submessage sub = 1; 6 | } 7 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_188/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for issue with Enums inside OneOf. 2 | 3 | Import('env') 4 | 5 | env.NanopbProto('oneof') 6 | 7 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_188/oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message MessageOne 4 | { 5 | required uint32 one = 1; 6 | required uint32 two = 2; 7 | required uint32 three = 3; 8 | required int32 four = 4; 9 | } 10 | 11 | enum EnumTwo 12 | { 13 | SOME_ENUM_1 = 1; 14 | SOME_ENUM_2 = 5; 15 | SOME_ENUM_3 = 6; 16 | SOME_ENUM_4 = 9; 17 | SOME_ENUM_5 = 10; 18 | SOME_ENUM_6 = 12; 19 | SOME_ENUM_7 = 39; 20 | SOME_ENUM_8 = 401; 21 | } 22 | 23 | message OneofMessage 24 | { 25 | oneof payload { 26 | MessageOne message = 1; 27 | EnumTwo enum = 2; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_195/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 195: Message size not calculated if a submessage includes 2 | # bytes. Basically a non-working #define being generated. 3 | 4 | Import("env") 5 | 6 | env.NanopbProto(["test"]) 7 | env.Object('test.pb.c') 8 | 9 | env.Match(['test.pb.h', 'test.expected']) 10 | 11 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_195/test.expected: -------------------------------------------------------------------------------- 1 | /\* TestMessage_size depends 2 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_195/test.proto: -------------------------------------------------------------------------------- 1 | message TestMessage { 2 | required uint32 id = 1; 3 | required bytes payload = 2; 4 | } 5 | message EncapsulatedMessage { 6 | required uint32 id = 1; 7 | required TestMessage test = 2; 8 | } 9 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_203/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for issue with multiple files generated at once 2 | 3 | Import('env') 4 | 5 | env.Command(['file1.pb.c', 'file1.pb.h', 'file2.pb.c', 'file2.pb.h'], ['file1.proto', 'file2.proto'], 6 | env['NANOPB_PROTO_CMD']) 7 | 8 | env.Object('file1.pb.c') 9 | env.Object('file2.pb.c') 10 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_203/file1.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message SubMessage1 { 4 | required int32 foo = 1; 5 | } 6 | 7 | message Message1 { 8 | required SubMessage1 bar = 1; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_203/file2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message SubMessage2 { 4 | required int32 foo = 1; 5 | } 6 | 7 | message Message2 { 8 | required SubMessage2 bar = 1; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_205/SConscript: -------------------------------------------------------------------------------- 1 | # Check that pb_release() correctly handles corrupted size fields of 2 | # static arrays. 3 | 4 | Import('env', 'malloc_env') 5 | 6 | env.NanopbProto('size_corruption') 7 | 8 | p = malloc_env.Program(["size_corruption.c", 9 | "size_corruption.pb.c", 10 | "$COMMON/pb_decode_with_malloc.o", 11 | "$COMMON/pb_common_with_malloc.o", 12 | "$COMMON/malloc_wrappers.o"]) 13 | env.RunTest(p) 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_205/size_corruption.c: -------------------------------------------------------------------------------- 1 | #include "size_corruption.pb.h" 2 | #include 3 | 4 | int main() 5 | { 6 | MainMessage msg = MainMessage_init_zero; 7 | msg.bar_count = (pb_size_t)-1; 8 | pb_release(MainMessage_fields, &msg); 9 | 10 | return 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_205/size_corruption.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import 'nanopb.proto'; 3 | 4 | message SubMessage { 5 | repeated int32 foo = 1 [(nanopb).type = FT_POINTER]; 6 | } 7 | 8 | message MainMessage { 9 | repeated SubMessage bar = 1 [(nanopb).max_count = 5]; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_227/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 227:Using proto3 type fields can cause unaligned access 2 | # NOTE: This test will only detect problems when run with clang sanitizer (which 3 | # is done regularly by a jenkins run). 4 | 5 | Import('env') 6 | 7 | env.NanopbProto('unaligned_uint64') 8 | 9 | p = env.Program(["unaligned_uint64.c", 10 | "unaligned_uint64.pb.c", 11 | "$COMMON/pb_encode.o", 12 | "$COMMON/pb_common.o"]) 13 | env.RunTest(p) 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_227/unaligned_uint64.c: -------------------------------------------------------------------------------- 1 | #include "unaligned_uint64.pb.h" 2 | #include 3 | 4 | int main() 5 | { 6 | uint8_t buf[128]; 7 | pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); 8 | MainMessage msg = MainMessage_init_zero; 9 | msg.bar[0] = 'A'; 10 | pb_encode(&stream, MainMessage_fields, &msg); 11 | 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_227/unaligned_uint64.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | import 'nanopb.proto'; 3 | 4 | message MainMessage { 5 | string foo = 1 [(nanopb).max_size = 3]; 6 | string bar = 2 [(nanopb).max_size = 8]; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_229/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 229: problem encoding message that has 2 | # multiple oneof fields 3 | Import('env') 4 | 5 | env.NanopbProto('multiple_oneof') 6 | 7 | p = env.Program(["multiple_oneof.c", 8 | "multiple_oneof.pb.c", 9 | "$COMMON/pb_decode.o", 10 | "$COMMON/pb_encode.o", 11 | "$COMMON/pb_common.o"]) 12 | env.RunTest(p) 13 | 14 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_229/multiple_oneof.c: -------------------------------------------------------------------------------- 1 | #include "multiple_oneof.pb.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int status = 0; 9 | uint8_t buf[128]; 10 | size_t msglen; 11 | 12 | { 13 | pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); 14 | MainMessage msg = MainMessage_init_zero; 15 | msg.which_oneof1 = MainMessage_oneof1_uint32_tag; 16 | msg.oneof1.oneof1_uint32 = 1234; 17 | msg.which_oneof2 = MainMessage_oneof2_uint32_tag; 18 | msg.oneof2.oneof2_uint32 = 5678; 19 | TEST(pb_encode(&stream, MainMessage_fields, &msg)); 20 | msglen = stream.bytes_written; 21 | } 22 | 23 | { 24 | pb_istream_t stream = pb_istream_from_buffer(buf, msglen); 25 | MainMessage msg = MainMessage_init_zero; 26 | TEST(pb_decode(&stream, MainMessage_fields, &msg)); 27 | TEST(msg.which_oneof1 == MainMessage_oneof1_uint32_tag); 28 | TEST(msg.oneof1.oneof1_uint32 == 1234); 29 | TEST(msg.which_oneof2 == MainMessage_oneof2_uint32_tag); 30 | TEST(msg.oneof2.oneof2_uint32 == 5678); 31 | } 32 | 33 | return status; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_229/multiple_oneof.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message MainMessage { 4 | oneof oneof1 { 5 | uint32 oneof1_uint32 = 1; 6 | } 7 | oneof oneof2 { 8 | uint32 oneof2_uint32 = 2; 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_242/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 242: pb_encode does not encode tag for 2 | # extension fields that is all zeros 3 | Import('env') 4 | 5 | env.NanopbProto('zero_value') 6 | 7 | p = env.Program(["zero_value.c", 8 | "zero_value.pb.c", 9 | "$COMMON/pb_decode.o", 10 | "$COMMON/pb_encode.o", 11 | "$COMMON/pb_common.o"]) 12 | env.RunTest(p) 13 | 14 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_242/zero_value.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "zero_value.pb.h" 6 | 7 | int main() 8 | { 9 | int status = 0; 10 | 11 | COMMENT("Test extension fields with zero values"); 12 | { 13 | uint8_t buffer[256] = {0}; 14 | pb_ostream_t ostream; 15 | int32_t value = 0; 16 | Extendable source = {0}; 17 | 18 | pb_extension_t source_ext = {0}; 19 | source_ext.type = &opt_int32; 20 | source_ext.dest = &value; 21 | source.extensions = &source_ext; 22 | 23 | ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 24 | TEST(pb_encode(&ostream, Extendable_fields, &source)); 25 | 26 | TEST(ostream.bytes_written == 2); 27 | TEST(memcmp(buffer, "\x58\x00", 2) == 0); 28 | } 29 | 30 | /* Note: There never was a bug here, but this check is included 31 | * in the regression test because the logic is closely related. 32 | */ 33 | COMMENT("Test pointer fields with zero values"); 34 | { 35 | uint8_t buffer[256] = {0}; 36 | pb_ostream_t ostream; 37 | int32_t value = 0; 38 | PointerMessage source = {0}; 39 | 40 | source.opt_int32 = &value; 41 | 42 | ostream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 43 | TEST(pb_encode(&ostream, PointerMessage_fields, &source)); 44 | 45 | TEST(ostream.bytes_written == 2); 46 | TEST(memcmp(buffer, "\x58\x00", 2) == 0); 47 | } 48 | 49 | return status; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_242/zero_value.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "nanopb.proto"; 3 | 4 | message Extendable { 5 | extensions 10 to 100; 6 | } 7 | 8 | extend Extendable { 9 | optional int32 opt_int32 = 11; 10 | } 11 | 12 | message PointerMessage { 13 | optional int32 opt_int32 = 11 [(nanopb).type = FT_POINTER]; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_247/SConscript: -------------------------------------------------------------------------------- 1 | # Test that pb_check_proto3_default_value() correctly skips padding 2 | # bytes in submessage structures. 3 | 4 | Import("env") 5 | 6 | env.NanopbProto("padding") 7 | 8 | p = env.Program(["padding.c", 9 | "padding.pb.c", 10 | "$COMMON/pb_encode.o", 11 | "$COMMON/pb_common.o"]) 12 | 13 | env.RunTest(p) 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_247/padding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "padding.pb.h" 5 | 6 | int main() 7 | { 8 | int status = 0; 9 | 10 | TestMessage msg; 11 | 12 | /* Set padding bytes to garbage */ 13 | memset(&msg, 0xAA, sizeof(msg)); 14 | 15 | /* Set all meaningful fields to 0 */ 16 | msg.submsg.boolfield = false; 17 | msg.submsg.intfield = 0; 18 | 19 | /* Test encoding */ 20 | { 21 | pb_byte_t buf[128] = {0}; 22 | pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); 23 | TEST(pb_encode(&stream, TestMessage_fields, &msg)); 24 | 25 | /* Because all fields have zero values, proto3 encoder 26 | * shouldn't write out anything. */ 27 | TEST(stream.bytes_written == 0); 28 | } 29 | 30 | return status; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_247/padding.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | import "nanopb.proto"; 3 | 4 | message SubMessage { 5 | bool boolfield = 1; 6 | int64 intfield = 2; 7 | } 8 | 9 | message TestMessage { 10 | SubMessage submsg = 1; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_249/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 249: proto3 mode pb_decode() corrupts callback fields 2 | Import('env') 3 | 4 | env.NanopbProto('test') 5 | 6 | p = env.Program(["test.c", 7 | "test.pb.c", 8 | "$COMMON/pb_decode.o", 9 | "$COMMON/pb_encode.o", 10 | "$COMMON/pb_common.o"]) 11 | env.RunTest(p) 12 | 13 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_249/test.c: -------------------------------------------------------------------------------- 1 | #include "test.pb.h" 2 | #include 3 | #include 4 | #include 5 | 6 | static bool write_array(pb_ostream_t *stream, const pb_field_t *field, void * const *arg) 7 | { 8 | int i; 9 | for (i = 0; i < 5; i++) 10 | { 11 | if (!pb_encode_tag_for_field(stream, field)) 12 | return false; 13 | if (!pb_encode_varint(stream, 1000 + i)) 14 | return false; 15 | } 16 | 17 | return true; 18 | } 19 | 20 | static bool read_array(pb_istream_t *stream, const pb_field_t *field, void **arg) 21 | { 22 | uint32_t i; 23 | int *sum = *arg; 24 | 25 | if (!pb_decode_varint32(stream, &i)) 26 | return false; 27 | 28 | *sum += i; 29 | 30 | return true; 31 | } 32 | 33 | int main() 34 | { 35 | int status = 0; 36 | pb_byte_t buf[128] = {0}; 37 | pb_size_t msglen; 38 | 39 | { 40 | MainMessage msg = MainMessage_init_zero; 41 | pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf)); 42 | msg.submsg.foo.funcs.encode = &write_array; 43 | TEST(pb_encode(&stream, MainMessage_fields, &msg)); 44 | msglen = stream.bytes_written; 45 | } 46 | 47 | { 48 | MainMessage msg = MainMessage_init_zero; 49 | pb_istream_t stream = pb_istream_from_buffer(buf, msglen); 50 | int sum = 0; 51 | msg.submsg.foo.funcs.decode = &read_array; 52 | msg.submsg.foo.arg = ∑ 53 | TEST(pb_decode(&stream, MainMessage_fields, &msg)); 54 | TEST(sum == 1000 + 1001 + 1002 + 1003 + 1004); 55 | } 56 | 57 | return status; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_249/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message SubMessage { 4 | repeated int32 foo = 1; 5 | } 6 | 7 | message MainMessage { 8 | SubMessage submsg = 1; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_253/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 253: Wrong calculated message maximum size 2 | 3 | Import('env') 4 | 5 | env.NanopbProto('short_array') 6 | 7 | p = env.Program(['short_array.c', 8 | 'short_array.pb.c', 9 | "$COMMON/pb_decode.o", 10 | "$COMMON/pb_encode.o", 11 | "$COMMON/pb_common.o"]) 12 | 13 | env.RunTest(p) 14 | 15 | 16 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_253/short_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "short_array.pb.h" 4 | 5 | int main() 6 | { 7 | int status = 0; 8 | 9 | COMMENT("Test message length calculation for short arrays"); 10 | { 11 | uint8_t buffer[TestMessage_size] = {0}; 12 | pb_ostream_t ostream = pb_ostream_from_buffer(buffer, TestMessage_size); 13 | TestMessage msg = TestMessage_init_zero; 14 | 15 | msg.rep_uint32_count = 1; 16 | msg.rep_uint32[0] = (1 << 31); 17 | 18 | TEST(pb_encode(&ostream, TestMessage_fields, &msg)); 19 | TEST(ostream.bytes_written == TestMessage_size); 20 | } 21 | 22 | return status; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_253/short_array.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "nanopb.proto"; 3 | 4 | message TestMessage { 5 | repeated uint32 rep_uint32 = 1 [(nanopb).max_count = 1]; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_256/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for Issue 256: Proto3 mode skips submessages even when 2 | # later array fields have non-zero value 3 | 4 | Import('env') 5 | 6 | env.NanopbProto('submsg_array') 7 | 8 | p = env.Program(['submsg_array.c', 9 | 'submsg_array.pb.c', 10 | "$COMMON/pb_decode.o", 11 | "$COMMON/pb_encode.o", 12 | "$COMMON/pb_common.o"]) 13 | 14 | env.RunTest(p) 15 | 16 | 17 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_256/submsg_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "submsg_array.pb.h" 5 | 6 | int main() 7 | { 8 | int status = 0; 9 | 10 | COMMENT("Test encoding for submessage with array"); 11 | { 12 | uint8_t buffer[TestMessage_size] = {0}; 13 | pb_ostream_t ostream = pb_ostream_from_buffer(buffer, TestMessage_size); 14 | TestMessage msg = TestMessage_init_zero; 15 | 16 | msg.submsg.rep_uint32_count = 3; 17 | msg.submsg.rep_uint32[0] = 0; 18 | msg.submsg.rep_uint32[1] = 1; 19 | msg.submsg.rep_uint32[2] = 2; 20 | 21 | TEST(pb_encode(&ostream, TestMessage_fields, &msg)); 22 | TEST(ostream.bytes_written > 0); 23 | 24 | { 25 | pb_istream_t istream = pb_istream_from_buffer(buffer, ostream.bytes_written); 26 | TestMessage msg2 = TestMessage_init_zero; 27 | 28 | TEST(pb_decode(&istream, TestMessage_fields, &msg2)); 29 | TEST(msg2.submsg.rep_uint32_count == 3); 30 | TEST(msg2.submsg.rep_uint32[0] == 0); 31 | TEST(msg2.submsg.rep_uint32[1] == 1); 32 | TEST(msg2.submsg.rep_uint32[2] == 2); 33 | } 34 | } 35 | 36 | return status; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_256/submsg_array.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | import "nanopb.proto"; 3 | 4 | message SubMessage { 5 | repeated uint32 rep_uint32 = 1 [(nanopb).max_count = 3]; 6 | } 7 | 8 | message TestMessage { 9 | SubMessage submsg = 1; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_259/SConscript: -------------------------------------------------------------------------------- 1 | # Check that callback fields inside malloc()ed messages 2 | # are correctly initialized. 3 | 4 | Import('env', 'malloc_env') 5 | 6 | env.NanopbProto('callback_pointer') 7 | 8 | p = malloc_env.Program(["callback_pointer.c", 9 | "callback_pointer.pb.c", 10 | "$COMMON/pb_decode_with_malloc.o", 11 | "$COMMON/pb_common_with_malloc.o", 12 | "$COMMON/malloc_wrappers.o"]) 13 | 14 | # Run test under valgrind if available 15 | valgrind = env.WhereIs('valgrind') 16 | kwargs = {} 17 | if valgrind: 18 | kwargs['COMMAND'] = valgrind 19 | kwargs['ARGS'] = ["-q", "--error-exitcode=99", p[0].abspath] 20 | 21 | env.RunTest(p, **kwargs) 22 | 23 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_259/callback_pointer.c: -------------------------------------------------------------------------------- 1 | #include "callback_pointer.pb.h" 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int status = 0; 8 | const uint8_t msgdata[] = {0x0A, 0x02, 0x08, 0x7F}; 9 | 10 | MainMessage msg = MainMessage_init_zero; 11 | 12 | { 13 | pb_istream_t stream = pb_istream_from_buffer(msgdata, sizeof(msgdata)); 14 | COMMENT("Running first decode"); 15 | TEST(pb_decode(&stream, MainMessage_fields, &msg)); 16 | pb_release(MainMessage_fields, &msg); 17 | } 18 | 19 | { 20 | pb_istream_t stream = pb_istream_from_buffer(msgdata, sizeof(msgdata)); 21 | COMMENT("Running second decode"); 22 | TEST(pb_decode(&stream, MainMessage_fields, &msg)); 23 | pb_release(MainMessage_fields, &msg); 24 | } 25 | 26 | TEST(get_alloc_count() == 0); 27 | 28 | return status; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_259/callback_pointer.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import 'nanopb.proto'; 3 | 4 | message SubMessage { 5 | optional int32 foo = 1 [(nanopb).type = FT_CALLBACK]; 6 | } 7 | 8 | message MainMessage { 9 | optional SubMessage bar = 1 [(nanopb).type = FT_POINTER]; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_306/SConscript: -------------------------------------------------------------------------------- 1 | # Check that generator gives a warning about large extension field number. 2 | 3 | Import('env') 4 | 5 | env.NanopbProto('large_extension') 6 | 7 | env.Match(['large_extension.pb.c', 'large_extension.expected']) 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_306/large_extension.expected: -------------------------------------------------------------------------------- 1 | PB_FIELD_32BIT 2 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_306/large_extension.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message Foo { 4 | extensions 1 to max; 5 | } 6 | 7 | extend Foo { 8 | optional int32 foo_ext = 99999; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_322/SConscript: -------------------------------------------------------------------------------- 1 | # Check that default values with special characters are 2 | # correctly handled. 3 | 4 | Import('env') 5 | 6 | env.NanopbProto('defaults') 7 | 8 | p = env.Program(["defaults.c", 9 | "defaults.pb.c", 10 | "$COMMON/pb_decode.o", 11 | "$COMMON/pb_common.o"]) 12 | 13 | env.RunTest(p) 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_322/defaults.c: -------------------------------------------------------------------------------- 1 | #include "defaults.pb.h" 2 | #include 3 | #include 4 | 5 | int check_defaults(const DefaultsMsg *msg) 6 | { 7 | int status = 0; 8 | 9 | TEST(msg->b1[0] == 0xDE && msg->b1[1] == 0xAD && msg->b1[2] == 0x00 && 10 | msg->b1[3] == 0xBE && msg->b1[4] == 0xEF); 11 | TEST(msg->b2.bytes[0] == 0xDE && msg->b2.bytes[1] == 0xAD && 12 | msg->b2.bytes[2] == 0x00 && msg->b2.bytes[3] == 0xBE && 13 | msg->b2.bytes[4] == 0xEF && msg->b2.size == 5); 14 | TEST(msg->b3.bytes[0] == 0xDE && msg->b3.bytes[1] == 0xAD && 15 | msg->b3.bytes[2] == 0x00 && msg->b3.bytes[3] == 0xBE && 16 | msg->b3.bytes[4] == 0xEF && msg->b2.size == 5); 17 | TEST(msg->s1[0] == (char)0xC3 && msg->s1[1] == (char)0xA4 && 18 | msg->s1[2] == (char)0xC3 && msg->s1[3] == (char)0xB6 && 19 | msg->s1[4] == '\0'); 20 | 21 | return status; 22 | } 23 | 24 | int main() 25 | { 26 | int status = 0; 27 | 28 | { 29 | DefaultsMsg msg = DefaultsMsg_init_default; 30 | COMMENT("Checking defaults from static initializer"); 31 | status += check_defaults(&msg); 32 | } 33 | 34 | { 35 | DefaultsMsg msg = DefaultsMsg_init_zero; 36 | pb_istream_t empty = {0,0,0}; 37 | pb_decode(&empty, DefaultsMsg_fields, &msg); 38 | COMMENT("Checking defaults set at runtime"); 39 | status += check_defaults(&msg); 40 | } 41 | 42 | return status; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_322/defaults.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import 'nanopb.proto'; 3 | 4 | message DefaultsMsg { 5 | optional bytes b1 = 1 [default = "\xDE\xAD\x00\xBE\xEF", (nanopb).max_size = 5, (nanopb).fixed_length=true]; 6 | optional bytes b2 = 2 [default = "\xDE\xAD\x00\xBE\xEF", (nanopb).max_size = 5]; 7 | optional bytes b3 = 3 [default = "\xDE\xAD\000\xBE\xEF", (nanopb).max_size = 15]; 8 | optional string s1 = 4 [default = "äö", (nanopb).max_size = 8]; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_338/SConscript: -------------------------------------------------------------------------------- 1 | # Check that generator doesn't exceed memory limits 2 | 3 | Import('env') 4 | 5 | env.NanopbProto('bigvalue') 6 | 7 | 8 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_342/SConscript: -------------------------------------------------------------------------------- 1 | # Regression test for #342: 2 | # Possible null-pointer dereference in pb_decode.c 3 | 4 | Import("env") 5 | 6 | # Define the compilation options 7 | opts = env.Clone() 8 | opts.Append(CPPDEFINES = {'PB_OLD_CALLBACK_STYLE': 1}) 9 | 10 | # Build new version of core 11 | strict = opts.Clone() 12 | strict.Append(CFLAGS = strict['CORECFLAGS']) 13 | strict.Object("pb_decode_oldcallback.o", "$NANOPB/pb_decode.c") 14 | strict.Object("pb_encode_oldcallback.o", "$NANOPB/pb_encode.c") 15 | strict.Object("pb_common_oldcallback.o", "$NANOPB/pb_common.c") 16 | 17 | opts.NanopbProto("extensions") 18 | testprog = opts.Program(["test_extensions.c", "extensions.pb.c", "pb_encode_oldcallback.o", "pb_decode_oldcallback.o", "pb_common_oldcallback.o"]) 19 | 20 | opts.RunTest(testprog) 21 | 22 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_342/extensions.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message BaseMessage { 4 | extensions 100 to 200; 5 | } 6 | 7 | extend BaseMessage { 8 | optional string string_extension = 100; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/regression/issue_342/test_extensions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "extensions.pb.h" 7 | #include "unittests.h" 8 | 9 | static bool write_string(pb_ostream_t *stream, const pb_field_t *field, const void *arg) 10 | { 11 | return pb_encode_tag_for_field(stream, field) && 12 | pb_encode_string(stream, (const void*)"abc", 3); 13 | } 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int status = 0; 18 | uint8_t buffer[64]; 19 | pb_size_t msglen = 0; 20 | 21 | { 22 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); 23 | pb_callback_t callback_def = {{0}}; 24 | pb_extension_t ext = {0}; 25 | BaseMessage msg = {0}; 26 | 27 | callback_def.funcs.encode = &write_string; 28 | ext.type = &string_extension; 29 | ext.dest = &callback_def; 30 | msg.extensions = &ext; 31 | 32 | TEST(pb_encode(&stream, BaseMessage_fields, &msg)); 33 | 34 | msglen = stream.bytes_written; 35 | TEST(msglen > 3); 36 | } 37 | 38 | { 39 | pb_istream_t stream = pb_istream_from_buffer(buffer, msglen); 40 | pb_extension_t ext = {0}; 41 | BaseMessage msg = {0}; 42 | 43 | ext.type = &string_extension; 44 | /* Note: ext.dest remains null to trigger buf #342 */ 45 | msg.extensions = &ext; 46 | 47 | TEST(pb_decode(&stream, BaseMessage_fields, &msg)); 48 | } 49 | 50 | return status; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/special_characters/SConscript: -------------------------------------------------------------------------------- 1 | # Test that special characters in .proto filenames work. 2 | 3 | Import('env') 4 | 5 | env.NanopbProto("funny-proto+name has.characters.proto") 6 | env.Object("funny-proto+name has.characters.pb.c") 7 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/special_characters/funny-proto+name has.characters.proto: -------------------------------------------------------------------------------- 1 | syntax="proto2"; 2 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/splint/SConscript: -------------------------------------------------------------------------------- 1 | # Check the nanopb core using splint 2 | 3 | Import('env') 4 | 5 | p = env.WhereIs('splint') 6 | 7 | if p: 8 | env.Command('pb_decode.splint', '$NANOPB/pb_decode.c', 9 | 'splint -f splint/splint.rc $SOURCE 2> $TARGET') 10 | 11 | env.Command('pb_encode.splint', '$NANOPB/pb_encode.c', 12 | 'splint -f splint/splint.rc $SOURCE 2> $TARGET') 13 | 14 | env.Command('pb_common.splint', '$NANOPB/pb_common.c', 15 | 'splint -f splint/splint.rc $SOURCE 2> $TARGET') 16 | 17 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/splint/splint.rc: -------------------------------------------------------------------------------- 1 | +checks 2 | +partial 3 | +matchanyintegral 4 | +strictlib 5 | -nullassign 6 | -predboolint 7 | -predboolptr 8 | +ptrnegate 9 | -switchloopbreak 10 | +ignoresigns 11 | -infloopsuncon 12 | -type 13 | 14 | # splint's memory checks don't quite work without annotations 15 | -mustfreeonly 16 | -compmempass 17 | -nullret 18 | -observertrans 19 | -statictrans 20 | -compdestroy 21 | -nullpass 22 | -nullstate 23 | -compdef 24 | -usereleased 25 | -temptrans 26 | -dependenttrans 27 | -kepttrans 28 | -branchstate 29 | -immediatetrans 30 | -mustfreefresh 31 | 32 | # These tests give false positives, compiler typically has 33 | # better warnings for these. 34 | -noret 35 | -noeffect 36 | -usedef 37 | 38 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/typename_mangling/SConscript: -------------------------------------------------------------------------------- 1 | # Test mangle_names option 2 | 3 | Import('env') 4 | 5 | def set_mangling(type): 6 | def command(target, source, env): 7 | with open(str(source[0])) as src, open(str(target[0]), "w") as dst: 8 | dst.write("* mangle_names:{}\n".format(type)) 9 | dst.write(src.read()) 10 | return command 11 | 12 | env.Command("strip_package.options", "with_package.options", set_mangling("M_STRIP_PACKAGE")) 13 | env.Command("strip_package.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) 14 | env.NanopbProto(["strip_package", "strip_package.options"]) 15 | env.Program(["test_strip_package.c", "strip_package.pb.c"]) 16 | 17 | env.Command("flatten.options", "with_package.options", set_mangling("M_FLATTEN")) 18 | env.Command("flatten.proto", "with_package.proto", Copy("$TARGET", "$SOURCE")) 19 | env.NanopbProto(["flatten", "flatten.options"]) 20 | env.Program(["test_flatten.c", "flatten.pb.c"]) 21 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/typename_mangling/test_flatten.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tests if expected names are generated when M_FLATTEN is used. 3 | */ 4 | 5 | #include 6 | #include "unittests.h" 7 | #include "flatten.pb.h" 8 | 9 | int main() 10 | { 11 | TopLevelMessage msg = {0}; 12 | NestedMessage nmsg = msg.nested; 13 | NestedLevel2 nmsg2 = nmsg.nested; 14 | NestedLevel3 nmsg3 = nmsg2.nested; 15 | nmsg3.nothing = 42; 16 | 17 | msg.short_if_none = ShortIfNone_IfNone_A; 18 | msg.short_if_strip_package = ShortIfStripPackage_IfPackage_A; 19 | msg.short_if_flatten = IfFlatten_A; 20 | 21 | return nmsg3.nothing; /* this sets `nmsg3` as used, to prevent warning */ 22 | } 23 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/typename_mangling/test_strip_package.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Tests if expected names are generated when M_STRIP_PACKAGE is used. 3 | */ 4 | 5 | #include 6 | #include "unittests.h" 7 | #include "strip_package.pb.h" 8 | 9 | int main() 10 | { 11 | TopLevelMessage msg = {0}; 12 | TopLevelMessage_NestedMessage_NestedLevel2_NestedLevel3 nmsg = msg.nested.nested.nested; 13 | 14 | msg.short_if_none = TopLevelMessage_ShortIfNone_IfNone_A; 15 | msg.short_if_strip_package = TopLevelMessage_IfPackage_A; 16 | msg.short_if_flatten = TopLevelMessage_ShortIfFlatten_IfFlatten_A; 17 | 18 | return nmsg.nothing; /* marks nmsg as used */ 19 | } 20 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/typename_mangling/with_package.options: -------------------------------------------------------------------------------- 1 | * long_names:true 2 | 3 | com.example.nanopb.TopLevelMessage.ShortIfNone long_names:false 4 | TopLevelMessage.ShortIfStripPackage long_names:false 5 | ShortIfFlatten long_names: false 6 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/typename_mangling/with_package.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package com.example.nanopb; 4 | 5 | message TopLevelMessage { 6 | required uint32 base_field = 1; 7 | required NestedMessage nested = 2; 8 | optional ShortIfNone short_if_none = 3; 9 | optional ShortIfStripPackage short_if_strip_package = 4; 10 | optional ShortIfFlatten short_if_flatten = 5; 11 | 12 | message NestedMessage { 13 | required NestedLevel2 nested = 1; 14 | 15 | message NestedLevel2 { 16 | required NestedLevel3 nested = 1; 17 | 18 | message NestedLevel3 { 19 | required uint32 nothing = 1; 20 | } 21 | } 22 | } 23 | 24 | enum ShortIfNone { 25 | IfNone_A = 1; 26 | IfNone_B = 2; 27 | } 28 | 29 | enum ShortIfStripPackage { 30 | IfPackage_A = 1; 31 | IfPackage_B = 2; 32 | } 33 | 34 | enum ShortIfFlatten { 35 | IfFlatten_A = 1; 36 | IfFlatten_B = 2; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/without_64bit/SConscript: -------------------------------------------------------------------------------- 1 | # Run the alltypes test case, but compile with PB_WITHOUT_64BIT. 2 | 3 | Import("env") 4 | 5 | env.NanopbProto(["alltypes", "alltypes.options"]) 6 | 7 | # Define the compilation options 8 | opts = env.Clone() 9 | opts.Append(CPPDEFINES = {'PB_WITHOUT_64BIT': 1, 'HAVE_STDINT_H': 0, 'PB_SYSTEM_HEADER': '\\"no_64bit_syshdr.h\\"'}) 10 | opts.Append(CPPPATH = "#without_64bit") 11 | 12 | if 'SYSHDR' in opts: 13 | opts.Append(CPPDEFINES = {'PB_OLD_SYSHDR': opts['SYSHDR']}) 14 | 15 | # Build new version of core 16 | strict = opts.Clone() 17 | strict.Append(CFLAGS = strict['CORECFLAGS']) 18 | strict.Object("pb_decode_no64bit.o", "$NANOPB/pb_decode.c") 19 | strict.Object("pb_encode_no64bit.o", "$NANOPB/pb_encode.c") 20 | strict.Object("pb_common_no64bit.o", "$NANOPB/pb_common.c") 21 | 22 | # Now build and run the test normally. 23 | enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_no64bit.o", "pb_common_no64bit.o"]) 24 | dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_no64bit.o", "pb_common_no64bit.o"]) 25 | 26 | env.RunTest(enc) 27 | env.RunTest([dec, "encode_alltypes.output"]) 28 | 29 | # Re-encode the data using protoc, and check that the results from nanopb 30 | # match byte-per-byte to the protoc output. 31 | env.Decode("encode_alltypes.output.decoded", 32 | ["encode_alltypes.output", "alltypes.proto"], 33 | MESSAGE='AllTypes') 34 | env.Encode("encode_alltypes.output.recoded", 35 | ["encode_alltypes.output.decoded", "alltypes.proto"], 36 | MESSAGE='AllTypes') 37 | env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"]) 38 | 39 | 40 | # Do the same checks with the optional fields present. 41 | env.RunTest("optionals.output", enc, ARGS = ['1']) 42 | env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1']) 43 | env.Decode("optionals.output.decoded", 44 | ["optionals.output", "alltypes.proto"], 45 | MESSAGE='AllTypes') 46 | env.Encode("optionals.output.recoded", 47 | ["optionals.output.decoded", "alltypes.proto"], 48 | MESSAGE='AllTypes') 49 | env.Compare(["optionals.output", "optionals.output.recoded"]) 50 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/without_64bit/alltypes.options: -------------------------------------------------------------------------------- 1 | * max_size:16 2 | * max_count:5 3 | *.*fbytes fixed_length:true max_size:4 4 | -------------------------------------------------------------------------------- /external/nanopb-master/tests/without_64bit/no_64bit_syshdr.h: -------------------------------------------------------------------------------- 1 | /* This wrapper undefines (u)int64_t */ 2 | 3 | #ifdef PB_OLD_SYSHDR 4 | #include PB_OLD_SYSHDR 5 | #else 6 | #include 7 | #include 8 | #include 9 | #include 10 | #endif 11 | 12 | #define uint64_t disabled_uint64_t 13 | #define int64_t disabled_int64_t 14 | 15 | -------------------------------------------------------------------------------- /external/nanopb-master/tools/make_linux_package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Run this script in the top nanopb directory to create a binary package 4 | # for Linux users. 5 | 6 | # Requires: protobuf, python-protobuf, pyinstaller 7 | 8 | set -e 9 | set -x 10 | 11 | VERSION=`git describe --always`-linux-x86 12 | DEST=dist/$VERSION 13 | 14 | rm -rf $DEST 15 | mkdir -p $DEST 16 | 17 | # Export the files from newest commit 18 | git archive HEAD | tar x -C $DEST 19 | 20 | # Rebuild the Python .proto files 21 | make -BC $DEST/generator/proto 22 | 23 | # Package the Python libraries 24 | ( cd $DEST/generator; pyinstaller nanopb_generator.py ) 25 | mv $DEST/generator/dist/nanopb_generator $DEST/generator-bin 26 | 27 | # Remove temp files 28 | rm -rf $DEST/generator/dist $DEST/generator/build $DEST/generator/nanopb_generator.spec 29 | 30 | # Make the nanopb generator available as a protoc plugin 31 | cp $DEST/generator-bin/nanopb_generator $DEST/generator-bin/protoc-gen-nanopb 32 | 33 | # Package the protoc compiler 34 | cp `which protoc` $DEST/generator-bin/protoc.bin 35 | LIBPROTOC=$(ldd `which protoc` | grep -o '/.*libprotoc[^ ]*') 36 | LIBPROTOBUF=$(ldd `which protoc` | grep -o '/.*libprotobuf[^ ]*') 37 | cp $LIBPROTOC $LIBPROTOBUF $DEST/generator-bin/ 38 | cat > $DEST/generator-bin/protoc << EOF 39 | #!/bin/bash 40 | SCRIPTDIR=\$(dirname "\$0") 41 | export LD_LIBRARY_PATH=\$SCRIPTDIR 42 | export PATH=\$SCRIPTDIR:\$PATH 43 | exec "\$SCRIPTDIR/protoc.bin" "\$@" 44 | EOF 45 | chmod +x $DEST/generator-bin/protoc 46 | 47 | # Remove debugging symbols to reduce size of package 48 | ( cd $DEST/generator-bin; strip *.so *.so.* ) 49 | 50 | # Tar it all up 51 | ( cd dist; tar -czf $VERSION.tar.gz $VERSION ) 52 | 53 | -------------------------------------------------------------------------------- /external/nanopb-master/tools/make_mac_package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Run this script in the top nanopb directory to create a binary package 4 | # for Mac OS X users. 5 | 6 | # Requires: protobuf, python-protobuf, pyinstaller 7 | 8 | set -e 9 | set -x 10 | 11 | VERSION=`git describe --always`-macosx-x86 12 | DEST=dist/$VERSION 13 | 14 | rm -rf $DEST 15 | mkdir -p $DEST 16 | 17 | # Export the files from newest commit 18 | git archive HEAD | tar x -C $DEST 19 | 20 | # Rebuild the Python .proto files 21 | make -BC $DEST/generator/proto 22 | 23 | # Package the Python libraries 24 | ( cd $DEST/generator; pyinstaller nanopb_generator.py ) 25 | mv $DEST/generator/dist/nanopb_generator $DEST/generator-bin 26 | 27 | # Remove temp files 28 | rm -rf $DEST/generator/dist $DEST/generator/build $DEST/generator/nanopb_generator.spec 29 | 30 | # Make the nanopb generator available as a protoc plugin 31 | cp $DEST/generator-bin/nanopb_generator $DEST/generator-bin/protoc-gen-nanopb 32 | 33 | # Package the protoc compiler 34 | cp `which protoc` $DEST/generator-bin/protoc.bin 35 | LIBPROTOC=$(otool -L `which protoc` | grep -o '/.*libprotoc[^ ]*') 36 | LIBPROTOBUF=$(otool -L `which protoc` | grep -o '/.*libprotobuf[^ ]*') 37 | cp $LIBPROTOC $LIBPROTOBUF $DEST/generator-bin/ 38 | cat > $DEST/generator-bin/protoc << EOF 39 | #!/bin/bash 40 | SCRIPTDIR=\$(dirname "\$0") 41 | export DYLD_LIBRARY_PATH=\$SCRIPTDIR 42 | export PATH=\$SCRIPTDIR:\$PATH 43 | exec "\$SCRIPTDIR/protoc.bin" "\$@" 44 | EOF 45 | chmod +x $DEST/generator-bin/protoc 46 | 47 | # Tar it all up 48 | ( cd dist; tar -czf $VERSION.tar.gz $VERSION ) 49 | 50 | -------------------------------------------------------------------------------- /external/nanopb-master/tools/set_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Run this from the top directory of nanopb tree. 4 | # e.g. user@localhost:~/nanopb$ tools/set_version.sh nanopb-0.1.9-dev 5 | # It sets the version number in pb.h and generator/nanopb_generator.py. 6 | 7 | sed -i -e 's/nanopb_version\s*=\s*"[^"]*"/nanopb_version = "'$1'"/' generator/nanopb_generator.py 8 | sed -i -e 's/#define\s*NANOPB_VERSION\s*.*/#define NANOPB_VERSION '$1'/' pb.h 9 | sed -i -e 's/set(\s*nanopb_VERSION_STRING\s*[^)]*)/set(nanopb_VERSION_STRING '$1')/' CMakeLists.txt 10 | 11 | VERSION_ONLY=$(echo $1 | sed 's/nanopb-//') 12 | if [[ $1 != *dev ]] 13 | then sed -i -e 's/"version":\s*"[^"]*"/"version": "'$VERSION_ONLY'"/' library.json 14 | fi 15 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import io 5 | import os 6 | import sys 7 | from shutil import rmtree 8 | 9 | from setuptools import find_packages, setup, Command 10 | 11 | # python3 setup.py upload 12 | 13 | NAME = 'zrna' 14 | DESCRIPTION = 'API client for the Zrna software-defined analog platform.' 15 | URL = 'https://github.com/zrna-research/zrna-api' 16 | EMAIL = 'nicolas@zrna.org' 17 | AUTHOR = 'Nicolas Steven Miller' 18 | REQUIRES_PYTHON = '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4' 19 | 20 | VERSION = '1.0.8' 21 | 22 | REQUIRED = [ 23 | 'cobs', 24 | 'future', 25 | 'inflection', 26 | 'protobuf', 27 | 'pyserial' 28 | ] 29 | 30 | here = os.path.abspath(os.path.dirname(__file__)) 31 | 32 | try: 33 | with io.open(os.path.join(here, 'README_PYPI.md'), encoding='utf-8') as f: 34 | long_description = '\n' + f.read() 35 | except FileNotFoundError: 36 | long_description = DESCRIPTION 37 | 38 | about = {} 39 | if not VERSION: 40 | project_slug = NAME.lower().replace("-", "_").replace(" ", "_") 41 | with open(os.path.join(here, project_slug, '__version__.py')) as f: 42 | exec(f.read(), about) 43 | else: 44 | about['__version__'] = VERSION 45 | 46 | 47 | class UploadCommand(Command): 48 | """Support setup.py upload.""" 49 | 50 | description = 'Build and publish the package.' 51 | user_options = [] 52 | 53 | def initialize_options(self): 54 | pass 55 | 56 | def finalize_options(self): 57 | pass 58 | 59 | def run(self): 60 | try: 61 | print('Removing previous builds') 62 | rmtree(os.path.join(here, 'dist')) 63 | except OSError: 64 | pass 65 | 66 | print('Building Source and Wheel (universal) distribution') 67 | os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) 68 | 69 | print('Uploading the package to PyPI via Twine') 70 | os.system('twine upload dist/*') 71 | 72 | sys.exit() 73 | 74 | setup( 75 | name=NAME, 76 | version=about['__version__'], 77 | description=DESCRIPTION, 78 | long_description=long_description, 79 | long_description_content_type='text/markdown', 80 | author=AUTHOR, 81 | author_email=EMAIL, 82 | python_requires=REQUIRES_PYTHON, 83 | url=URL, 84 | packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]), 85 | install_requires=REQUIRED, 86 | include_package_data=True, 87 | license='APACHE', 88 | classifiers=[ 89 | 'License :: OSI Approved :: Apache Software License', 90 | 'Programming Language :: Python :: 2', 91 | 'Programming Language :: Python :: 2.7', 92 | 'Programming Language :: Python :: 3', 93 | 'Programming Language :: Python :: 3.6' 94 | ], 95 | cmdclass={ 96 | 'upload': UploadCommand, 97 | }, 98 | ) 99 | -------------------------------------------------------------------------------- /zrna/__init__.py: -------------------------------------------------------------------------------- 1 | from .api import Client 2 | -------------------------------------------------------------------------------- /zrna/__version__.py: -------------------------------------------------------------------------------- 1 | VERSION = (1, 0, 1) 2 | __version__ = '.'.join(map(str, VERSION)) 3 | --------------------------------------------------------------------------------