void S1mmeSession::CtEncodeKqi(S1MMEKQI* kqi, S1APNode* p_node, uint8_t worker_id) { MsgCommonInfo& common = p_node->GetCommonInfo(); SPUserInfo& sp_user_info = p_node->GetUserInfo(); //获取 buf TlvEncoder* p_encoder_cur = g_p_encoder_[worker_id]; YdCDR_T* p_dst_data = (YdCDR_T*)malloc(sizeof(YdCDR_T)); if (p_dst_data == NULL) { return; } p_dst_data->not_associate = 0; if ((common.not_associate & 0x03) == 0x03) p_dst_data->not_associate = 1; p_encoder_cur->Set(p_dst_data->cdr_data,kMaxOneCdrBufLen); uint64_t imsi = sp_user_info->GetIMSI(); if(common.eci == 0) { common.eci = sp_user_info->GetEci(); } uint16_t tmp_enbid = common.tac;//>>8; //uint32_t tmp_enbid = (common.eci >> 8)&0xfffff; char xdrid_str[32]={0}; #ifdef OPEN_NEW_HUISU convert_xdrid_to_string(xdrid_str, kqi->xdrid, s_xdr_id_len); #else #ifdef OPENCTPR g4sigtran::pr::ProcBlock* p_blk = kqi->binary_block_in_xdr_.GetBlock(); p_blk->SerializeXid(xdrid_str, sizeof(xdrid_str)); #else uint64_t subcdrid = g_ct_xdr_id.GetXid(); //reverse subend; if(::is_open_reverse) { SetReverseSubend(p_node, subcdrid); } #ifdef ONE_THIRD_YUNNAN_MRO g_ct_xdr_id.Serialize((uint8_t*)xdrid_str, s_xdr_id_len, imsi); #else g_ct_xdr_id.Serialize((uint8_t*)xdrid_str, s_xdr_id_len); #endif #endif #endif struct timespec start_time = kqi->request_time_, end_time = kqi->response_time_; if (kqi->request_time_.tv_sec == 0) { if (!(kqi->response_time_.tv_sec == 0)) { start_time = kqi->response_time_; } else if (!(kqi->complete_time_.tv_sec == 0)) { start_time = kqi->complete_time_; } } 在S1mmeSession::CtEncodeKqi函数最后面加一个函数,来维护一组key、value的关系。 key:imsi value:imsi、imei、common.eci、common.tac、last_time 要求,imsi相同时,以最后一条记录的value内容为准进行保存。
时间: 2024-03-29 16:41:10 浏览: 77
可以使用一个 std::unordered_map 来维护这组 key-value 的关系,其中 key 为 imsi,value 为一个结构体,包含了 imsi、imei、common.eci、common.tac、last_time 等信息。每次调用 CtEncodeKqi 函数时,先从 unordered_map 中查找该 imsi 是否已经存在,如果存在则更新该 imsi 对应的 value 值,否则插入一个新的 key-value 对。最后需要注意,当 unordered_map 中的 value 被更新时,需要同时更新 last_time 值为当前时间。
相关问题
void S1mmeSession::CtEncodeKqi(S1MMEKQI* kqi, S1APNode* p_node, uint8_t worker_id) { MsgCommonInfo& common = p_node->GetCommonInfo(); SPUserInfo& sp_user_info = p_node->GetUserInfo(); //获取 buf TlvEncoder* p_encoder_cur = g_p_encoder_[worker_id]; YdCDR_T* p_dst_data = (YdCDR_T*)malloc(sizeof(YdCDR_T)); if (p_dst_data == NULL) { return; } p_dst_data->not_associate = 0; if ((common.not_associate & 0x03) == 0x03) p_dst_data->not_associate = 1; p_encoder_cur->Set(p_dst_data->cdr_data,kMaxOneCdrBufLen); uint64_t imsi = sp_user_info->GetIMSI(); if(common.eci == 0) { common.eci = sp_user_info->GetEci(); } uint16_t tmp_enbid = common.tac;//>>8; //uint32_t tmp_enbid = (common.eci >> 8)&0xfffff; char xdrid_str[32]={0}; #ifdef OPEN_NEW_HUISU convert_xdrid_to_string(xdrid_str, kqi->xdrid, s_xdr_id_len); #else #ifdef OPENCTPR g4sigtran::pr::ProcBlock* p_blk = kqi->binary_block_in_xdr_.GetBlock(); p_blk->SerializeXid(xdrid_str, sizeof(xdrid_str)); #else uint64_t subcdrid = g_ct_xdr_id.GetXid(); //reverse subend; if(::is_open_reverse) { SetReverseSubend(p_node, subcdrid); } #ifdef ONE_THIRD_YUNNAN_MRO g_ct_xdr_id.Serialize((uint8_t*)xdrid_str, s_xdr_id_len, imsi); #else g_ct_xdr_id.Serialize((uint8_t*)xdrid_str, s_xdr_id_len); #endif #endif #endif struct timespec start_time = kqi->request_time_, end_time = kqi->response_time_; if (kqi->request_time_.tv_sec == 0) { if (!(kqi->response_time_.tv_sec == 0)) { start_time = kqi->response_time_; } else if (!(kqi->complete_time_.tv_sec == 0)) { start_time = kqi->complete_time_; } }要求:在S1mmeSession::CtEncodeKqi函数后面新加一个函数,来维护一组key、value的关系。 key为:imsi value为:imsi、imei、common.eci、common.tac、last_time 当imsi相同时,以最后一条记录的value内容为准进行保存;imsi不同时直接插入。请用C++实现该功能,需要用到哈希的知识点
像进行JPEG解压缩,并将解压缩后的图像存储到视频文件中。
```matlab
outputVideo =好的,根据您的要求,我可以为您提供以下C++代码来实现所需功能,其中使用了哈希表来维护key-value关系:
#include <unordered_map>
#include <ctime>
struct KqiInfo {
uint64 VideoWriter('compressed.avi');
open(outputVideo);
for k = 1:numFrames
decoded_img = decoded_imgs{k};
% 调_t imsi;
uint64_t imei;
uint32_t eci;
uint16_t tac;
timespec last_time;
};
std::unordered_map<uint64_t, KqiInfo> kqi_map;
void update_kqi_map(S1MMEKQI用jpegdec函数进行JPEG解压缩
img = jpegdec(decoded_img);
writeVideo(outputVideo,img);
end
close(output* kqi, S1APNode* p_node) {
MsgCommonInfo& common = p_node->GetCommonInfo();
SPUserInfo& sp_user_info = p_node->GetUserInfo();
uint64_t imsi = sp_user_info->GetIMSI();
uintVideo);
```
完整的代码如下:
```matlab
% 读取视频文件并将每一帧图像进行64_t imei = sp_user_info->GetIMEI();
uint32_t eci = common.eci;
uint16_t tacJPEG压缩
vidObj = VideoReader('sample.avi');
numFrames = vidObj.NumberOfFrames;
for k = 1:numFrames = common.tac;
timespec now;
clock_gettime(CLOCK_REALTIME, &now);
KqiInfo kqi_info = {imsi, imei, eci, tac, now};
kqi_map[imsi] = kqi_info;
}
在
img = read(vidObj, k);
compressed_img = jpegenc(img); % 调用jpegenc函数进行JPEG压缩原有的S1mmeSession::CtEncodeKqi函数中,调用update_kqi_map函数即可将相关信息保存到哈希表中。如果imsi已经存在,会自动覆盖原有记录;如果imsi不存在,则新,返回压缩后的图像
% 将压缩后的图像存储到数组中,用于后续的建一条记录。需要注意的是,本代码中使用的哈希表默认使用std::hash函数进行哈希,如果需要自定义哈希函数可以通过std::unordered_map的第三个模板参数传入。
void S1mmeSession::CtOutputKqi(S1MMEKQI* kqi, S1APNode* p_node, uint8_t worker_id) { SPUserInfo& sp_user_info = p_node->GetUserInfo(); //先填充kqi中承载信息 for (uint8_t i=0; i<kqi->GetBearerNum(); i++) { KQIBearer* p_bearer = kqi->GetBearer(i); if (p_bearer == NULL) break; sp_user_info->FillKQIBearer(p_bearer->ebi, p_bearer); } //再执行该信令功能 switch (kqi->kqi_type_) { case kS1mmeProcTypeEPSBearerContextDeactivation: //删除释放的承载 sp_user_info->EraseEBI(kqi->GetBearer1()->ebi); break; case kS1mmeProcTypeERABRelease: case kS1mmeProcTypeERABReleaseIndication: //删除需要释放的承载 for (uint8_t i=0; i<kqi->GetBearerNum(); i++) { KQIBearer* p_bearer = kqi->GetBearer(i); if (p_bearer == NULL) break; sp_user_info->EraseEBI(p_bearer->ebi); } break; case kS1mmeProcTypePathSwitch: case kS1mmeProcTypeS1SwitchOut: case kS1mmeProcTypeS1SwitchIn: kqi->bearer_num_ = 0;//暂不输出切换相关的承载信息 //删除没有切换过来的承载 break; } if (!(kqi->kqi_type_ >= kS1mmeProcTypeAttach && kqi->kqi_type_ <= kS1mmeProcTypeMax)) { return; } // CtEncodeKqi(kqi, p_node, worker_id); update_test(p_node); return; }什么意思
这是一段 C++ 代码,其中定义了一个名为 S1mmeSession 的类,该类包含一个名为 CtOutputKqi 的成员函数。该函数的作用是根据传入的 S1MMEKQI 类型的参数 kqi,向 sp_user_info 对象中填充一些信息,然后根据 kqi 的类型执行不同的功能。具体来说,如果 kqi 的类型是 kS1mmeProcTypeEPSBearerContextDeactivation,则删除释放的承载;如果 kqi 的类型是 kS1mmeProcTypeERABRelease 或 kS1mmeProcTypeERABReleaseIndication,则删除需要释放的承载;如果 kqi 的类型是 kS1mmeProcTypePathSwitch、kS1mmeProcTypeS1SwitchOut 或 kS1mmeProcTypeS1SwitchIn,则删除没有切换过来的承载;如果 kqi 的类型不在 kS1mmeProcTypeAttach 和 kS1mmeProcTypeMax 之间,则直接返回。最后,该函数调用 CtEncodeKqi 函数对 kqi 进行编码,并且更新 test。
阅读全文