示例#1
0
char* Namespace::getNextBatch(int &count)
{
	if (_DEBUG)
		LOGI("get next batch");

	int batchSize = 0;
	int sizes[count];
	int jsonSize = 0;
	char *records[count]; //= (char**)malloc(count*sizeof(char*));

	int lastRetrievedRecord = -1, recordSize, skip = 0;

	int i = 0;
	Extent *extent = getFirstExtent();
	while (extent != NULL)
	{
		lastRetrievedRecord = -1;
		Record *record = extent->getFirstRecord();
		while (record != NULL && i < count)
		{
			recordSize = 0;

			int bsonSize = 0;
			bson_little_endian32( &bsonSize, record->data);
			//FORCE_LOG_INT("bsonSize: ", bsonSize);
			char *val = (char*) malloc((bsonSize + 100) * sizeof(char));
			int cur = 0;
			val = bson_to_json(val, record->data, 0, true, bsonSize, recordSize,
					cur);

			records[i] = val;
			batchSize += recordSize;
			sizes[i] = recordSize;
			jsonSize += recordSize;

			record = extent->getRecord(record->nextRecLoc);

			i++;
		}

		extent = db->getExtent(extent->nextExtent);
	}

	count = i;
	FORCE_LOG_INT("count: ", i);

	return serializeJSON(records, jsonSize, count, sizes);
}