ProtoBuf在使用protoc進行編譯時提示: Required fields are not allowed in proto3


場景

在使用protobuf的編譯器進行編譯proto文件時提示

 Required fields are not allowed in proto3

 

 

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。

實現

這是因為protobuf2與protobuf3的語法不同。

在prptp文件中

syntax = "proto3";

使用的語法規則是prptobuf3

但是在聲明message時使用的是protobuf2的語法

message Student {
    required string name = 1;
}

proto3”僅僅支持repeated字段修飾,如果使用required,optional編譯會報錯。

所以將required去掉即可。

message Student {
    string name = 1;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM