I have two simple .proto files. One has an import towards the other. When launching the command;
protocols --java_out = 'exit path' -I 'path root' 'path .proto with import'. It throws me the following error: Import "path proto2.proto" was not found or had errors. In the import I have absolute paths
My two files.
proto1.proto:
syntax = "proto3";
import "/home/myuser/insProtoc/proto2.proto";
message SearchResponse {
repeated Result results = 1;
}
proto2.proto:
syntax = "proto3";
message Result {
string url = 1;
string title = 2;
repeated string snippets = 3;
}
Return this error;
/home//mysuser/insProtoc/proto2.proto: File not found.
/--proto_path/ejemplo1.proto: Import
"/home/muyuser/insProtoc/proto2.proto" was not found or had errors.
/--proto_path/proto1.proto:6:12: "Result" is not defined.
Related
I need to use Protocol Buffers to serialize JSON messages received from the Google Drive drives:list method and write them to the BigQuery Storage Write API (GRPC). This is working for all field types except timestamp. I cannot for the life of me generate go classes that include timestamps. To begin, I'm following this document, although have also tried everything I can find online including here on stackoverflow to no avail.
On MacOS 12.6, protoc is installed from this zip to /usr/local/bin and the contents of include from the zip are installed to /usr/local/include.
This is the drives.proto file I need to create a class for:
syntax = "proto3";
option go_package = "./driveBuffers";
import "google/protobuf/timestamp.proto";
message Drive {
string id =1;
string name =2;
string colorRgb = 3;
string backgroundImageLink =4;
bool hidden = 5;
string orgUnitId = 6;
timestamp createdTime = 7;
message restrictions {
bool adminManagedRestrictions = 1;
bool domainUsersOnly = 2;
bool copyRequiresWriterPermission = 3;
bool driveMembersOnly = 4;
}
}
If I remove the field with type timestamp, the tool creates a file named ./driveBuffers/drives.pb.go. With the timestamp type, this error is thrown:
% protoc --go_out=. -I ./ -I /usr/local/include/ drives.proto
drives.proto:11:3: "timestamp" is not defined.
Thank you.
You should refer the type as google.protobuf.Timestamp. As example:
string orgUnitId = 6;
google.protobuf.Timestamp createdTime = 7;
syntax = "proto3";
package model;
import "google/protobuf/Empty.proto";
message User {
string id = 1;
string name = 2;
string email = 3;
string alamat = 4;
string password = 5;
}
message UserList {
repeated User list = 1;
}
message userId {
string id = 1;
}
message UserUpdate {
string id = 1;
User user = 2;
}
service Users {
rpc getUserList(google.protobuf.Empty) returns (UserList) {}
rpc getUserById(userId) returns (User) {}
rpc inserUser(User) returns (google.protobuf.Empty) {}
rpc updateUser(UserUpdate) returns (google.protobuf.Empty) {}
rpc deleteUser(userId) returns (google.protobuf.Empty) {}
}
above is my proto file. I get error google/protobuf/Empty.proto: File not found.
when trying to compile the proto file above. can someone help me ?
First of all, the correct import is import "google/protobuf/empty.proto";
second, for generating a proto file run this code:
protoc --proto_path={proto_directory_address} --proto_path={proto_directory_name} --go-grpc_out={generated_directory_path} --go_out={generated_directory_path} {proto_directory_address}/{proto_file_name}.proto
hi there / i had the same issue for a long time .. this process worked for me i hope it dose for you too :
navigate to this directory using your cmd(command line) :
cd .local/include
this directory normally should contain some folder named "google" copy this folder and paste it to this directory :
/usr/local/include
and now try the protoc engine again to generate your project and if the error still exists then try the rest of process :
navigate to that specific directory and check if its been copied or not . if it is then try to navigate to the folder from where you are (which it should be /usr/local/include) if the error says you have no permission to get in the folder
use this command to get the permission
$ sudo chmod o+r -R ./google
and then try to get permission to get in protobuf folder in the same directory using above command again
when its all done . check the protoc generator again /// hope works for you because it dose for me
We are using protobuf messages to use in Zsockets on AWS Linux machines. We have 3 protobuf files in the same directory. 2 protobuf files are importing the 3rd file. Protobuf files are as below.
Fs.proto :
syntax = "proto3";
option java_package = "com.abc.xyz.service";
option java_outer_classname = "FsProto";
option java_multiple_files = true;
option cc_enable_arenas = true;
import "Ping.proto";
package Fs;
Ds.proto :
syntax = "proto3";
option java_package = "com.abc.xyz.service";
option java_outer_classname = "DsProto";
option java_multiple_files = true;
option cc_enable_arenas = true;
import "Ping.proto";
package Ds;
Ping.proto :
syntax = "proto3";
option java_package = "com.abc.xyz.service";
option java_multiple_files = true;
option cc_enable_arenas = true;
package Ping;
message P1
{
fixed64 tid = 1;
fixed32 port = 2;
}
message P2
{
fixed64 tid = 1;
string ip = 2;
}
We generated archive library using the directory (but with -fPIC flag as we need to link this library with a shared library). When we are running our code, it is throwing below error.
[libprotobuf ERROR google/protobuf/descriptor_database.cc:641] File already exists in database: Ping.proto
[libprotobuf FATAL google/protobuf/descriptor.cc:1371] CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size):
We are not sure why it is throwing this error. We have only one Ping.proto in whole project. We are not able to proceed further on this. Can anyone please help us to identify what is causing the issue and how to fix this.
Note:
I already checked File already exists in database error from Protobuf when deploying Google Dataflow template after MacOS Catalina upgrade But it didn't help.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
What's best practice for separating the declaration of messages used in services in (Go-specific) Protocol Buffers? The context is a large application with multiple gRPC services. Some messages are used in multiple services. The thought was to divide the definitions of message and services, like this (simplified a bit):
airline/pb/airline_messages.proto:
syntax = "proto3";
option go_package = "github.com/example.com/example-repo/airline/pb";
message Airline {
string code = 1;
string name = 2;
string country = 3;
}
airline/pb/airline_services.proto:
syntax = "proto3";
option go_package = "github.com/example.com/example-repo/airline/pb";
import "airline/pb/airline_messages.proto"
service AirlineService {
rpc GetAirline(string) returns (Airline) {}
rpc GetAirlines(GetAirlinesRequest) returns (repeated Airline) {}
}
message GetAirlinesRequest {
int max = 1;
string country = 2;
string pattern = 3;
string sortby = 4;
}
I'm calling protoc like this:
protoc --go_out=. \
--go_opt=paths=source_relative \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
--proto_path=. \
--proto_path=../../ airline_services.proto
This doesn't work because Airline isn't defined. Invoking it like this:
protoc ... airline_services.proto airline_messages.proto
generates an error message the Airline is multiply defined. Doing this:
protoc ... airline_messages.proto
protoc ... airline_services.proto
just overwrites the Go files and is equivalent to just compiling airline_services.proto.
What's best practice for being able to reuse message definitions in multiple services?
Not sure if it helps or if you are using a different version of the Go generator.
I have multiple *.proto files in one directory. Some of them import others:
A part of device.proto importing status.proto:
syntax = "proto3";
package somePackage;
import "status.proto";
option go_package = "goPackageName";
service Device {
rpc GetStatus (GetStatusRequest) returns (Status) {}
}
message GetStatusRequest {
// ...
}
with status.proto containing the Status message:
syntax = "proto3";
package somePackage;
option go_package = "goPackageName";
message Status {
int32 customer = 1;
string device_id = 2;
// ...
}
I generate the Go code with:
protoc --go_out=plugins=grpc:. --go_opt=paths=source_relative *.proto
Note: I'm still using the old Go protobuf github.com/golang/protobuf.
I am trying to write code to read a text file and to filter out those lines which have both search items:
import std.stdio;
import std.string;
import std.file : readText;
import std.algorithm;
void main(){
string[] srchitems = ["second", "pen"]; // to search file text for lines which have both these;
auto alltext = readText("testing.txt");
auto alllist = alltext.split("\n");
foreach(str; srchitems){
alllist = alllist.filter!(a => a.indexOf(str) >= 0); // not working ;
}
writeln(alllist);
}
However, it is not working and giving this error:
$ rdmd soq_filter.d
soq_filter.d(11): Error: cannot implicitly convert expression filter(alllist) of type FilterResult!(__lambda1, string[]) to string[]
Failed: ["/usr/bin/dmd", "-v", "-o-", "soq_filter.d", "-I."]
Following line with cast also does not work:
alllist = cast(string[]) alllist.filter!(a => a.indexOf(str) >= 0); // not working ;
Error:
Error: cannot cast expression filter(alllist) of type FilterResult!(__lambda1, string[]) to string[]
Where is the problem and how can it be solved? Thanks.
As you have figured out, the return value from filter isn't an array, but a custom range. filter's return value is in fact a lazy range, so that if you only use the first few items only those items will be calculated. To convert a lazy range into an array, you will need to use std.array.array:
import std.array : array;
alllist = alllist.filter!(a => a.indexOf(str) >= 0).array;
In your case, that seems to work well. However, by slightly restructuring your code, there is a more idiomatic solution:
import std.stdio;
import std.string;
import std.file : readText;
import std.algorithm;
import std.array;
void main() {
string[] srchitems = ["second", "pen"];
auto alltext = readText("testing.txt");
auto alllist = alltext.split("\n");
auto results = alllist.filter!(a => srchitems.any!(b => a.indexOf(b) >= 0));
writeln(results);
}
In the above code, we use the result of filter directly, rather than convert it to an array.