我正在構建一個轉譯器,需要了解 protobuf/go 范圍查找系統。我一直在嘗試用谷歌搜索檔案并沒有找到運氣。
問:在 Go/protobufs 中匯入型別時,是否可以進行共享包范圍查找?
這是我要質疑的示例:
原型1:
package cosmos.crypto.keyring.v1;
...
message Ledger {
hd.v1.BIP44Params path = 1;
}
原型2:
package cosmos.crypto.hd.v1;
message BIP44Params {
...
}
到目前為止,我已經看到了兩種有意義的語法:
全范圍
message Ledger {
cosmos.crypto.hd.v1.BIP44Params path = 1;
}
或者我也看過這樣的版本
完全無范圍
message Ledger {
BIP44Params path = 1;
}
部分范圍?
但我看到的風格是部分范圍的
message Ledger {
hd.v1.BIP44Params path = 1;
}
他們離開的原因是cosmos.crypto因為這兩個包共享cosmos.crypto其包名的根目錄嗎?
還是基于匯入的更通用的范圍查找?
任何見解或閱讀鏈接表示贊賞:)
uj5u.com熱心網友回復:
我不確定我是否完全明白這個問題,但我會盡力回答。如果你需要我改變它,請告訴我。
這是兩者的結合。您需要擁有包并匯入 .proto 檔案。讓我解釋。如果您有兩個檔案定義如下:
proto1.proto
syntax = "proto3";
package cosmos.crypto.keyring.v1;
message Ledger {
hd.v1.BIP44Params path = 1;
}
proto2.proto
syntax = "proto3";
package cosmos.crypto.hd.v1;
message BIP44Params {}
試圖編譯會告訴你"hd.v1.BIP44Params" is not defined。這是因為proto1.proto不知道其他定義。現在,如果您import "proto2.proto";在 中proto1.proto,它將知道BIP44Params定義并會注意到包定義。
使用此包定義,它將能夠訪問以下型別定義:
cosmos.crypto.hd.v1.BIP44Params- 這很不言自明hd.v1.BIP44Params- 因為這兩個包在hd零件之前匹配。
但它應該能夠訪問:
BIP44Paramscosmos.crypto.keyring.v1- 因為包中沒有定義這樣的型別
希望這很清楚
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/474147.html
標籤:去 协议缓冲区 protobuf-c
