WHat is the difference between the filename_pb2_grpc.py and the filename_pb2.py files? - protocol-buffers

From what I understand, the pb2.py file is code from the protoc file and the pb2_grpc.py file is code generated by protoc from the .proto file. But I don't understand what that means. I am very confused, can someone please explain this to me.
Thank you
I have tried to google the question, but I couldn't find anything that I could understand

Both are generated by protoc or python -m grpc_tools.protoc (a Python module that wraps protoc).
A pb2.py file contains the core Protocol Buffer (message) definitions and is created as a result of the --python_out flag being specified.
A pb2_grpc.py file contains the service and rpc (method) definitions and is created as a result of the --grpc_python_out flag being specified.

Related

Writing .cargo/config.toml to allow rust code to be imported by python

I'm using rust-cpython to make a python module in rust. I've run my code on a linux os and it runs just fine but I get the familiar "linking with cc failed:exit code 1 error". I've gathered from this that I need to add the .cargo/config file to my project as suggested at the bottom of this:
https://github.com/dgrunwald/rust-cpython
I've copied and pasted their code into a file, config.toml, and place there in a directory, .cargo. I've tried nesting this in my src directory and my project directory with no success, what am I missing?
Solution found: Thought I'd post it as this gave me grief.
Everything with this setup is fine except the config file can't have the extension .toml despite being written in a toml format

How do I use my tsconfig file with ng-packagr?

I'm packaging an Angular 5 library with ng-packagr and I need to use my existing tsconfig.json. I've read the docs here https://github.com/ng-packagr/ng-packagr/blob/master/docs/override-tsconfig.md and it says I need to write a script (I was expecting an option in the config) and pass through the filepath to my tsconfig file.
I don't understand where I write this code? I guess this needs to be an NPM script? The documentation and example seems to be very minimal.
Help with this would be appreciated.
I did this by creating a build-package.ts file with the contents (but require not import) then did:
node build-package.ts.

Running GRPC example for golang

newbie here.
Currently learning how grpc works and was going through the tutorial in this link
https://grpc.io/docs/quickstart/go.html#update-and-run-the-application
When I ran the example using the helloworld.pb.go file provided, it works. But when I deleted that file and ran protoc --go_out=plugins=grpc:. *.proto to generate the that file again, I find that I can no longer run the greeter server.
The error I am getting is
google.golang.org/grpc/examples/helloworld/helloworld
helloworld/helloworld.pb.go:105:11: cannot use _Greeter_SayHello_Handler (type func(interface {}, "context".Context, grpc.Codec, []byte) (interface {}, error)) as type grpc.methodHandler in field value
Tried to google but couldn't find out why. My protobuf version is 3.5.1 and the grpc is freshly cloned from github.com/golang/protobuf/protoc-gen-go
Generate proto like this
file_name : Your proto file name with the path
//To generate the grpc code
protoc proto/file_name.proto --go_out=plugins=grpc:.
Take a look this link How to write proto and generate the proto file. It may help your problem
https://github.com/SXerox007/protos-

Adding and compiling new code in the linux kernel

This may sound like a very noob question.
I'm trying to implement a UDP-based protocol in the linux kernel. I was following the UDPLite protocol implementation as a reference.
Step 1
I created a new_protocol.c in net/ipv4/
This file has a function
void _init protocol_init(void){*Code here*}
I also used
#include "udp_impl.h"
in this file as I was using some functions from the UDP protocol
Step 2
I modified the file net/ipv4/udp_impl.h to include net/new_protocol.h
Step 3
I created the file include/net/new_protocol.h where I defined the function
void protocol_init(void);
Step 4
Finally, I called the function in net/ipv4/af_inet.c. Also, I gave an include statement in this file for net/new_protocol.h
Now when I try to build the kernel, I get an error saying
undefined reference to `protocol_init()'
What am I missing here? Is my way of including header files incorrect? Do I need to include some info in the makefile to pick up the new net/ipv4/protocol.c?
Do I need to include some info in the makefile to pick up the new net/ipv4/protocol.c?
Yes, you need. Kernel build system doesn't autodetect source files, all of them should be listed explicitely in appropriate Makefile. In you case you need to modify net/ipv4/Makefile.
Makefiles used for kernel build are described in file Documentation/kbuild/makefiles.txt.
I just needed to add protocol.o in the makefile in net/ipv4/

protoc not generating service stub files

I have just started playing with google proto. When I try to compile proto file present in proto-java example, it does not generate any grpc file.
proto file,
https://github.com/grpc/grpc-java/blob/master/examples/src/main/proto/hello_world.proto
terminal output,
rsonkhla#raman-OptiPlex-9020:~/sandbox/grpc-java/examples$ protoc
--version libprotoc 3.0.0 rsonkhla#raman-OptiPlex-9020:~/sandbox/grpc-java/examples$ protoc
--java_out=test/ -I../../grpc-java/examples ../../grpc-java/examples/src/main/proto/hello_world.proto
rsonkhla#raman-OptiPlex-9020:~/sandbox/grpc-java/examples$ ls -R test/
test/: io
test/io: grpc
test/io/grpc: examples
test/io/grpc/examples: helloworld
test/io/grpc/examples/helloworld: HelloRequest.java
HelloResponse.java HelloWorldProto.java
HelloRequestOrBuilder.java HelloResponseOrBuilder.java
Has anybody else faced this issue?
The command line you are showing does not enable the grpc plugin. You need to specify an _out argument for the grpc plugin, which enables the plugin and specifies where it should output files. Since the plugin is likely not in your PATH, you also need to tell protoc how to find the plugin with --plugin.
So you need to add two arguments:
--plugin=protoc-gen-grpc-java=path/to/protoc-gen-grpc-java --grpc-java_out=path/to/output/dir
For more info, see the gRPC compiler documentation.
You can add these option to your .proto (base on your language) to generate abstract services:
option cc_generic_services = true;
option java_generic_services = true;
option py_generic_services = true;
You can also add --plugin=EXECUTABLE option in your protoc cmd to use custom code generator plugin to generate code more specific to each system, rather than rely on the "abstract" services. Just like Eric's suggestion.

Resources