services/serialization/nanopb.html · services/serialization/nanopb.rst 공식 원문 ↗

Zephyr 3.7.0 · Serialization · Protocol Buffers

Nanopb

Protocol Buffers schema를 작은 embedded C용 source와 header로 생성합니다.

Official pathservices/serialization/nanopb.html
Source fileservices/serialization/nanopb.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Ubuntu·macOS·Windows의 protoc 설치부터 west module filter, CMake include, zephyr_nanopb_sources와 generator option을 설명합니다.

Compiler

protoc

Module

+nanopb

Build

.proto → C

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 F2A788262EBAB633F15A0B7D7475C3991048A6DDDEA0ECB235BED46A3EADEE19
.. _nanopb_reference:

Nanopb
######

`Nanopb <https://jpa.kapsi.fi/nanopb/>`_ is a C implementation of Google's
`Protocol Buffers <https://protobuf.dev/>`_.

Requirements
************

Nanopb uses the protocol buffer compiler to generate source and header files,
make sure the ``protoc`` executable is installed and available.

.. tabs::

   .. group-tab:: Ubuntu

      Use ``apt`` to install dependency:

         .. code-block:: shell

            sudo apt install protobuf-compiler

   .. group-tab:: macOS

      Use ``brew`` to install dependency:

         .. code-block:: shell

            brew install protobuf

   .. group-tab:: Windows

      Use ``choco`` to install dependency:

         .. code-block:: shell

            choco install protoc


Additionally, Nanopb is an optional module and needs to be added explicitly to the workspace:

.. code-block:: shell

   west config manifest.project-filter -- +nanopb
   west update

Configuration
*************

Make sure to include ``nanopb`` within your ``CMakeLists.txt`` file as follows:

.. code-block:: cmake

   list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
   include(nanopb)

Adding ``proto`` files can be done with the ``zephyr_nanopb_sources()`` CMake function which
ensures the generated header and source files are created before building the specified target.

Nanopb has `generator options <https://jpa.kapsi.fi/nanopb/docs/reference.html#generator-options>`_
that can be used to configure messages or fields. This allows to set fixed sizes or skip fields
entirely.

The internal CMake generator has an extension to configure ``*.options.in`` files automatically
with CMake variables.

See :zephyr_file:`samples/modules/nanopb/src/simple.options.in` and
:zephyr_file:`samples/modules/nanopb/CMakeLists.txt` for usage example.

Part 3

한국어 전문 번역

Nanopb는 Google Protocol Buffers의 C implementation입니다. .proto schema에서 embedded 환경에 적합한 C source와 header를 생성하고, runtime library로 message를 encode·decode합니다.

Requirements

Nanopb는 source와 header 생성에 Protocol Buffer compiler를 사용하므로 protoc executable을 설치하고 command path에서 실행할 수 있어야 합니다.

Ubuntu
sudo apt install protobuf-compiler
macOS
brew install protobuf
Windows
choco install protoc

Nanopb는 optional Zephyr module이므로 workspace manifest filter에 명시적으로 추가한 뒤 module을 내려받아야 합니다.

west config manifest.project-filter -- +nanopb
west update

Configuration

Application의 CMakeLists.txt에서 Zephyr가 제공하는 Nanopb CMake module path를 추가하고 module을 include합니다.

list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
include(nanopb)

zephyr_nanopb_sources() CMake function에 .proto file을 넘기면 지정 target을 compile하기 전에 generated header와 source를 만들도록 build dependency가 구성됩니다. 따라서 generated file을 수동으로 미리 만들 필요가 없습니다.

Nanopb generator option은 message 또는 field 동작을 조정합니다. Embedded system에서는 최대 길이와 array 크기를 고정해 dynamic allocation을 피하거나, 사용하지 않는 field를 생성 대상에서 완전히 제외할 수 있습니다.

Zephyr 내부 CMake generator는 *.options.in file을 CMake variable로 자동 configure하는 extension도 제공합니다. 실제 사용 방식은 samples/modules/nanopb/src/simple.options.in과 samples/modules/nanopb/CMakeLists.txt에서 확인할 수 있습니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.