How to use parse_buf method in hypothesis

Best Python code snippet using hypothesis

build_sdb1.py

Source:build_sdb1.py Github

copy

Full Screen

1g_sdb1_cpp="sdb1.c"2g_sdb1_h="sdb1.h"3g_sphere_fields = [4 ["id", "int"], 5 ["name","string"], 6 ["uid","int"],7 ["level", "int"],8 ["prestige", "int"],9 ['desc', 'string'],10 ['is_npc', 'byte'],11 ]12g_city_fields = [13 ["id", "int"],14 ["sph_id","int"],15 ["level","byte"],16 ["name","string"],17 ["jun_name","string"],18 ["zhou_name","string"],19 ["desc","string"],20 ["defense","float"],21 ["is_alloted","byte"],22 ["x","int"],23 ["y","int"],24 ["jun_code","byte"],25 ["zhou_code","byte"],26 ['sol', 'int'],27 ]28g_general_fields = [29 ["id","int"], 30 ["uid","int"], 31 ["first_name","string"], 32 ["last_name","string"], 33 ["zi","string"], 34 ['type', 'byte'],35 ["sex","byte"], 36 ["is_dead","byte"], 37 ["born_year","short"], 38 ["init_year","short"], 39 ["die_year","short"], 40 ["face_id","int"], 41 ["place","byte"], 42 ["place_id","int"], 43 ["kongfu","int"], 44 ["speed","int"], 45 ["polity","int"], 46 ["intel","int"], 47 ["faith", "float"],48 ["skill", "uint"], 49 ["zhen", "uint"], 50 ["used_zhen", "uint"],51 ["sol_num", "uint"], 52 ["sol_spirit", "float"],53 ['level', 'int'],54 ['level_percent', 'int'],55 ['fri', 'int'],56 ['hurt_num', 'uint'],57 ['fol', 'int'],58 ]59g_army_fields = [60 ["id","int"],61 ["x","int"], 62 ["y","int"], 63 ["money","int"], 64 ["food","int"], 65 ["original","int"], 66 ["gene_id", "int"],67 ["type", "byte"],68 ['state', 'byte'],69 ['from_place', 'byte'],70 ['from_place_id', 'int'],71 ]72g_wubao_fields = [73 ["id", 'int'],74 ["uid", 'int'],75 ["people", 'int'],76 ["family", 'int'],77 ["prestige", 'int'],78 ["city_id", 'int'],79 ["sph_id", 'int'],80 ["dig_id", 'int'],81 ["off_id", 'int'],82 ["sol", 'int'],83 ["got_sol", 'int'],84 ["used_made", 'int'],85 ["cure_sol", 'int'], 86 ["max_gene", "int"],87 ["task_id", "int"],88 ["task_is_fin", "int"],89 ["last_welfare_time", "int"],90 ["last_login_time", "int"],91 ["been_plunder_num", "int"],92 ['use_gx_trea_num', 'int'],93 ['war_sleep_end_time', 'int'],94 ['train_sleep_end_time', 'int'],95 ['box_level', 'int'],96 ['rank', 'int'],97 ['gx', 'int'],98 ['jl', 'int'],99 ['fresh_step', 'int'],100 ]101g_cmd_trans_fields = [102 ["id", 'int'],103 ["type", 'int'],104 ["from_id", 'int'],105 ["to_id", 'int'],106 ["sph_id", 'int'],107 ["good_type", 'int'],108 ["good_id", 'int'],109 ["good_num", 'int'],110 ["end", 'int'],111 ]112g_order_fields = [113 ["id", 'int'],114 ["uid", 'int'],115 ["type", 'int'],116 ["res", 'int'],117 ["num", 'int'],118 ["deal_num", 'int'],119 ["unit_money", 'int'],120 ["last_unit_money", 'int'],121 ["money", 'int'],122 ["ts", 'int'],123 ]124g_sell_order_fields = [125 ["id", 'int'],126 ["uid", 'int'],127 ["weap_id", 'int'],128 ["weap_level", 'int'],129 ["weap_num", 'int'],130 ["gold", 'int'],131 ["ts", 'int'],132 ]133g_gk_fields = [134 ["id", 'int'],135 ["used", 'int'],136 ]137g_room_fields = [138 ["id", "int"],139 ["attack_sph_id", "int"],140 ["defense_sph_id", "int"],141 ["city_id", "int"],142 ["ts", "int"],143 ]144def write_header(f):145 buf = '''146#ifndef _SDB1_H_147#define _SDB1_H_148#include "game.h"149extern void create_sdb_sphere(int ver, Sph *sph, dstring *dst);150extern void create_sdb_general(int ver, Gene *gene, dstring *dst);151extern void create_sdb_army(int ver, Army *army, dstring *dst);152extern void create_sdb_city(int ver, City *city, dstring *dst);153extern void create_sdb_wubao(int ver, Wubao *w, dstring *dst);154extern void create_sdb_cmd_trans(int ver, CmdTrans *cmd, dstring *dst);155extern void create_sdb_order(int ver, Order *o, dstring *dst);156extern void create_sdb_sell_order(int ver, SellOrder *o, dstring *dst);157extern void create_sdb_gk(int ver, Guanka *p, dstring *dst);158extern void create_sdb_room(int ver, Room *p, dstring *dst);159extern bool parse_sdb_sphere(int ver, Shmem *src, Sph *sph);160extern bool parse_sdb_city(int ver, Shmem *src, City *city);161extern bool parse_sdb_general(int ver, Shmem *src, Gene *gene);162extern bool parse_sdb_army(int ver, Shmem *src, Army *army);163extern bool parse_sdb_wubao(int ver, Shmem *src, Wubao *w);164extern bool parse_sdb_cmd_trans(int ver, Shmem *src, CmdTrans *cmd);165extern bool parse_sdb_order(int ver, Shmem *src, Order *o);166extern bool parse_sdb_sell_order(int ver, Shmem *src, SellOrder *o);167extern bool parse_sdb_gk(int ver, Shmem *src, Guanka *p);168extern bool parse_sdb_room(int ver, Shmem *src, Room *p);169#endif170'''171 f.write(buf)172def write_sphere_func(f):173 create_buf = '''174void create_sdb_sphere(int version, Sph *sph, dstring *dst)175{176 if (!( dst && sph))177 return;''' + "\n"178 parse_buf = '''179bool parse_sdb_sphere(int ver, Shmem *src, Sph *sph)180{181 if (!(src && sph))182 return false;''' + "\n"183 for [k, v] in g_sphere_fields:184 t = "\tdstring_write_%s(dst, sph->%s);\n" % (v, k)185 if v == "string":186 t = "\tdstring_write_%s1(dst, sph->%s.buf, sph->%s.offset);\n" % (v, k, k)187 create_buf = create_buf + t188 t = "\tshmem_read_%s(src, &sph->%s);\n" % (v, k)189 parse_buf = parse_buf + t190 191 create_buf = create_buf + "}\n"192 parse_buf = parse_buf + "\treturn true;\n}\n"193 f.write(create_buf)194 f.write(parse_buf)195def write_city_func(f):196 create_buf = '''197void create_sdb_city(int version, City *city, dstring * dst)198{199 if (!(city && dst)) 200 return;201 '''202 parse_buf = '''203bool parse_sdb_city(int ver, Shmem *src, City *city)204{205 if (!(src && city)) 206 return false;207 208 '''209 for [k, v] in g_city_fields:210 t = "\tdstring_write_%s(dst, city->%s);\n" % (v, k)211 if v == "string":212 t = "\tdstring_write_%s1(dst, city->%s.buf, city->%s.offset);\n" % (v, k, k)213 create_buf = create_buf + t214 t = "\tshmem_read_%s(src, &city->%s);\n" % (v, k)215 parse_buf = parse_buf + t216 217 create_buf = create_buf + '''218} 219 '''220 221 parse_buf = parse_buf + '''222 return true; 223} 224 '''225 f.write(create_buf)226 f.write(parse_buf)227 228def write_general_func(f):229 create_buf = '''230void create_sdb_general(int version, Gene *gene, dstring *dst)231{232 if (!(gene && dst))233 return;234 int i = 0;235'''236 parse_buf = '''237bool parse_sdb_general(int ver, Shmem *src, Gene *gene)238{239 if (!(src && gene))240 return false;241 int i = 0;242'''243 for [k, v] in g_general_fields:244 t = "\tdstring_write_%s(dst, gene->%s);\n" % (v, k)245 if v == "string":246 t = "\tdstring_write_%s1(dst, gene->%s.buf, gene->%s.offset);\n" % (v, k, k)247 create_buf = create_buf + t248 t = "\tshmem_read_%s(src, &gene->%s);\n" % (v, k)249 parse_buf = parse_buf + t250 create_buf = create_buf + '''251 for(i = 0; i < GENE_WEAP_NUM; i++) {252 dstring_write_int(dst, gene->weap[i].id);253 dstring_write_int(dst, gene->weap[i].level);254 }255}256 257 '''258 259 parse_buf = parse_buf + '''260 261 for(i = 0; i < GENE_WEAP_NUM; i++) {262 shmem_read_int(src, &gene->weap[i].id);263 shmem_read_int(src, &gene->weap[i].level);264 }265 return true;266}267 '''268 f.write(create_buf)269 f.write(parse_buf)270def write_army_func(f):271 create_buf = '''272void create_sdb_army(int version, Army *army, dstring *dst)273{274 if (!(army && dst)) 275 return ;276'''277 parse_buf = '''278bool parse_sdb_army(int ver, Shmem *src, Army *army)279{280 if (!(src && army))281 return false;282'''283 for [k, v] in g_army_fields:284 t = "\tdstring_write_%s(dst, army->%s);\n" % (v, k)285 if v == "string":286 t = "\tdstring_write_%s1(dst, army->%s.buf, army->%s.offset);\n" % (v, k, k)287 create_buf = create_buf + t288 t = "\tshmem_read_%s(src, &army->%s);\n" % (v, k)289 parse_buf = parse_buf + t290 291 create_buf = create_buf + '''292}293 '''294 parse_buf = parse_buf + '''295 return true;296} 297 '''298 f.write(create_buf)299 f.write(parse_buf)300def write_wubao_func(f):301 create_buf = '''302void create_sdb_wubao(int version, Wubao *w, dstring *dst)303{304 if (!(w && dst)) 305 return ;306 307 int i = 0;308 int j = 0;309 Key *k ;310'''311 parse_buf = '''312bool parse_sdb_wubao(int ver, Shmem *src, Wubao *w)313{314 if (!(src && w))315 return false;316 Game *g = GAME;317 int i = 0;318 int j = 0;319 int num = 0;320'''321 for [k, v] in g_wubao_fields:322 t = "\tdstring_write_%s(dst, w->%s);\n" % (v, k)323 if v == "string":324 t = "\tdstring_write_%s1(dst, w->%s.buf, w->%s.offset);\n" % (v, k, k)325 create_buf = create_buf + t326 t = "\tshmem_read_%s(src, &w->%s);\n" % (v, k)327 parse_buf = parse_buf + t328 329 create_buf = create_buf + '''330 for(i = 0; i < RES_MAX - 1; i++) {331 dstring_write_int(dst, w->res[i]);332 }333 334 for(i = 0; i < WEAP_MAX - 1; i++) {335 for(j = 0; j < WEAP_LEVEL_MAX; j++) {336 dstring_write_int(dst, w->weap[i].id);337 dstring_write_int(dst, w->weap[i].num[j]);338 }339 }340 341 for(i = 0; i < BUILDING_MAX - 1; i++) {342 dstring_write_int(dst, w->build[i].id);343 dstring_write_int(dst, w->build[i].level);344 dstring_write_int(dst, w->build[i].up_end_time);345 }346 347 for(i = 0; i < TECH_MAX - 1; i++) {348 dstring_write_int(dst, w->tech[i].id);349 dstring_write_int(dst, w->tech[i].level);350 dstring_write_int(dst, w->tech[i].up_end_time);351 }352 dstring_write_int(dst, w->fri_num);353 RB_FOREACH(k, KeyMap, &w->fris) {354 dstring_write_int(dst, k->id);355 dstring_write_int(dst, (int)k->arg);356 }357 358 dstring_write_int(dst, w->task_fin_num);359 RB_FOREACH(k, KeyMap, &w->task_fins) {360 dstring_write_int(dst, k->id);361 }362 363}364 '''365 366 parse_buf = parse_buf + '''367 for(i = 0; i < RES_MAX - 1; i++) {368 shmem_read_int(src, &w->res[i]);369 }370 371 for(i = 0; i < WEAP_MAX - 1; i++) {372 for(j = 0; j < WEAP_LEVEL_MAX; j++) {373 shmem_read_int(src, &w->weap[i].id);374 shmem_read_int(src, &w->weap[i].num[j]);375 }376 }377 378 for(i = 0; i < BUILDING_MAX - 1; i++) {379 shmem_read_int(src, &w->build[i].id);380 shmem_read_int(src, &w->build[i].level);381 shmem_read_int(src, &w->build[i].up_end_time);382 }383 384 for(i = 0; i < TECH_MAX - 1; i++) {385 shmem_read_int(src, &w->tech[i].id);386 shmem_read_int(src, &w->tech[i].level);387 shmem_read_int(src, &w->tech[i].up_end_time);388 }389 390 shmem_read_int(src, &num);391 for(i = 0; i < num; i++) {392 int gene_id = 0;393 int fri = 0;394 shmem_read_int(src, &gene_id);395 shmem_read_int(src, &fri);396 wubao_add_fri(w, gene_id, fri);397 }398 399 shmem_read_int(src, &num);400 for(i = 0; i < num; i++) {401 int task_id = 0;402 Task *t = NULL;403 shmem_read_int(src, &task_id);404 if (!(t = game_find_task(g, task_id)))405 continue;406 wubao_add_task_fin(w, t);407 }408 return true;409} 410 '''411 f.write(create_buf)412 f.write(parse_buf)413def write_cmd_trans_func(f):414 create_buf = '''415void create_sdb_cmd_trans(int version, CmdTrans *cmd, dstring *dst)416{417 if (!(cmd && dst)) 418 return ;419'''420 parse_buf = '''421bool parse_sdb_cmd_trans(int ver, Shmem *src, CmdTrans *cmd)422{423 if (!(src && cmd))424 return false;425'''426 for [k, v] in g_cmd_trans_fields:427 t = "\tdstring_write_%s(dst, cmd->%s);\n" % (v, k)428 if v == "string":429 t = "\tdstring_write_%s1(dst, cmd->%s.buf, cmd->%s.offset);\n" % (v, k, k)430 create_buf = create_buf + t431 t = "\tshmem_read_%s(src, &cmd->%s);\n" % (v, k)432 parse_buf = parse_buf + t433 434 create_buf = create_buf + '''435 436}437 '''438 439 parse_buf = parse_buf + '''440 441 return true;442} 443 '''444 f.write(create_buf)445 f.write(parse_buf)446def write_order_func(f):447 create_buf = '''448void create_sdb_order(int version, Order *o, dstring *dst)449{450 if (!(o && dst)) 451 return ;452'''453 parse_buf = '''454bool parse_sdb_order(int ver, Shmem *src, Order *o)455{456 if (!(src && o))457 return false;458'''459 for [k, v] in g_order_fields:460 t = "\tdstring_write_%s(dst, o->%s);\n" % (v, k)461 if v == "string":462 t = "\tdstring_write_%s1(dst, o->%s.buf, o->%s.offset);\n" % (v, k, k)463 create_buf = create_buf + t464 t = "\tshmem_read_%s(src, &o->%s);\n" % (v, k)465 parse_buf = parse_buf + t466 467 create_buf = create_buf + '''468 469}470 '''471 472 parse_buf = parse_buf + '''473 474 return true;475} 476 '''477 f.write(create_buf)478 f.write(parse_buf)479def write_sell_order_func(f):480 create_buf = '''481void create_sdb_sell_order(int version, SellOrder *o, dstring *dst)482{483 if (!(o && dst)) 484 return ;485'''486 parse_buf = '''487bool parse_sdb_sell_order(int ver, Shmem *src, SellOrder *o)488{489 if (!(src && o))490 return false;491'''492 for [k, v] in g_sell_order_fields:493 t = "\tdstring_write_%s(dst, o->%s);\n" % (v, k)494 if v == "string":495 t = "\tdstring_write_%s1(dst, o->%s.buf, o->%s.offset);\n" % (v, k, k)496 create_buf = create_buf + t497 t = "\tshmem_read_%s(src, &o->%s);\n" % (v, k)498 parse_buf = parse_buf + t499 500 create_buf = create_buf + '''501 502}503 '''504 505 parse_buf = parse_buf + '''506 507 return true;508} 509 '''510 f.write(create_buf)511 f.write(parse_buf)512def write_gk_func(f):513 create_buf = '''514void create_sdb_gk(int version, Guanka *o, dstring *dst)515{516 if (!(o && dst)) 517 return ;518'''519 parse_buf = '''520bool parse_sdb_gk(int ver, Shmem *src, Guanka *o)521{522 if (!(src && o))523 return false;524'''525 for [k, v] in g_gk_fields:526 t = "\tdstring_write_%s(dst, o->%s);\n" % (v, k)527 if v == "string":528 t = "\tdstring_write_%s1(dst, o->%s.buf, o->%s.offset);\n" % (v, k, k)529 create_buf = create_buf + t530 t = "\tshmem_read_%s(src, &o->%s);\n" % (v, k)531 parse_buf = parse_buf + t532 533 create_buf = create_buf + '''534 535}536 '''537 538 parse_buf = parse_buf + '''539 540 return true;541} 542 '''543 f.write(create_buf)544 f.write(parse_buf)545def write_room_func(f):546 create_buf = '''547void create_sdb_room(int version, Room *p, dstring *dst)548{549 if (!(p && dst)) 550 return ;551 552 int i = 0;553'''554 parse_buf = '''555bool parse_sdb_room(int ver, Shmem *src, Room *p)556{557 if (!(src && p))558 return false;559 int i = 0;560'''561 for [k, v] in g_room_fields:562 t = "\tdstring_write_%s(dst, p->%s);\n" % (v, k)563 if v == "string":564 t = "\tdstring_write_%s1(dst, p->%s.buf, p->%s.offset);\n" % (v, k, k)565 create_buf = create_buf + t566 t = "\tshmem_read_%s(src, &p->%s);\n" % (v, k)567 parse_buf = parse_buf + t568 569 create_buf = create_buf + '''570 for(i = 0; i < ROOM_USER_NUM; i++) {571 dstring_write_int(dst, p->attack_uid[i]);572 }573 574 for(i = 0; i < ROOM_USER_NUM; i++) {575 dstring_write_int(dst, p->defense_uid[i]);576 }577 578}579 '''580 581 parse_buf = parse_buf + '''582 for(i = 0; i < ROOM_USER_NUM; i++) {583 shmem_read_int(src, &p->attack_uid[i]);584 }585 586 for(i = 0; i < ROOM_USER_NUM; i++) {587 shmem_read_int(src, &p->defense_uid[i]);588 }589 return true;590} 591 '''592 f.write(create_buf)593 f.write(parse_buf)594if __name__ == '__main__':595 header = open(g_sdb1_h, "w")596 cpp = open(g_sdb1_cpp, "w")597 cpp.write("#include \"hf.h\"\n")598 write_header(header)599 write_sphere_func(cpp)600 write_city_func(cpp)601 write_general_func(cpp)602 write_army_func(cpp)603 write_wubao_func(cpp)604 write_cmd_trans_func(cpp)605 write_order_func(cpp)606 write_sell_order_func(cpp)607 write_gk_func(cpp)608 write_room_func(cpp)609 header.write("\n")610 header.close()611 cpp.write("\n")...

Full Screen

Full Screen

build_sdb2.py

Source:build_sdb2.py Github

copy

Full Screen

1g_sdb1_cpp="sdb2.c"2g_sdb1_h="sdb2.h"3g_sphere_fields = [4 ["id", "int"], 5 ["name","string"], 6 ["uid","int"],7 ["level", "int"],8 ["prestige", "int"],9 ['desc', 'string'],10 ['is_npc', 'byte'],11 ]12g_city_fields = [13 ["id", "int"],14 ["sph_id","int"],15 ["level","byte"],16 ["name","string"],17 ["jun_name","string"],18 ["zhou_name","string"],19 ["desc","string"],20 ["defense","float"],21 ["is_alloted","byte"],22 ["x","int"],23 ["y","int"],24 ["jun_code","byte"],25 ["zhou_code","byte"],26 ['sol', 'int'],27 ]28g_general_fields = [29 ["id","int"], 30 ["uid","int"], 31 ["first_name","string"], 32 ["last_name","string"], 33 ["zi","string"], 34 ['type', 'byte'],35 ["sex","byte"], 36 ["is_dead","byte"], 37 ["born_year","short"], 38 ["init_year","short"], 39 ["die_year","short"], 40 ["face_id","int"], 41 ["place","byte"], 42 ["place_id","int"], 43 ["kongfu","int"], 44 ["speed","int"], 45 ["polity","int"], 46 ["intel","int"], 47 ["faith", "float"],48 ["skill", "uint"], 49 ["zhen", "uint"], 50 ["used_zhen", "uint"],51 ["sol_num", "uint"], 52 ["sol_spirit", "float"],53 ['fri', 'int'],54 ['hurt_num', 'uint'],55 ['fol', 'int'],56 ]57g_army_fields = [58 ["id","int"],59 ["x","int"], 60 ["y","int"], 61 ["money","int"], 62 ["food","int"], 63 ["original","int"], 64 ["gene_id", "int"],65 ["type", "byte"],66 ['state', 'byte'],67 ['from_place', 'byte'],68 ['from_place_id', 'int'],69 ]70g_wubao_fields = [71 ["id", 'int'],72 ["uid", 'int'],73 ["people", 'int'],74 ["family", 'int'],75 ["prestige", 'int'],76 ["city_id", 'int'],77 ["sph_id", 'int'],78 ["dig_id", 'int'],79 ["off_id", 'int'],80 ["sol", 'int'],81 ["got_sol", 'int'],82 ["used_made", 'int'],83 ["cure_sol", 'int'], 84 ["max_gene", "int"],85 ["task_id", "int"],86 ["task_is_fin", "int"],87 ["last_welfare_time", "int"],88 ]89g_cmd_trans_fields = [90 ["id", 'int'],91 ["type", 'int'],92 ["from_id", 'int'],93 ["to_id", 'int'],94 ["sph_id", 'int'],95 ["good_type", 'int'],96 ["good_id", 'int'],97 ["good_num", 'int'],98 ["end", 'int'],99 ]100g_order_fields = [101 ["id", 'int'],102 ["uid", 'int'],103 ["type", 'int'],104 ["res", 'int'],105 ["num", 'int'],106 ["deal_num", 'int'],107 ["unit_money", 'int'],108 ["last_unit_money", 'int'],109 ["money", 'int'],110 ["ts", 'int'],111 ]112g_sell_order_fields = [113 ["id", 'int'],114 ["uid", 'int'],115 ["weap_id", 'int'],116 ["weap_level", 'int'],117 ["weap_num", 'int'],118 ["gold", 'int'],119 ["ts", 'int'],120 ]121g_gk_fields = [122 ["id", 'int'],123 ["used", 'int'],124 ]125g_room_fields = [126 ["id", "int"],127 ["attack_sph_id", "int"],128 ["defense_sph_id", "int"],129 ["city_id", "int"],130 ["ts", "int"],131 ]132def write_header(f):133 buf = '''134#ifndef _SDB2_H_135#define _SDB2_H_136#include "game.h"137extern void create_sdb_sphere1(int ver, Sph *sph, dstring *dst);138extern void create_sdb_general1(int ver, Gene *gene, dstring *dst);139extern void create_sdb_army1(int ver, Army *army, dstring *dst);140extern void create_sdb_city1(int ver, City *city, dstring *dst);141extern void create_sdb_wubao1(int ver, Wubao *w, dstring *dst);142extern void create_sdb_cmd_trans1(int ver, CmdTrans *cmd, dstring *dst);143extern void create_sdb_order1(int ver, Order *o, dstring *dst);144extern void create_sdb_sell_order1(int ver, SellOrder *o, dstring *dst);145extern void create_sdb_gk1(int ver, Guanka *o, dstring *dst);146extern void create_sdb_room1(int ver, Room *o, dstring *dst);147extern bool parse_sdb_sphere1(int ver, Shmem *src, Sph *sph);148extern bool parse_sdb_city1(int ver, Shmem *src, City *city);149extern bool parse_sdb_general1(int ver, Shmem *src, Gene *gene);150extern bool parse_sdb_army1(int ver, Shmem *src, Army *army);151extern bool parse_sdb_wubao1(int ver, Shmem *src, Wubao *w);152extern bool parse_sdb_cmd_trans1(int ver, Shmem *src, CmdTrans *cmd);153extern bool parse_sdb_order1(int ver, Shmem *src, Order *o);154extern bool parse_sdb_sell_order1(int ver, Shmem *src, SellOrder *o);155extern bool parse_sdb_gk1(int ver, Shmem *src, Guanka *o);156extern bool parse_sdb_room1(int ver, Shmem *src, Room *o);157#endif158'''159 f.write(buf)160def write_sphere_func(f):161 create_buf = '''162void create_sdb_sphere1(int version, Sph *sph, dstring *dst)163{164 if (!( dst && sph))165 return;''' + "\n"166 parse_buf = '''167bool parse_sdb_sphere1(int ver, Shmem *src, Sph *sph)168{169 if (!(src && sph))170 return false;''' + "\n"171 for [k, v] in g_sphere_fields:172 t = "\tdstring_write_%s(dst, sph->%s);\n" % (v, k)173 if v == "string":174 t = "\tdstring_write_%s1(dst, sph->%s.buf, sph->%s.offset);\n" % (v, k, k)175 create_buf = create_buf + t176 t = "\tshmem_read_%s(src, &sph->%s);\n" % (v, k)177 parse_buf = parse_buf + t178 179 create_buf = create_buf + "}\n"180 parse_buf = parse_buf + "\treturn true;\n}\n"181 f.write(create_buf)182 f.write(parse_buf)183def write_city_func(f):184 create_buf = '''185void create_sdb_city1(int version, City *city, dstring * dst)186{187 if (!(city && dst)) 188 return;189 '''190 parse_buf = '''191bool parse_sdb_city1(int ver, Shmem *src, City *city)192{193 if (!(src && city)) 194 return false;195 196 '''197 for [k, v] in g_city_fields:198 t = "\tdstring_write_%s(dst, city->%s);\n" % (v, k)199 if v == "string":200 t = "\tdstring_write_%s1(dst, city->%s.buf, city->%s.offset);\n" % (v, k, k)201 create_buf = create_buf + t202 t = "\tshmem_read_%s(src, &city->%s);\n" % (v, k)203 parse_buf = parse_buf + t204 205 create_buf = create_buf + '''206} 207 '''208 209 parse_buf = parse_buf + '''210 return true; 211} 212 '''213 f.write(create_buf)214 f.write(parse_buf)215 216def write_general_func(f):217 create_buf = '''218void create_sdb_general1(int version, Gene *gene, dstring *dst)219{220 if (!(gene && dst))221 return;222 int i = 0;223'''224 parse_buf = '''225bool parse_sdb_general1(int ver, Shmem *src, Gene *gene)226{227 if (!(src && gene))228 return false;229 int i = 0;230'''231 for [k, v] in g_general_fields:232 t = "\tdstring_write_%s(dst, gene->%s);\n" % (v, k)233 if v == "string":234 t = "\tdstring_write_%s1(dst, gene->%s.buf, gene->%s.offset);\n" % (v, k, k)235 create_buf = create_buf + t236 t = "\tshmem_read_%s(src, &gene->%s);\n" % (v, k)237 parse_buf = parse_buf + t238 create_buf = create_buf + '''239 for(i = 0; i < GENE_WEAP_NUM; i++) {240 dstring_write_int(dst, gene->weap[i].id);241 dstring_write_int(dst, gene->weap[i].level);242 }243}244 245 '''246 247 parse_buf = parse_buf + '''248 249 for(i = 0; i < GENE_WEAP_NUM; i++) {250 shmem_read_int(src, &gene->weap[i].id);251 shmem_read_int(src, &gene->weap[i].level);252 }253 return true;254}255 '''256 f.write(create_buf)257 f.write(parse_buf)258def write_army_func(f):259 create_buf = '''260void create_sdb_army1(int version, Army *army, dstring *dst)261{262 if (!(army && dst)) 263 return ;264'''265 parse_buf = '''266bool parse_sdb_army1(int ver, Shmem *src, Army *army)267{268 if (!(src && army))269 return false;270'''271 for [k, v] in g_army_fields:272 t = "\tdstring_write_%s(dst, army->%s);\n" % (v, k)273 if v == "string":274 t = "\tdstring_write_%s1(dst, army->%s.buf, army->%s.offset);\n" % (v, k, k)275 create_buf = create_buf + t276 t = "\tshmem_read_%s(src, &army->%s);\n" % (v, k)277 parse_buf = parse_buf + t278 279 create_buf = create_buf + '''280}281 '''282 parse_buf = parse_buf + '''283 return true;284} 285 '''286 f.write(create_buf)287 f.write(parse_buf)288def write_wubao_func(f):289 create_buf = '''290void create_sdb_wubao1(int version, Wubao *w, dstring *dst)291{292 if (!(w && dst)) 293 return ;294 295 int i = 0;296 int j = 0;297 Key *k ;298'''299 parse_buf = '''300bool parse_sdb_wubao1(int ver, Shmem *src, Wubao *w)301{302 if (!(src && w))303 return false;304 Game *g = GAME;305 int i = 0;306 int j = 0;307 int num = 0;308'''309 for [k, v] in g_wubao_fields:310 t = "\tdstring_write_%s(dst, w->%s);\n" % (v, k)311 if v == "string":312 t = "\tdstring_write_%s1(dst, w->%s.buf, w->%s.offset);\n" % (v, k, k)313 create_buf = create_buf + t314 t = "\tshmem_read_%s(src, &w->%s);\n" % (v, k)315 parse_buf = parse_buf + t316 317 create_buf = create_buf + '''318 for(i = 0; i < RES_MAX - 1; i++) {319 dstring_write_int(dst, w->res[i]);320 }321 322 for(i = 0; i < WEAP_MAX - 1; i++) {323 for(j = 0; j < WEAP_LEVEL_MAX; j++) {324 dstring_write_int(dst, w->weap[i].id);325 dstring_write_int(dst, w->weap[i].num[j]);326 }327 }328 329 for(i = 0; i < BUILDING_MAX - 1; i++) {330 dstring_write_int(dst, w->build[i].id);331 dstring_write_int(dst, w->build[i].level);332 dstring_write_int(dst, w->build[i].up_end_time);333 }334 335 for(i = 0; i < TECH_MAX - 1; i++) {336 dstring_write_int(dst, w->tech[i].id);337 dstring_write_int(dst, w->tech[i].level);338 dstring_write_int(dst, w->tech[i].up_end_time);339 }340 dstring_write_int(dst, w->fri_num);341 RB_FOREACH(k, KeyMap, &w->fris) {342 dstring_write_int(dst, k->id);343 dstring_write_int(dst, (int)k->arg);344 }345 346 dstring_write_int(dst, w->task_fin_num);347 RB_FOREACH(k, KeyMap, &w->task_fins) {348 dstring_write_int(dst, k->id);349 }350 351}352 '''353 354 parse_buf = parse_buf + '''355 for(i = 0; i < RES_MAX - 1; i++) {356 shmem_read_int(src, &w->res[i]);357 }358 359 for(i = 0; i < WEAP_MAX - 1; i++) {360 for(j = 0; j < WEAP_LEVEL_MAX; j++) {361 shmem_read_int(src, &w->weap[i].id);362 shmem_read_int(src, &w->weap[i].num[j]);363 }364 }365 366 for(i = 0; i < BUILDING_MAX - 1; i++) {367 shmem_read_int(src, &w->build[i].id);368 shmem_read_int(src, &w->build[i].level);369 shmem_read_int(src, &w->build[i].up_end_time);370 }371 372 for(i = 0; i < TECH_MAX - 1; i++) {373 shmem_read_int(src, &w->tech[i].id);374 shmem_read_int(src, &w->tech[i].level);375 shmem_read_int(src, &w->tech[i].up_end_time);376 }377 378 shmem_read_int(src, &num);379 for(i = 0; i < num; i++) {380 int gene_id = 0;381 int fri = 0;382 shmem_read_int(src, &gene_id);383 shmem_read_int(src, &fri);384 wubao_add_fri(w, gene_id, fri);385 }386 387 shmem_read_int(src, &num);388 for(i = 0; i < num; i++) {389 int task_id = 0;390 Task *t = NULL;391 shmem_read_int(src, &task_id);392 if (!(t = game_find_task(g, task_id)))393 continue;394 wubao_add_task_fin(w, t);395 }396 return true;397} 398 '''399 f.write(create_buf)400 f.write(parse_buf)401def write_cmd_trans_func(f):402 create_buf = '''403void create_sdb_cmd_trans1(int version, CmdTrans *cmd, dstring *dst)404{405 if (!(cmd && dst)) 406 return ;407'''408 parse_buf = '''409bool parse_sdb_cmd_trans1(int ver, Shmem *src, CmdTrans *cmd)410{411 if (!(src && cmd))412 return false;413'''414 for [k, v] in g_cmd_trans_fields:415 t = "\tdstring_write_%s(dst, cmd->%s);\n" % (v, k)416 if v == "string":417 t = "\tdstring_write_%s1(dst, cmd->%s.buf, cmd->%s.offset);\n" % (v, k, k)418 create_buf = create_buf + t419 t = "\tshmem_read_%s(src, &cmd->%s);\n" % (v, k)420 parse_buf = parse_buf + t421 422 create_buf = create_buf + '''423 424}425 '''426 427 parse_buf = parse_buf + '''428 429 return true;430} 431 '''432 f.write(create_buf)433 f.write(parse_buf)434def write_order_func(f):435 create_buf = '''436void create_sdb_order1(int version, Order *o, dstring *dst)437{438 if (!(o && dst)) 439 return ;440'''441 parse_buf = '''442bool parse_sdb_order1(int ver, Shmem *src, Order *o)443{444 if (!(src && o))445 return false;446'''447 for [k, v] in g_order_fields:448 t = "\tdstring_write_%s(dst, o->%s);\n" % (v, k)449 if v == "string":450 t = "\tdstring_write_%s1(dst, o->%s.buf, o->%s.offset);\n" % (v, k, k)451 create_buf = create_buf + t452 t = "\tshmem_read_%s(src, &o->%s);\n" % (v, k)453 parse_buf = parse_buf + t454 455 create_buf = create_buf + '''456 457}458 '''459 460 parse_buf = parse_buf + '''461 462 return true;463} 464 '''465 f.write(create_buf)466 f.write(parse_buf)467def write_sell_order_func(f):468 create_buf = '''469void create_sdb_sell_order1(int version, SellOrder *o, dstring *dst)470{471 if (!(o && dst)) 472 return ;473'''474 parse_buf = '''475bool parse_sdb_sell_order1(int ver, Shmem *src, SellOrder *o)476{477 if (!(src && o))478 return false;479'''480 for [k, v] in g_sell_order_fields:481 t = "\tdstring_write_%s(dst, o->%s);\n" % (v, k)482 if v == "string":483 t = "\tdstring_write_%s1(dst, o->%s.buf, o->%s.offset);\n" % (v, k, k)484 create_buf = create_buf + t485 t = "\tshmem_read_%s(src, &o->%s);\n" % (v, k)486 parse_buf = parse_buf + t487 488 create_buf = create_buf + '''489 490}491 '''492 493 parse_buf = parse_buf + '''494 495 return true;496} 497 '''498 f.write(create_buf)499 f.write(parse_buf)500def write_gk_func(f):501 create_buf = '''502void create_sdb_gk1(int version, Guanka *o, dstring *dst)503{504 if (!(o && dst)) 505 return ;506'''507 parse_buf = '''508bool parse_sdb_gk1(int ver, Shmem *src, Guanka *o)509{510 if (!(src && o))511 return false;512'''513 for [k, v] in g_gk_fields:514 t = "\tdstring_write_%s(dst, o->%s);\n" % (v, k)515 if v == "string":516 t = "\tdstring_write_%s1(dst, o->%s.buf, o->%s.offset);\n" % (v, k, k)517 create_buf = create_buf + t518 t = "\tshmem_read_%s(src, &o->%s);\n" % (v, k)519 parse_buf = parse_buf + t520 521 create_buf = create_buf + '''522 523}524 '''525 526 parse_buf = parse_buf + '''527 528 return true;529} 530 '''531 f.write(create_buf)532 f.write(parse_buf)533def write_room_func(f):534 create_buf = '''535void create_sdb_room1(int version, Room *p, dstring *dst)536{537 if (!(p && dst)) 538 return ;539 540 int i = 0;541'''542 parse_buf = '''543bool parse_sdb_room1(int ver, Shmem *src, Room *p)544{545 if (!(src && p))546 return false;547 int i = 0;548'''549 for [k, v] in g_room_fields:550 t = "\tdstring_write_%s(dst, p->%s);\n" % (v, k)551 if v == "string":552 t = "\tdstring_write_%s1(dst, p->%s.buf, p->%s.offset);\n" % (v, k, k)553 create_buf = create_buf + t554 t = "\tshmem_read_%s(src, &p->%s);\n" % (v, k)555 parse_buf = parse_buf + t556 557 create_buf = create_buf + '''558 for(i = 0; i < ROOM_USER_NUM; i++) {559 dstring_write_int(dst, p->attack_uid[i]);560 }561 562 for(i = 0; i < ROOM_USER_NUM; i++) {563 dstring_write_int(dst, p->defense_uid[i]);564 }565 566}567 '''568 569 parse_buf = parse_buf + '''570 for(i = 0; i < ROOM_USER_NUM; i++) {571 shmem_read_int(src, &p->attack_uid[i]);572 }573 574 for(i = 0; i < ROOM_USER_NUM; i++) {575 shmem_read_int(src, &p->defense_uid[i]);576 }577 return true;578} 579 '''580 f.write(create_buf)581 f.write(parse_buf)582if __name__ == '__main__':583 header = open(g_sdb1_h, "w")584 cpp = open(g_sdb1_cpp, "w")585 cpp.write("#include \"hf.h\"\n")586 write_header(header)587 write_sphere_func(cpp)588 write_city_func(cpp)589 write_general_func(cpp)590 write_army_func(cpp)591 write_wubao_func(cpp)592 write_cmd_trans_func(cpp)593 write_order_func(cpp)594 write_sell_order_func(cpp)595 write_gk_func(cpp)596 write_room_func(cpp)597 header.write("\n")598 header.close()599 cpp.write("\n")...

Full Screen

Full Screen

test_sock.py

Source:test_sock.py Github

copy

Full Screen

...13 print(reply)14 assert(replies != "")15 s = Sock()16 s.buf = "\r\nx\r\n"17 x = s.parse_buf()18 assert(x[0] == "x")19 s.buf = "\r\n"20 x = s.parse_buf()21 assert(x == [])22 s.buf = "\r\n\r\n"23 x = s.parse_buf()24 assert(x == [])25 s.buf = "\r\r\n\r\n"26 x = s.parse_buf()27 assert(x[0] == "\r")28 s.buf = "\r\n\r\n\r\nx"29 x = s.parse_buf()30 assert(x == [])31 s.buf = "\r\n\r\nx\r\nsdfsdfsdf\r\n"32 x = s.parse_buf()33 assert(x[0] == "x" and x[1] == "sdfsdfsdf")34 s.buf = "sdfsdfsdf\r\n"35 s.parse_buf()36 s.buf += "abc\r\n"37 x = s.parse_buf()38 assert(x[0] == "abc")39 s.buf += "\r\ns\r\n"40 x = s.parse_buf()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful