Golang - google/protobuf/Empty.proto: File not found - go

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

Related

Protoc protoc-gen-go "timestamp" is not defined

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;

File already exists in database error from protobuf while using on Amazon Linux

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.

Protoc import was not found or had errors

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.

File found in IntelliJ but not in built jar

I am running some code through a compiler, and I have to query which Operating System the user is using to call the appropriate binary. The code works, and calls the binary in IntelliJ, but when I build a jar file with gradle, I get a file not found exception (the binary) on the line that corresponds to val tempBinaryCopy.
fun assemble(file: String) {
val currentDirectory = System.getProperty("user.dir")
val binary = when {
System.getProperty("os.name").startsWith("Linux") -> javaClass.classLoader.getResource("osx_linux").file
System.getProperty("os.name").startsWith("Mac") -> javaClass.classLoader.getResource("osx_mac").file
else ->javaClass.classLoader.getResource("osx_win.exe").file
}
val binaryFile = File(binary).name
val assemblyFile = File(file).name
val tempBinaryCopy = File(binary).copyTo(File(currentDirectory, binaryFile), true)
val tempAssemblyCopy = File(file).copyTo(File(currentDirectory, assemblyFile), true)
tempAssemblyCopy.deleteOnExit()
tempBinaryCopy.deleteOnExit()
Files.setPosixFilePermissions(tempBinaryCopy.toPath(), setOf(PosixFilePermission.OWNER_EXECUTE))
val process = Runtime.getRuntime().exec(arrayOf(tempBinaryCopy.absolutePath, tempAssemblyCopy.absolutePath, "-v"))
process.inputStream.bufferedReader().readLines().forEach { println(it) }
}
The exception
Exception in thread "main" kotlin.io.NoSuchFileException: file:/Users/dross/Desktop/OS.jar!/osx_mac: The source file doesn't exist.
at kotlin.io.FilesKt__UtilsKt.copyTo(Utils.kt:179)
at kotlin.io.FilesKt__UtilsKt.copyTo$default(Utils.kt:177)
at com.max.power.os.assembler.ProvidedAssembler.assemble(ProvidedAssembler.kt:22)
I have also tried a replace on the line in question to remove the ! and the result was the same.
javaClass.classLoader.getResource("osx_linux") gives you an instance of URL, URL.file gives you the file part of the URL. This might work as long as the file is not packaged in a JAR, but as you can see fails in case the file is packed into a JAR. You should probably instead use getResourceAsStream and the copy the InputStream you receive to the destination where you want to have it.

How to navigate to a sub directory through a proxy with FTPWebRequest

I am currently trying to log on to a ftp server via an ftp proxy. Using the following snippet
async {
let r = FtpWebRequest.Create("ftp://<ftp-proxy-address>") :?> FtpWebRequest
r.Method <- WebRequestMethods.Ftp.ListDirectoryDetails
r.Timeout <- req.Timeout.TotalMilliseconds |> int
r.Proxy <- null
r.Credentials <- NetworkCredential("user#host/subdirectory","password")
use! response = r.AsyncGetResponse()
use sr = new StreamReader(response.GetResponseStream(), req.Encoding)
let result = handler sr
return result
}
However this always logs me on to the user directory root not into the subdirectory I have specified in the user credentials. Is there a way to get this to work?
Note It seems to work if I do not use a FTP proxy instead specify a HTTP proxy.. I can see the CWD command being issued and I end up in the directory I expected
You have to logon first and then change directory.

Resources