Advertisement

Google Protobuf universal send-receive template for sockets

阅读量:

在数据传输过程中,需提供一个socket连接及Protobuf对象,传输时首先会发送数据的长度信息,随后才进行Protobuf数据的传输。

复制代码
 #pragma once

    
 #ifndef __PROTOC_H__
    
 #define __PROTOC_H__
    
  
    
 #include "ConnectProtocol.pb.h" //protobuf编译生成的定义文件
    
 #include <iostream>
    
 #include <string>
    
 template<typename T>
    
 inline int ReceiveGPTB(SOCKET & ClientSocket, T & CGPTB)
    
 {
    
 	int RecveIn = 0;
    
 	unsigned int DataLenth = 0;
    
 	unsigned int DataLenth_Img = 0;
    
  
    
 	char * p_DataLenth = (char *)&DataLenth;
    
  
    
 	unsigned int UIntSize = sizeof(unsigned int);
    
 	unsigned int UIntSiz

全部评论 (0)

还没有任何评论哟~