c++grpcprotobuf-c

How to get gRPC / protobuf version programmatically?


Is there an API to know gRPC/protobuf version or the git commit hash? We would like to include these in --version information of our C++ application.

The files gRPC-Core.podspec, gRPC-C++.podspec, Protobuf-C++.podspecetc. do have this information; wonder if the same can be extracted without having to parse these files.


Solution

  • gRPC exposes the version in its API:

    const GRPCAPI char* grpc_version_string ( void )

    For the C++ implementation there appears to be the following method in the <grpcpp/grpcpp.h> header:

    std::string grpc::Version()

    For protobuf the macro GOOGLE_PROTOBUF_VERSION is the integer value of its version & can be converted to string using the following API:

    std::string google::protobuf::internal::VersionString(int version)