Protoful 安装

发布时间:2022-07-04 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Protoful 安装脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

PRoto 文件

syntax = "proto3";
// 字段的 tag
// 1到15 只占用一个字节,所以应该用在不频繁使用的字段上。

import "data.proto" //引用其他的包

package my.project; // c# namespace My.Project

option csharp_namespace = "My.WebApis"; // C# 的话生成的命名空间就是 =My.WebApis,其他的还是 my.project



message Preson {
  int32 id = 1;
  string name = 2;
  float height = 3;
  float weight = 4;
  bytes avatar = 5;
  string email = 6;
  bool email_verified = 7;
  rePEated string phone_numbers =
      8; //数组的话,使用paked,(一个人可以有多个话号码)

  Gender gender = 11;
  Date birthday = 12;

  repeated Address addresses = 13; //方式可能是个复数

  reserved 9, 10, 20 to 100; //保留的tag,不能再用了
  reserved "foo", "bar";     //保留的字段

  enum Gender {
    option allow_alias = true; //起好别名了
    NOT_SPECIFIED = 0;         //未指定
    FEMALE = 1;                //男
    MALE = 2;                  //女

    WOMAN = 1; //男
    MAN = 2;   //女
  }

  message Address {
    string province = 1;
    string cITy = 2;
    string zip_code = 3;
    string street = 4;
    string number = 5;
  }
}

引用的 data 包

syntax = "proto3";
message Date {
  int32 year = 1;
  int32 month = 2;
  int32 day = 3;
}

生成文件

生成csharp文件的命令

protoc First.proto --csharp_out=csharp

下载 go 的依赖

go get -u github.COM/golang/protobuf/protoc-gen-go

简单例子

syntax = "proto3";
// package example.first;
package src;
option go_package = "./src"; //输出目录
message PresonMessage {
  int32 id = 1;
  bool is_adult = 2;
  string name = 3;
  repeated int32 lucky_number = 4;
}

生成go的 proto 命令

protoc --go_out=.  person.proto   // 执行命令

脚本宝典总结

以上是脚本宝典为你收集整理的Protoful 安装全部内容,希望文章能够帮你解决Protoful 安装所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。