C语言通过结构体来“封装”一个业务的中要处理的数据。
如果这个数据比较多,建议拆成多个子结构体,分解业务各个模块数据,总的业务模块再包含各个子模块结构体。
这样更容易处理和分离不同的业务,保证了数据互不影响。
并且这样条理会更加清晰。
如:
struct gvod_session_s
{
char read_again;
time_t now;
gvod_sockfd_t sockfd;
gvod_pool_t *pool;
gvod_buff_t recvbuf;
gvod_buff_t sendbuf;
gvod_db_pool_t *dbpool;
gvod_login_info_t login_info;
gvod_region_list_t region_list;
gvod_language_list_t language_list;
gvod_category_list_t category_list;
gvod_genre_list_t genre_list;
gvod_request_info_t request;
gvod_request_info_t last_request;
gvod_program_list_t program_list;
gvod_program_info_t program_info;
gvod_song_list_t song_list;
//save multi song is paid or not
int save_flag[32];
/* for parse url */
ytb_url_t url[YTB_MAX_URL_NUM];
int url_num;
};
struct gvod_song_list_s
{
unsigned int total;
unsigned int num; //the total number of song
gvod_song_t song[GVOD_MAX_NUM_PER_PAGE + 1];
};
struct gvod_song_s
{
int episode;
char media_id[GVOD_LEN_MEDIA_ID + 1];
char name[GVOD_LEN_NAME_PROGRAM + 1];
char url[GVOD_LEN_URL_PROGRAM + 1];
char thumbnail_url[GVOD_LEN_URL_PROGRAM + 1];
char publish_by[GVOD_LEN_PUBLISH_BY+1];
};
gvod_session_s对所用的业务数据进行了封装,通过一个结构体就能获得和处理所用的业务信息,每个不同的业务又用一个不同的结构体封装数据。