I need to define a communication protocol with a Linux device driver. Protobufs look very nice, and there is an active C port.
Is it possible to use protobufs in a Linux device driver?
Obviously the vanilla c code will not work as it makes malloc calls, etc. Is there protobufs implementation that targets the kernel?
If there is a drop in solution, how much effort is it to port a C library for use in the kernel?
Bonus question: Are the answers significantly different when writing with windows drivers?
Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data.
Benchmark — telemetry data We then modified the benchmark to encode our example data which is an opentelemetry trace data. These were the results we expected — for this data, protobuf was actually slower than JSON.
Protocol buffers are a combination of the definition language (created in . proto files), the code that the proto compiler generates to interface with data, language-specific runtime libraries, and the serialization format for data that is written to a file (or sent across a network connection).
In theory, you could do this - but there really isn't any point in doing so. Protocol Buffers was created to ease the task of transferring data between different machines and languages that use different representations for binary data - but the interface between a kernel driver and userspace is on the same machine (and typically the same language - a C language library is usually used on the userspace side, even when writing application code in another language).
This means that the different representation issue doesn't arise - you can simply define struct
s in header files and pass those across the kernel/userspace boundary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With