头文件
#include <iostream>
#include <stdio.h>
#include <string>
#include <Windows.h>
#include "winsock.h"
#pragma comment(lib, "wsock32")
using namespace std;
//通信消息/命令格式
struct VoteInfo
{
UINT64 count;
int candidate;
bool isInquiry;
bool isResponse;
};
int GetNextMsg(FILE *in, UINT8 *buf, size_t bufSize);
int PutMsg(UINT8 buf[], size_t msgSize, FILE *out);
size_t Encode(const VoteInfo *v, UINT8 *outBuf, const size_t bufSize);
bool Decode(UINT8 *inBuf, const size_t mSize, VoteInfo *v);
源文件:
#include "main.h"
static const char DELIMITER = '\n';
int GetNextMsg(FILE *in, UINT8 *buf, size_t bufSize)
{
int count = 0;
int nextChar;
while (count < bufSize)
{
fseek(in,0,SEEK_CUR);
nextChar = fgetc(in);
//模拟流的取出,一旦输出就不在保留了
//这样取完后,文件中就没有内容了
fseek(in,-1L,SEEK_CUR);
fputc(&#