Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use protobufs to in the kernel?

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?

like image 261
deft_code Avatar asked May 05 '11 21:05

deft_code


People also ask

What are Protobufs used for?

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.

Is protobuf faster than JSON?

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.

How do Protobufs work?

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).


1 Answers

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 structs in header files and pass those across the kernel/userspace boundary.

like image 149
caf Avatar answered Sep 28 '22 08:09

caf