Add ShowAsRustArray option
This commit is contained in:
parent
6ce15b9521
commit
c9e08b7be3
|
@ -73,6 +73,7 @@ ShowPacketBytesDialog::ShowPacketBytesDialog(QWidget &parent, CaptureFile &cf) :
|
||||||
ui->cbShowAs->addItem(tr("HTML"), ShowAsHTML);
|
ui->cbShowAs->addItem(tr("HTML"), ShowAsHTML);
|
||||||
ui->cbShowAs->addItem(tr("Image"), ShowAsImage);
|
ui->cbShowAs->addItem(tr("Image"), ShowAsImage);
|
||||||
ui->cbShowAs->addItem(tr("Raw"), ShowAsRAW);
|
ui->cbShowAs->addItem(tr("Raw"), ShowAsRAW);
|
||||||
|
ui->cbShowAs->addItem(tr("Rust Array"), ShowAsRustArray);
|
||||||
// UTF-8 is guaranteed to exist as a QTextCodec
|
// UTF-8 is guaranteed to exist as a QTextCodec
|
||||||
ui->cbShowAs->addItem(tr("UTF-8"), ShowAsCodec);
|
ui->cbShowAs->addItem(tr("UTF-8"), ShowAsCodec);
|
||||||
ui->cbShowAs->addItem(tr("YAML"), ShowAsYAML);
|
ui->cbShowAs->addItem(tr("YAML"), ShowAsYAML);
|
||||||
|
@ -286,6 +287,7 @@ void ShowPacketBytesDialog::copyBytes()
|
||||||
|
|
||||||
case ShowAsASCIIandControl:
|
case ShowAsASCIIandControl:
|
||||||
case ShowAsCArray:
|
case ShowAsCArray:
|
||||||
|
case ShowAsRustArray:
|
||||||
case ShowAsEBCDIC:
|
case ShowAsEBCDIC:
|
||||||
case ShowAsHexDump:
|
case ShowAsHexDump:
|
||||||
case ShowAsRAW:
|
case ShowAsRAW:
|
||||||
|
@ -319,6 +321,7 @@ void ShowPacketBytesDialog::saveAs()
|
||||||
case ShowAsASCII:
|
case ShowAsASCII:
|
||||||
case ShowAsASCIIandControl:
|
case ShowAsASCIIandControl:
|
||||||
case ShowAsCArray:
|
case ShowAsCArray:
|
||||||
|
case ShowAsRustArray:
|
||||||
// We always save as UTF-8, so set text mode as we would for UTF-8
|
// We always save as UTF-8, so set text mode as we would for UTF-8
|
||||||
case ShowAsCodec:
|
case ShowAsCodec:
|
||||||
case ShowAsHexDump:
|
case ShowAsHexDump:
|
||||||
|
@ -344,6 +347,7 @@ void ShowPacketBytesDialog::saveAs()
|
||||||
|
|
||||||
case ShowAsASCIIandControl:
|
case ShowAsASCIIandControl:
|
||||||
case ShowAsCArray:
|
case ShowAsCArray:
|
||||||
|
case ShowAsRustArray:
|
||||||
case ShowAsEBCDIC:
|
case ShowAsEBCDIC:
|
||||||
case ShowAsHexDump:
|
case ShowAsHexDump:
|
||||||
case ShowAsYAML:
|
case ShowAsYAML:
|
||||||
|
@ -646,6 +650,43 @@ void ShowPacketBytesDialog::updatePacketBytes(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ShowAsRustArray:
|
||||||
|
{
|
||||||
|
int pos = 0, len = field_bytes_.length();
|
||||||
|
QString text("let packet_bytes: [u8; _] = [\n");
|
||||||
|
|
||||||
|
while (pos < len) {
|
||||||
|
gchar hexbuf[256];
|
||||||
|
char *cur = hexbuf;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
*cur++ = ' ';
|
||||||
|
for (i = 0; i < 8 && pos + i < len; i++) {
|
||||||
|
// Prepend entries with " 0x"
|
||||||
|
*cur++ = ' ';
|
||||||
|
*cur++ = '0';
|
||||||
|
*cur++ = 'x';
|
||||||
|
*cur++ = hexchars[(field_bytes_[pos + i] & 0xf0) >> 4];
|
||||||
|
*cur++ = hexchars[field_bytes_[pos + i] & 0x0f];
|
||||||
|
|
||||||
|
// Delimit array entries with a comma
|
||||||
|
if (pos + i + 1 < len)
|
||||||
|
*cur++ = ',';
|
||||||
|
}
|
||||||
|
|
||||||
|
pos += i;
|
||||||
|
*cur++ = '\n';
|
||||||
|
*cur = 0;
|
||||||
|
|
||||||
|
text.append(hexbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
text.append("];\n");
|
||||||
|
ui->tePacketBytes->setLineWrapMode(QTextEdit::NoWrap);
|
||||||
|
ui->tePacketBytes->setPlainText(text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ShowAsCodec:
|
case ShowAsCodec:
|
||||||
{
|
{
|
||||||
// The QTextCodecs docs say that there's a flag to cause invalid
|
// The QTextCodecs docs say that there's a flag to cause invalid
|
||||||
|
|
|
@ -77,6 +77,7 @@ private:
|
||||||
ShowAsASCII,
|
ShowAsASCII,
|
||||||
ShowAsASCIIandControl,
|
ShowAsASCIIandControl,
|
||||||
ShowAsCArray,
|
ShowAsCArray,
|
||||||
|
ShowAsRustArray,
|
||||||
ShowAsEBCDIC,
|
ShowAsEBCDIC,
|
||||||
ShowAsHexDump,
|
ShowAsHexDump,
|
||||||
ShowAsHTML,
|
ShowAsHTML,
|
||||||
|
|
Loading…
Reference in New Issue