本文整理汇总了C++中OutputBuffer::EncodeString方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer::EncodeString方法的具体用法?C++ OutputBuffer::EncodeString怎么用?C++ OutputBuffer::EncodeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputBuffer
的用法示例。
在下文中一共展示了OutputBuffer::EncodeString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strlen
// Get the list of files in the specified directory in JSON format.
// If flagDirs is true then we prefix each directory with a * character.
OutputBuffer *RepRap::GetFilesResponse(const char *dir, bool flagsDirs)
{
// Need something to write to...
OutputBuffer *response;
if (!OutputBuffer::Allocate(response))
{
return nullptr;
}
response->copy("{\"dir\":");
response->EncodeString(dir, strlen(dir), false);
response->cat(",\"files\":[");
FileInfo fileInfo;
bool firstFile = true;
bool gotFile = platform->GetMassStorage()->FindFirst(dir, fileInfo);
size_t bytesLeft = OutputBuffer::GetBytesLeft(response); // don't write more bytes than we can
char filename[FILENAME_LENGTH];
filename[0] = '*';
const char *fname;
while (gotFile)
{
if (fileInfo.fileName[0] != '.') // ignore Mac resource files and Linux hidden files
{
// Get the long filename if possible
if (flagsDirs && fileInfo.isDirectory)
{
strncpy(filename + sizeof(char), fileInfo.fileName, FILENAME_LENGTH - 1);
filename[FILENAME_LENGTH - 1] = 0;
fname = filename;
}
else
{
fname = fileInfo.fileName;
}
// Make sure we can end this response properly
if (bytesLeft < strlen(fname) * 2 + 4)
{
// No more space available - stop here
break;
}
// Write separator and filename
if (!firstFile)
{
bytesLeft -= response->cat(',');
}
bytesLeft -= response->EncodeString(fname, FILENAME_LENGTH, false);
firstFile = false;
}
gotFile = platform->GetMassStorage()->FindNext(fileInfo);
}
response->cat("]}");
return response;
}
示例2: if
//.........这里部分代码省略.........
response->catf("%c%.3f", ch, liveCoordinates[axis]);
ch = ',';
}
}
}
// Current tool number
const int toolNumber = (currentTool == nullptr) ? -1 : currentTool->Number();
response->catf("]},\"currentTool\":%d", toolNumber);
// Output - only reported once
{
bool sendBeep = (beepDuration != 0 && beepFrequency != 0);
bool sendMessage = (message[0] != 0);
if (sendBeep || sendMessage)
{
response->cat(",\"output\":{");
// Report beep values
if (sendBeep)
{
response->catf("\"beepDuration\":%d,\"beepFrequency\":%d", beepDuration, beepFrequency);
if (sendMessage)
{
response->cat(",");
}
beepFrequency = beepDuration = 0;
}
// Report message
if (sendMessage)
{
response->cat("\"message\":");
response->EncodeString(message, ARRAY_SIZE(message), false);
message[0] = 0;
}
response->cat("}");
}
}
// Parameters
{
// ATX power
response->catf(",\"params\":{\"atxPower\":%d", platform->AtxPower() ? 1 : 0);
// Cooling fan value
response->cat(",\"fanPercent\":");
ch = '[';
for(size_t i = 0; i < NUM_FANS; i++)
{
response->catf("%c%.2f", ch, platform->GetFanValue(i) * 100.0);
ch = ',';
}
// Speed and Extrusion factors
response->catf("],\"speedFactor\":%.2f,\"extrFactors\":", gCodes->GetSpeedFactor() * 100.0);
ch = '[';
for (size_t extruder = 0; extruder < GetExtrudersInUse(); extruder++)
{
response->catf("%c%.2f", ch, gCodes->GetExtrusionFactor(extruder) * 100.0);
ch = ',';
}
response->cat((ch == '[') ? "[]" : "]");
response->catf(",\"babystep\":%.03f}", gCodes->GetBabyStepOffset());
}
示例3: strlen
// Get a JSON-style filelist including file types and sizes
OutputBuffer *RepRap::GetFilelistResponse(const char *dir)
{
// Need something to write to...
OutputBuffer *response;
if (!OutputBuffer::Allocate(response))
{
return nullptr;
}
// If the requested volume is not mounted, report an error
if (!platform->GetMassStorage()->CheckDriveMounted(dir))
{
response->copy("{\"err\":1}");
return response;
}
// Check if the directory exists
if (!platform->GetMassStorage()->DirectoryExists(dir))
{
response->copy("{\"err\":2}");
return response;
}
response->copy("{\"dir\":");
response->EncodeString(dir, strlen(dir), false);
response->cat(",\"files\":[");
FileInfo fileInfo;
bool firstFile = true;
bool gotFile = platform->GetMassStorage()->FindFirst(dir, fileInfo);
size_t bytesLeft = OutputBuffer::GetBytesLeft(response); // don't write more bytes than we can
while (gotFile)
{
if (fileInfo.fileName[0] != '.') // ignore Mac resource files and Linux hidden files
{
// Make sure we can end this response properly
if (bytesLeft < strlen(fileInfo.fileName) + 70)
{
// No more space available - stop here
break;
}
// Write delimiter
if (!firstFile)
{
bytesLeft -= response->cat(',');
}
firstFile = false;
// Write another file entry
bytesLeft -= response->catf("{\"type\":\"%c\",\"name\":", fileInfo.isDirectory ? 'd' : 'f');
bytesLeft -= response->EncodeString(fileInfo.fileName, FILENAME_LENGTH, false);
bytesLeft -= response->catf(",\"size\":%u", fileInfo.size);
const struct tm * const timeInfo = gmtime(&fileInfo.lastModified);
if (timeInfo->tm_year <= /*19*/80)
{
// Don't send the last modified date if it is invalid
bytesLeft -= response->cat('}');
}
else
{
bytesLeft -= response->catf(",\"date\":\"%04u-%02u-%02uT%02u:%02u:%02u\"}",
timeInfo->tm_year + 1900, timeInfo->tm_mon + 1, timeInfo->tm_mday,
timeInfo->tm_hour, timeInfo->tm_min, timeInfo->tm_sec);
}
}
gotFile = platform->GetMassStorage()->FindNext(fileInfo);
}
response->cat("]}");
return response;
}
示例4: if
//.........这里部分代码省略.........
}
}
}
// Current tool number
int toolNumber = (currentTool == nullptr) ? -1 : currentTool->Number();
response->catf("]},\"currentTool\":%d", toolNumber);
/* Output - only reported once */
{
bool sendBeep = (beepDuration != 0 && beepFrequency != 0);
bool sendMessage = (message[0] != 0);
bool sourceRight = (gCodes->HaveAux() && source == ResponseSource::AUX) || (!gCodes->HaveAux() && source == ResponseSource::HTTP);
if ((sendBeep || message[0] != 0) && sourceRight)
{
response->cat(",\"output\":{");
// Report beep values
if (sendBeep)
{
response->catf("\"beepDuration\":%d,\"beepFrequency\":%d", beepDuration, beepFrequency);
if (sendMessage)
{
response->cat(",");
}
beepFrequency = beepDuration = 0;
}
// Report message
if (sendMessage)
{
response->cat("\"message\":");
response->EncodeString(message, ARRAY_SIZE(message), false);
message[0] = 0;
}
response->cat("}");
}
}
/* Parameters */
{
// ATX power
response->catf(",\"params\":{\"atxPower\":%d", platform->AtxPower() ? 1 : 0);
// Cooling fan value
response->cat(",\"fanPercent\":[");
for(size_t i = 0; i < NUM_FANS; i++)
{
if (i == NUM_FANS - 1)
{
response->catf("%.2f", platform->GetFanValue(i) * 100.0);
}
else
{
response->catf("%.2f,", platform->GetFanValue(i) * 100.0);
}
}
// Speed and Extrusion factors
response->catf("],\"speedFactor\":%.2f,\"extrFactors\":", gCodes->GetSpeedFactor() * 100.0);
ch = '[';
for (size_t extruder = 0; extruder < GetExtrudersInUse(); extruder++)
{
response->catf("%c%.2f", ch, gCodes->GetExtrusionFactor(extruder) * 100.0);
ch = ',';