場景
在使用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; }