void NetUtils::Send( GameEngineMessage* input, net::Socket* socket ) { /////////////////////////////////////////////////////////////////// // Initialize payload /////////////////////////////////////////////////////////////////// printf( "Size after serilizing is %d\n", input->ByteSize() ); int size = input->ByteSize() + 4; char *packet = new char [size]; google::protobuf::io::ArrayOutputStream aos(packet,size); CodedOutputStream *coded_output = new CodedOutputStream(&aos); coded_output->WriteVarint32(input->ByteSize()); input->SerializeToCodedStream(coded_output); /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// // Client socket work - send payload to server /////////////////////////////////////////////////////////////////// bool sent = socket->Send( (void *) packet, size ); if( sent ) { // Reclaim memory. delete packet; } /////////////////////////////////////////////////////////////////// }
void blah (int code1, int code2) { int i; int n_sets; n_sets = (int) (code1 == 32); if (code2 == 64) goto L2; else goto L3; L2: aa (); L3: if (n_sets > 1) goto L4; else goto L10; L4: aos (); i = 0; goto L24; L10: if (n_sets > 0) goto L25; else goto L8; L25: i = 0; L24: aob (); i = i + 1; if (i < n_sets) goto L24; else goto L8; L8: return; }
int main (int argc, char *argv[]) { // Cube std::list<Plane> planes; planes.push_back(Plane(1, 0, 0, -1)); planes.push_back(Plane(-1, 0, 0, -1)); planes.push_back(Plane(0, 1, 0, -1)); planes.push_back(Plane(0, -1, 0, -1)); planes.push_back(Plane(0, 0, 1, -1)); planes.push_back(Plane(0, 0, -1, -1)); std::vector<Point> points; int N, steps; // Number of points if (argc > 1) { N = atoi(argv[1]); } else { N = 50; } // Number of steps if (argc > 2) { steps = atoi(argv[2]); } else { steps = 10; } CGAL::Random_points_in_sphere_3<Point> g; for (int i = 0; i < N; i++) { Point p = *g++; points.push_back(p); } std::ofstream bos("before_lloyd.xyz"); std::copy(points.begin(), points.end(), std::ostream_iterator<Point>(bos, "\n")); // Apply Lloyd algorithm: will generate points // uniformly sampled inside a cube. for (int i = 0; i < steps; i++) { std::cout << "iteration " << i + 1 << std::endl; CGAL::Timer timer; timer.start(); lloyd_algorithm(planes.begin(), planes.end(), points); timer.stop(); std::cout << "Execution time : " << timer.time() << "s\n"; } std::ofstream aos("after_lloyd.xyz"); std::copy(points.begin(), points.end(), std::ostream_iterator<Point>(aos, "\n")); return 0; }
void sendCheck(int sockfd, bool flags){ check::Check check; check.set_check(flags); int pkg_size = check.ByteSize() + 4; char* pkt = new char[pkg_size]; google::protobuf::io::ArrayOutputStream aos(pkt, pkg_size); google::protobuf::io::CodedOutputStream* coded_output = new google::protobuf::io::CodedOutputStream(&aos); coded_output -> WriteVarint32(check.ByteSize()); check.SerializeToCodedStream(coded_output); write(sockfd, pkt, pkg_size); }
size_t ProtobufSocketSerializer::serialize( const ::google::protobuf::Message &msg, char *&packet) { size_t size = PROTOBUF_HEADER_LENGTH + (size_t) msg.ByteSize(); packet = new char[size](); ::google::protobuf::io::ArrayOutputStream aos(packet, (int) size); ::google::protobuf::io::CodedOutputStream coded_output(&aos); coded_output.WriteLittleEndian32((google::protobuf::uint32) msg.ByteSize()); msg.SerializeToCodedStream(&coded_output); return size; }
void sendAction(int sockfd, std::string act){ action::Action action; action.set_action(act); int pkg_size = action.ByteSize() + HDR_SIZE; char* pkg = new char[pkg_size]; google::protobuf::io::ArrayOutputStream aos(pkg, pkg_size); google::protobuf::io::CodedOutputStream* coded_output = new google::protobuf::io::CodedOutputStream(&aos); coded_output -> WriteVarint32(action.ByteSize()); action.SerializeToCodedStream(coded_output); write(sockfd, pkg, pkg_size); delete coded_output; }
void send_port(int sockfd, int port_num, std::string ip){ port::Port port; port.set_port_num(port_num); port.set_ip(ip); int pkg_size = port.ByteSize() + HDR_SIZE; char* pkg = new char[pkg_size]; google::protobuf::io::ArrayOutputStream aos(pkg, pkg_size); google::protobuf::io::CodedOutputStream* coded_output = new google::protobuf::io::CodedOutputStream(&aos); coded_output -> WriteVarint32(port.ByteSize()); port.SerializeToCodedStream(coded_output); write(sockfd, pkg, pkg_size); delete coded_output; }
void search_info(int sockfd){ file::Files files; for(auto items=file_sets.begin(); items!=file_sets.end(); ++items){ file::File* file = files.add_files(); file->set_file_name(items -> first ); //std::cout << file->DebugString(); } int pkg_size = files.ByteSize() + HDR_SIZE; char* pkg = new char[pkg_size]; google::protobuf::io::ArrayOutputStream aos(pkg, pkg_size); google::protobuf::io::CodedOutputStream* coded_output = new google::protobuf::io::CodedOutputStream(&aos); coded_output -> WriteVarint32(files.ByteSize()); files.SerializeToCodedStream(coded_output); write(sockfd, pkg, pkg_size); delete coded_output; }
void send_online_info(int sockfd){ online::OnlineSheet sheet; for(int i=0; i<loginData.logindata_size(); ++i){ if( loginData.logindata(i).online() == true){ if( loginData.logindata(i).id() != "" ){ online::OnlinePerson* person; person = sheet.add_sheets(); person->set_name(loginData.logindata(i).id()); } } } int pkg_size = sheet.ByteSize() + HDR_SIZE; char* pkg = new char[pkg_size]; google::protobuf::io::ArrayOutputStream aos(pkg, pkg_size); google::protobuf::io::CodedOutputStream* coded_output = new google::protobuf::io::CodedOutputStream(&aos); coded_output -> WriteVarint32(sheet.ByteSize()); sheet.SerializeToCodedStream(coded_output); write(sockfd, pkg, pkg_size); delete coded_output; }
void send_download_info(int sockfd, std::set<std::string>& peer_set){ download::DownloadInfo peer_info; for(auto it=peer_set.begin(); it!=peer_set.end(); ++it){ for(int i=0; i<loginData.logindata_size(); ++i){ if( loginData.logindata(i).id() == *it && loginData.logindata(i).online() == true ) { download::Peer* peer = peer_info.add_peer_info(); peer->set_ip(loginData.logindata(i).ip()); peer->set_port(loginData.logindata(i).port()); } } } peer_info.set_file_byte_size(peer_set.size()); int pkg_size = peer_info.ByteSize() + HDR_SIZE; char* pkg = new char[pkg_size]; google::protobuf::io::ArrayOutputStream aos(pkg, pkg_size); google::protobuf::io::CodedOutputStream* coded_output = new google::protobuf::io::CodedOutputStream(&aos); coded_output -> WriteVarint32(peer_info.ByteSize()); peer_info.SerializeToCodedStream(coded_output); write(sockfd, pkg, pkg_size); delete coded_output; }