ubuntu18.04上安装protubuf3.19.4

1、下载protobuf

sudo wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protobuf-all-3.19.4.tar.gz

2、解压protobuf

sudo tar -zxvf protobuf-all-3.19.4.tar.gz

3、编译安装

 cd protobuf-3.19.4sudo ./autogen.shsudo ./configure --prefix=/usr/local  #--prefix指定安装目录||sudo ./configure --prefix=$/usr/local  #--prefix指定安装目录sudo makesudo make checksudo make install

4、配置环境变量和动态连接库
更改环境变量:

 sudo vim /etc/profile
在文件的末尾添加如下的两行: (把bin路径和pkgconfig路径添加到系统PATH)
 export PATH=P A T H : PATH:PATH:/usr/local/bin/export PKG_CONFIG_PATH=$/usr/local/lib/pkgconfig/
配置动态链接库
sudo vim /etc/ld.so.conf
/usr/local/protobuf/lib
$/usr/local/lib

更改完成之后ldconfig即可
{
a、在 Vim 编辑器中,移动光标到文件的末尾或你想插入内容的位置。
b、按下 i 键进入插入模式,并输入你想添加的新内容。
c、按下 Esc 键退出插入模式。
d、输入 :wq 命令,保存并退出文件。如果需要仅保存文件而不退出 Vim,可以输入 :w 命令。
}
5、查看是否安装成功
protoc --version
test.proc代码

syntax = "proto3";package contacts;message LoginRequest
{string name = 1;string pwd = 2;
}

编译test.proc

6、执行protobuf

test.proto protoc test.proto --cpp_out=./

main.cppdaima

#include<iostream>
#include"test.pb.h"
#include<string>
using namespace std;
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/text_format.h"int main()
{contacts::LoginRequest tmp;tmp.set_name("shengjie");tmp.set_pwd("123456");string str;tmp.SerializeToString(&str);cout<<"str:"<<str<<endl;return 0;
}

test.pb.c代码

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: test.proto#ifndef GOOGLE_PROTOBUF_INCLUDED_test_2eproto
#define GOOGLE_PROTOBUF_INCLUDED_test_2eproto#include <limits>
#include <string>#include <google/protobuf/port_def.inc>
#if PROTOBUF_VERSION < 3019000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 3019004 < PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif#include <google/protobuf/port_undef.inc>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_table_driven.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata_lite.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>  // IWYU pragma: export
#include <google/protobuf/extension_set.h>  // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
#include <google/protobuf/port_def.inc>
#define PROTOBUF_INTERNAL_EXPORT_test_2eproto
PROTOBUF_NAMESPACE_OPEN
namespace internal {
class AnyMetadata;
}  // namespace internal
PROTOBUF_NAMESPACE_CLOSE// Internal implementation detail -- do not use these members.
struct TableStruct_test_2eproto {static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[]PROTOBUF_SECTION_VARIABLE(protodesc_cold);static const ::PROTOBUF_NAMESPACE_ID::internal::AuxiliaryParseTableField aux[]PROTOBUF_SECTION_VARIABLE(protodesc_cold);static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[1]PROTOBUF_SECTION_VARIABLE(protodesc_cold);static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[];static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[];static const uint32_t offsets[];
};
extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_test_2eproto;
namespace contacts {
class LoginRequest;
struct LoginRequestDefaultTypeInternal;
extern LoginRequestDefaultTypeInternal _LoginRequest_default_instance_;
}  // namespace contacts
PROTOBUF_NAMESPACE_OPEN
template<> ::contacts::LoginRequest* Arena::CreateMaybeMessage<::contacts::LoginRequest>(Arena*);
PROTOBUF_NAMESPACE_CLOSE
namespace contacts {// ===================================================================class LoginRequest final :public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:contacts.LoginRequest) */ {public:inline LoginRequest() : LoginRequest(nullptr) {}~LoginRequest() override;explicit constexpr LoginRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized);LoginRequest(const LoginRequest& from);LoginRequest(LoginRequest&& from) noexcept: LoginRequest() {*this = ::std::move(from);}inline LoginRequest& operator=(const LoginRequest& from) {CopyFrom(from);return *this;}inline LoginRequest& operator=(LoginRequest&& from) noexcept {if (this == &from) return *this;if (GetOwningArena() == from.GetOwningArena()#ifdef PROTOBUF_FORCE_COPY_IN_MOVE&& GetOwningArena() != nullptr#endif  // !PROTOBUF_FORCE_COPY_IN_MOVE) {InternalSwap(&from);} else {CopyFrom(from);}return *this;}static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() {return GetDescriptor();}static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() {return default_instance().GetMetadata().descriptor;}static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() {return default_instance().GetMetadata().reflection;}static const LoginRequest& default_instance() {return *internal_default_instance();}static inline const LoginRequest* internal_default_instance() {return reinterpret_cast<const LoginRequest*>(&_LoginRequest_default_instance_);}static constexpr int kIndexInFileMessages =0;friend void swap(LoginRequest& a, LoginRequest& b) {a.Swap(&b);}inline void Swap(LoginRequest* other) {if (other == this) return;#ifdef PROTOBUF_FORCE_COPY_IN_SWAPif (GetOwningArena() != nullptr &&GetOwningArena() == other->GetOwningArena()) {#else  // PROTOBUF_FORCE_COPY_IN_SWAPif (GetOwningArena() == other->GetOwningArena()) {#endif  // !PROTOBUF_FORCE_COPY_IN_SWAPInternalSwap(other);} else {::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other);}}void UnsafeArenaSwap(LoginRequest* other) {if (other == this) return;GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena());InternalSwap(other);}// implements Message ----------------------------------------------LoginRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final {return CreateMaybeMessage<LoginRequest>(arena);}using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom;void CopyFrom(const LoginRequest& from);using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom;void MergeFrom(const LoginRequest& from);private:static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to, const ::PROTOBUF_NAMESPACE_ID::Message& from);public:PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;bool IsInitialized() const final;size_t ByteSizeLong() const final;const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final;uint8_t* _InternalSerialize(uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final;int GetCachedSize() const final { return _cached_size_.Get(); }private:void SharedCtor();void SharedDtor();void SetCachedSize(int size) const final;void InternalSwap(LoginRequest* other);private:friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata;static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() {return "contacts.LoginRequest";}protected:explicit LoginRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena,bool is_message_owned = false);private:static void ArenaDtor(void* object);inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena);public:static const ClassData _class_data_;const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final;::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final;// nested types ----------------------------------------------------// accessors -------------------------------------------------------enum : int {kNameFieldNumber = 1,kPwdFieldNumber = 2,};// string name = 1;void clear_name();const std::string& name() const;template <typename ArgT0 = const std::string&, typename... ArgT>void set_name(ArgT0&& arg0, ArgT... args);std::string* mutable_name();PROTOBUF_NODISCARD std::string* release_name();void set_allocated_name(std::string* name);private:const std::string& _internal_name() const;inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value);std::string* _internal_mutable_name();public:// string pwd = 2;void clear_pwd();const std::string& pwd() const;template <typename ArgT0 = const std::string&, typename... ArgT>void set_pwd(ArgT0&& arg0, ArgT... args);std::string* mutable_pwd();PROTOBUF_NODISCARD std::string* release_pwd();void set_allocated_pwd(std::string* pwd);private:const std::string& _internal_pwd() const;inline PROTOBUF_ALWAYS_INLINE void _internal_set_pwd(const std::string& value);std::string* _internal_mutable_pwd();public:// @@protoc_insertion_point(class_scope:contacts.LoginRequest)private:class _Internal;template <typename T> friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper;typedef void InternalArenaConstructable_;typedef void DestructorSkippable_;::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_;::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr pwd_;mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;friend struct ::TableStruct_test_2eproto;
};
// ===================================================================// ===================================================================#ifdef __GNUC__#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif  // __GNUC__
// LoginRequest// string name = 1;
inline void LoginRequest::clear_name() {name_.ClearToEmpty();
}
inline const std::string& LoginRequest::name() const {// @@protoc_insertion_point(field_get:contacts.LoginRequest.name)return _internal_name();
}
template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void LoginRequest::set_name(ArgT0&& arg0, ArgT... args) {name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());// @@protoc_insertion_point(field_set:contacts.LoginRequest.name)
}
inline std::string* LoginRequest::mutable_name() {std::string* _s = _internal_mutable_name();// @@protoc_insertion_point(field_mutable:contacts.LoginRequest.name)return _s;
}
inline const std::string& LoginRequest::_internal_name() const {return name_.Get();
}
inline void LoginRequest::_internal_set_name(const std::string& value) {name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* LoginRequest::_internal_mutable_name() {return name_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* LoginRequest::release_name() {// @@protoc_insertion_point(field_release:contacts.LoginRequest.name)return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void LoginRequest::set_allocated_name(std::string* name) {if (name != nullptr) {} else {}name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name,GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRINGif (name_.IsDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited())) {name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING// @@protoc_insertion_point(field_set_allocated:contacts.LoginRequest.name)
}// string pwd = 2;
inline void LoginRequest::clear_pwd() {pwd_.ClearToEmpty();
}
inline const std::string& LoginRequest::pwd() const {// @@protoc_insertion_point(field_get:contacts.LoginRequest.pwd)return _internal_pwd();
}
template <typename ArgT0, typename... ArgT>
inline PROTOBUF_ALWAYS_INLINE
void LoginRequest::set_pwd(ArgT0&& arg0, ArgT... args) {pwd_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, static_cast<ArgT0 &&>(arg0), args..., GetArenaForAllocation());// @@protoc_insertion_point(field_set:contacts.LoginRequest.pwd)
}
inline std::string* LoginRequest::mutable_pwd() {std::string* _s = _internal_mutable_pwd();// @@protoc_insertion_point(field_mutable:contacts.LoginRequest.pwd)return _s;
}
inline const std::string& LoginRequest::_internal_pwd() const {return pwd_.Get();
}
inline void LoginRequest::_internal_set_pwd(const std::string& value) {pwd_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, value, GetArenaForAllocation());
}
inline std::string* LoginRequest::_internal_mutable_pwd() {return pwd_.Mutable(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, GetArenaForAllocation());
}
inline std::string* LoginRequest::release_pwd() {// @@protoc_insertion_point(field_release:contacts.LoginRequest.pwd)return pwd_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaForAllocation());
}
inline void LoginRequest::set_allocated_pwd(std::string* pwd) {if (pwd != nullptr) {} else {}pwd_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), pwd,GetArenaForAllocation());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRINGif (pwd_.IsDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited())) {pwd_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());}
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING// @@protoc_insertion_point(field_set_allocated:contacts.LoginRequest.pwd)
}#ifdef __GNUC__#pragma GCC diagnostic pop
#endif  // __GNUC__// @@protoc_insertion_point(namespace_scope)}  // namespace contacts// @@protoc_insertion_point(global_scope)#include <google/protobuf/port_undef.inc>
#endif  // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_test_2eproto

test.pb.ccd代码

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: test.proto#include "test.pb.h"#include <algorithm>#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// @@protoc_insertion_point(includes)
#include <google/protobuf/port_def.inc>PROTOBUF_PRAGMA_INIT_SEG
namespace contacts {
constexpr LoginRequest::LoginRequest(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized): name_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string), pwd_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){}
struct LoginRequestDefaultTypeInternal {constexpr LoginRequestDefaultTypeInternal(): _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}~LoginRequestDefaultTypeInternal() {}union {LoginRequest _instance;};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT LoginRequestDefaultTypeInternal _LoginRequest_default_instance_;
}  // namespace contacts
static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_test_2eproto[1];
static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_test_2eproto = nullptr;
static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_test_2eproto = nullptr;const uint32_t TableStruct_test_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {~0u,  // no _has_bits_PROTOBUF_FIELD_OFFSET(::contacts::LoginRequest, _internal_metadata_),~0u,  // no _extensions_~0u,  // no _oneof_case_~0u,  // no _weak_field_map_~0u,  // no _inlined_string_donated_PROTOBUF_FIELD_OFFSET(::contacts::LoginRequest, name_),PROTOBUF_FIELD_OFFSET(::contacts::LoginRequest, pwd_),
};
static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {{ 0, -1, -1, sizeof(::contacts::LoginRequest)},
};static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = {reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::contacts::_LoginRequest_default_instance_),
};const char descriptor_table_protodef_test_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) ="\n\ntest.proto\022\010contacts\")\n\014LoginRequest\022\014""\n\004name\030\001 \001(\t\022\013\n\003pwd\030\002 \001(\tb\006proto3";
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_test_2eproto_once;
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_test_2eproto = {false, false, 73, descriptor_table_protodef_test_2eproto, "test.proto", &descriptor_table_test_2eproto_once, nullptr, 0, 1,schemas, file_default_instances, TableStruct_test_2eproto::offsets,file_level_metadata_test_2eproto, file_level_enum_descriptors_test_2eproto, file_level_service_descriptors_test_2eproto,
};
PROTOBUF_ATTRIBUTE_WEAK const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable* descriptor_table_test_2eproto_getter() {return &descriptor_table_test_2eproto;
}// Force running AddDescriptors() at dynamic initialization time.
PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_test_2eproto(&descriptor_table_test_2eproto);
namespace contacts {// ===================================================================class LoginRequest::_Internal {public:
};LoginRequest::LoginRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena,bool is_message_owned): ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {SharedCtor();if (!is_message_owned) {RegisterArenaDtor(arena);}// @@protoc_insertion_point(arena_constructor:contacts.LoginRequest)
}
LoginRequest::LoginRequest(const LoginRequest& from): ::PROTOBUF_NAMESPACE_ID::Message() {_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRINGname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRINGif (!from._internal_name().empty()) {name_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_name(), GetArenaForAllocation());}pwd_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRINGpwd_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRINGif (!from._internal_pwd().empty()) {pwd_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_pwd(), GetArenaForAllocation());}// @@protoc_insertion_point(copy_constructor:contacts.LoginRequest)
}inline void LoginRequest::SharedCtor() {
name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRINGname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
pwd_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRINGpwd_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), "", GetArenaForAllocation());
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
}LoginRequest::~LoginRequest() {// @@protoc_insertion_point(destructor:contacts.LoginRequest)if (GetArenaForAllocation() != nullptr) return;SharedDtor();_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}inline void LoginRequest::SharedDtor() {GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());pwd_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}void LoginRequest::ArenaDtor(void* object) {LoginRequest* _this = reinterpret_cast< LoginRequest* >(object);(void)_this;
}
void LoginRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void LoginRequest::SetCachedSize(int size) const {_cached_size_.Set(size);
}void LoginRequest::Clear() {
// @@protoc_insertion_point(message_clear_start:contacts.LoginRequest)uint32_t cached_has_bits = 0;// Prevent compiler warnings about cached_has_bits being unused(void) cached_has_bits;name_.ClearToEmpty();pwd_.ClearToEmpty();_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}const char* LoginRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failurewhile (!ctx->Done(&ptr)) {uint32_t tag;ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);switch (tag >> 3) {// string name = 1;case 1:if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 10)) {auto str = _internal_mutable_name();ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "contacts.LoginRequest.name"));CHK_(ptr);} elsegoto handle_unusual;continue;// string pwd = 2;case 2:if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 18)) {auto str = _internal_mutable_pwd();ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "contacts.LoginRequest.pwd"));CHK_(ptr);} elsegoto handle_unusual;continue;default:goto handle_unusual;}  // switchhandle_unusual:if ((tag == 0) || ((tag & 7) == 4)) {CHK_(ptr);ctx->SetLastTag(tag);goto message_done;}ptr = UnknownFieldParse(tag,_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),ptr, ctx);CHK_(ptr != nullptr);}  // while
message_done:return ptr;
failure:ptr = nullptr;goto message_done;
#undef CHK_
}uint8_t* LoginRequest::_InternalSerialize(uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {// @@protoc_insertion_point(serialize_to_array_start:contacts.LoginRequest)uint32_t cached_has_bits = 0;(void) cached_has_bits;// string name = 1;if (!this->_internal_name().empty()) {::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(this->_internal_name().data(), static_cast<int>(this->_internal_name().length()),::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,"contacts.LoginRequest.name");target = stream->WriteStringMaybeAliased(1, this->_internal_name(), target);}// string pwd = 2;if (!this->_internal_pwd().empty()) {::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(this->_internal_pwd().data(), static_cast<int>(this->_internal_pwd().length()),::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE,"contacts.LoginRequest.pwd");target = stream->WriteStringMaybeAliased(2, this->_internal_pwd(), target);}if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);}// @@protoc_insertion_point(serialize_to_array_end:contacts.LoginRequest)return target;
}size_t LoginRequest::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:contacts.LoginRequest)size_t total_size = 0;uint32_t cached_has_bits = 0;// Prevent compiler warnings about cached_has_bits being unused(void) cached_has_bits;// string name = 1;if (!this->_internal_name().empty()) {total_size += 1 +::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(this->_internal_name());}// string pwd = 2;if (!this->_internal_pwd().empty()) {total_size += 1 +::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(this->_internal_pwd());}return MaybeComputeUnknownFieldsSize(total_size, &_cached_size_);
}const ::PROTOBUF_NAMESPACE_ID::Message::ClassData LoginRequest::_class_data_ = {::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,LoginRequest::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*LoginRequest::GetClassData() const { return &_class_data_; }void LoginRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message* to,const ::PROTOBUF_NAMESPACE_ID::Message& from) {static_cast<LoginRequest *>(to)->MergeFrom(static_cast<const LoginRequest &>(from));
}void LoginRequest::MergeFrom(const LoginRequest& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:contacts.LoginRequest)GOOGLE_DCHECK_NE(&from, this);uint32_t cached_has_bits = 0;(void) cached_has_bits;if (!from._internal_name().empty()) {_internal_set_name(from._internal_name());}if (!from._internal_pwd().empty()) {_internal_set_pwd(from._internal_pwd());}_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}void LoginRequest::CopyFrom(const LoginRequest& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:contacts.LoginRequest)if (&from == this) return;Clear();MergeFrom(from);
}bool LoginRequest::IsInitialized() const {return true;
}void LoginRequest::InternalSwap(LoginRequest* other) {using std::swap;auto* lhs_arena = GetArenaForAllocation();auto* rhs_arena = other->GetArenaForAllocation();_internal_metadata_.InternalSwap(&other->_internal_metadata_);::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),&name_, lhs_arena,&other->name_, rhs_arena);::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),&pwd_, lhs_arena,&other->pwd_, rhs_arena);
}::PROTOBUF_NAMESPACE_ID::Metadata LoginRequest::GetMetadata() const {return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_test_2eproto_getter, &descriptor_table_test_2eproto_once,file_level_metadata_test_2eproto[0]);
}// @@protoc_insertion_point(namespace_scope)
}  // namespace contacts
PROTOBUF_NAMESPACE_OPEN
template<> PROTOBUF_NOINLINE ::contacts::LoginRequest* Arena::CreateMaybeMessage< ::contacts::LoginRequest >(Arena* arena) {return Arena::CreateMessageInternal< ::contacts::LoginRequest >(arena);
}
PROTOBUF_NAMESPACE_CLOSE// @@protoc_insertion_point(global_scope)
#include <google/protobuf/port_undef.inc>
main.cpp test.proto
编译:test.proto protoc test.proto --cpp_out=./
g++ main.cpp test.pb.cc -I/usr/local/include -L/usr/local/lib -lprotobuf 

7、执行main.cpp代码

g++ main.cpp test.pb.cc -I/usr/local/include -L/usr/local/lib -lprotobuf 

8、查看ubuntu的版本:lsb_release -a,cat /etc/issue
9、查看内核版本:uname -r

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/134118.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

windows环境下安装Java过程(免登录Oracle官网下载java)

下载路径 oracle官网&#xff1a; java下载路径 Oracle共享账号可下载JDK&#xff1a; 指路 安装流程 执行下载后的jdk的可执行文件一路next下去&#xff0c; 可以自定义安装路径添加环境变量&#xff0c; 两个地方需要添加 在cmd中输入java -version 进行验证&#xff0c;…

计算/存储虚拟化高级特性

目录 计算虚拟化特性 HA高可用 虚拟机热迁移 虚拟机快照技术 存储虚拟化特性 链接克隆 存储热迁移 裸设备映射 计算虚拟化特性 HA高可用 通过HA&#xff08;High Available&#xff09;机制&#xff0c;可以提升虚拟机的可用度&#xff0c;允许虚拟机所在的服务器节点…

IP代理如何选择?4大误区你别踩!

近年来&#xff0c;我国互联网商业保持持续发展的状态大环境的优化&#xff0c;大大小小的企业都想乘胜追击&#xff0c;大展宏图&#xff0c;积极推动各项数据业务的进程。 而对于跨境业务来说&#xff0c;代理IP是不可或缺的重要工具之一&#xff0c;市面上代理IP类型众多&a…

每日一题(LeetCode)----数组--二分查找(四)

每日一题(LeetCode)----数组–二分查找&#xff08;四&#xff09; 1.题目&#xff08;367. 有效的完全平方数&#xff09; 给你一个正整数 num 。如果 num 是一个完全平方数&#xff0c;则返回 true &#xff0c;否则返回 false 。 完全平方数 是一个可以写成某个整数的平方…

获取狮子座明年恋爱运势预测API接口

获取狮子座明年恋爱运势预测API接口的功能是通过API接口获取狮子座明年恋爱运势的预测结果&#xff0c;为用户提供恋爱运势指导。 首先&#xff0c;使用挖数据平台该API接口需要先申请API密钥。在获取API密钥后&#xff0c;可以使用该接口进行开发。 API接口地址为&#xff1a…

基于卷积优化算法的无人机航迹规划-附代码

基于卷积优化算法的无人机航迹规划 文章目录 基于卷积优化算法的无人机航迹规划1.卷积优化搜索算法2.无人机飞行环境建模3.无人机航迹规划建模4.实验结果4.1地图创建4.2 航迹规划 5.参考文献6.Matlab代码 摘要&#xff1a;本文主要介绍利用卷积优化算法来优化无人机航迹规划。 …

【空调】空调主控板实习记录

空调主控板实习笔记记录1 空调型号 空调kfr35gw什么意思 { 这个表示空调是3500W的&#xff0c;是1.5匹空调。 除了以上所说&#xff0c;空调主要机型的型号标识及其含义&#xff1a; KFR-25GW&#xff0c;简称25机型。KFR-35GW&#xff0c;简称35机型。KFR-50LW&#xff0c…

跨境电商,用指纹浏览器还是VPS?有何区别?

目前做跨境电商的小伙伴基本都是选择vps或者指纹浏览器来防关联。不过随着指纹浏览器的普及&#xff0c;越来越多人选择使用指纹浏览器&#xff0c;还没了解过指纹浏览器的小伙伴可能还在犹豫&#xff0c;vps和指纹浏览器到底哪个更好呢&#xff1f; Vps就是一个虚拟服务器&…

sql学习笔记(三)

目录 1.四舍五入 2.向上取整 3.向下取整 4.Hive 分区 5.case when条件语句 6.日期函数 7.字符串函数 8.窗口函数 1️⃣排序函数 1.四舍五入 round select round(3.14) —>3 2.向上取整 ceiling select ceiling(12.15) —>13 3.向下取整 floor select flo…

计算机服务器中了locked勒索病毒怎么办,勒索病毒解密,数据恢复

随着网络技术的不断成熟&#xff0c;网络中存在的病毒威胁也不断增多&#xff0c;近期&#xff0c;云天数据恢复中心陆续接到很多企业的求助&#xff0c;企业的计算机服务器数据库遭到了勒索病毒攻击&#xff0c;并且勒索病毒的攻击与加密形式也发生了许多变化。其中攻击次数较…

jenkins部署job

apt install fontconfig openjdk-11-jre wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.429/jenkins.wardeb包安装 wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/debian-stable/jenkins_2.414.3_all.debdpkg -i jenkins_2.414.3_all.deb 访问 http://…

【亲测可用】SpringBoot使用Redis的Lettuce连接池报RedisCommandTimeoutException

目录 一、问题详情 二、根本原因 三、解决方案 一、问题详情 在最近新项目的开发当中,当项目刚启动的时候访问Redis服务一切正常,但是过了几分钟后再次访问Redis就报如下错误。 Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutExcept…

ElasticSearch高级功能详解与原理剖析

ES数据预处理 Ingest Node Elasticsearch 5.0后&#xff0c;引入的一种新的节点类型。默认配置下&#xff0c;每个节点都是Ingest Node&#xff1a; 具有预处理数据的能力&#xff0c;可拦截lndex或Bulk API的请求对数据进行转换&#xff0c;并重新返回给Index或Bulk APl 无…

第一篇-专题说明及当前进度

第一篇-专题说明及当前进度 专题说明及写作目的 从知道Rust、决定要学Rust到开始学Rust经历了一些时间&#xff0c;后面进一步了解C之后又鉴定了学习Rust的必要性。 鉴于Rust学习来有些痛苦&#xff0c;有点难&#xff0c;以及工作中暂时用不到、目前主要是go&#xff0c;本…

算法小白的心得笔记:关于Nan

NaN 是什么 在C中&#xff0c;NaN&#xff08;Not a Number&#xff09;是一种特殊的浮点数值&#xff0c;用于表示无法表示的数值或未定义的操作&#xff0c;例如0除以0。如果你的double类型变量显示为NaN&#xff0c;那么可能是在计算过程中出现了这种未定义的操作。 如果你…

SpringSecurity6 | 委派筛选器代理和过滤器链代理

✅作者简介&#xff1a;大家好&#xff0c;我是Leo&#xff0c;热爱Java后端开发者&#xff0c;一个想要与大家共同进步的男人&#x1f609;&#x1f609; &#x1f34e;个人主页&#xff1a;Leo的博客 &#x1f49e;当前专栏&#xff1a; Java从入门到精通 ✨特色专栏&#xf…

Unreal Engine 学习笔记 (1)—— 日夜交替

1.创建关卡 文件新建关卡空白关卡保存关卡&#xff08;命名为NewWorld&#xff09; 2.创建蓝图类 创建蓝图类&#xff08;继承自Actor&#xff09; 命名为SunAndMoon 3.编辑SunAndMoon蓝图类 添加SkyAtmosphere添加SkyLight添加DirectionalLight将DirectionalLight重命名为…

C++入门学习(1)命名空间和输入输出

前言 在C语言和基本的数据结构学习之后&#xff0c;我们终于迎来了期待已久的C啦&#xff01;C发明出来的意义就是填补一些C语言的不足&#xff0c;让我们更加方便的写代码&#xff0c;所以今天我们就来讲一下C语言不足的地方和在C中的解决办法&#xff01; 一、命名空间 在学习…

OWASP TOP 10-XML外部实体(XXE)

文章目录 XML基础漏洞原理攻击方式 XML基础 XML用于标记电子文件使其具有结构性的标记语言&#xff0c;可以用来标记数据、定义数据类型&#xff0c;是一种允许用户对自己的标记语言进行定义的源语言。XML文档结构包括XML声明、DTD文档类型定义&#xff08;可选&#xff09;、…

【机器学习3】有监督学习经典分类算法

1 支持向量机 在现实世界的机器学习领域&#xff0c; SVM涵盖了各个方面的知识&#xff0c; 也是面试题目中常见的基础模型。 SVM的分类结果仅依赖于支持向量&#xff0c;对于任意线性可分的两组点&#xff0c;它 们在SVM分类的超平面上的投影都是线性不可分的。 2逻辑回归 …