MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / csv_cb1

Function csv_cb1

libCacheSim/traceReader/generalReader/csv.c:199–269  ·  view source on GitHub ↗

* @brief call back for csv field end * * @param s the string of the field * @param len length of the string * @param data user passed data: reader_t* */

Source from the content-addressed store, hash-verified

197 * @param data user passed data: reader_t*
198 */
199static inline void csv_cb1(void *s, size_t len, void *data) {
200 reader_t *reader = (reader_t *)data;
201 csv_params_t *csv_params = reader->reader_params;
202 request_t *req = csv_params->request;
203 char *end;
204
205 if (csv_params->curr_field_idx == csv_params->obj_id_field_idx) {
206 if (reader->obj_id_is_num) {
207 req->obj_id = strtoull((char *)s, &end, 0);
208 if (req->obj_id == 0 && s == end) {
209 WARN("object id is not numeric: \"%s\"\n", (char *)s);
210 }
211 } else {
212 if (!reader->obj_id_is_num_set) {
213 if (is_str_num((char *)s, len)) {
214 csv_params->n_obj_id_is_num++;
215 } else {
216 csv_params->n_obj_id_is_not_num++;
217 }
218 int n_req =
219 csv_params->n_obj_id_is_num + csv_params->n_obj_id_is_not_num;
220 if (n_req > 20000) {
221 if (csv_params->n_obj_id_is_num > (double)n_req * 0.99) {
222 ERROR(
223 "detect obj_id is numeric, please specify -t "
224 "'obj-id-is-num=1'\n");
225 }
226 }
227 }
228 // req->obj_id = (uint64_t)g_quark_from_string(s);
229 req->obj_id = (uint64_t)get_hash_value_str((char *)s, len);
230 }
231 } else if (csv_params->curr_field_idx == csv_params->time_field_idx) {
232 // int64_t ts = (int64_t)atof((char *)s);
233 int64_t ts = (int64_t)strtod((char *)s, NULL);
234 req->clock_time = ts;
235 } else if (csv_params->curr_field_idx == csv_params->obj_size_field_idx) {
236 req->obj_size = (int64_t)strtoll((char *)s, &end, 0);
237 if (req->obj_size == 0 && end == s) {
238 WARN("csvReader obj_size is not a number: \"%s\"\n", (char *)s);
239 }
240 } else if (csv_params->curr_field_idx == csv_params->op_field_idx) {
241 if (strncasecmp((char *)s, "read", len) == 0) {
242 req->op = OP_READ;
243 } else if (strncasecmp((char *)s, "write", len) == 0) {
244 req->op = OP_WRITE;
245 } else if (strncasecmp((char *)s, "get", len) == 0) {
246 req->op = OP_GET;
247 } else if (strncasecmp((char *)s, "set", len) == 0) {
248 req->op = OP_SET;
249 } else if (strncasecmp((char *)s, "delete", len) == 0) {
250 req->op = OP_DELETE;
251 } else {
252 WARN("unknown operation: \"%s\"\n", (char *)s);
253 }
254 } else if (csv_params->curr_field_idx == csv_params->ttl_field_idx) {
255 req->ttl = (uint32_t)strtoul((char *)s, &end, 0);
256 } else if (csv_params->curr_field_idx == csv_params->cnt_field_idx) {

Callers

nothing calls this directly

Calls 1

is_str_numFunction · 0.85

Tested by

no test coverage detected