mirror of
https://github.com/Fabio286/mizar.git
synced 2024-12-21 20:44:20 +01:00
feat: hex or utf8 automatic conversion for server traces
This commit is contained in:
parent
45c9537cc9
commit
46e9d157d6
@ -9,7 +9,7 @@ export interface ClientHost {
|
||||
|
||||
export interface ClientMessage {
|
||||
enabled: boolean;
|
||||
format: 'hex' | 'ascii' | 'binary';
|
||||
format: 'hex' | 'utf-8' | 'binary';
|
||||
message: string;
|
||||
name: string;
|
||||
}
|
||||
|
@ -142,8 +142,8 @@ class Sender {
|
||||
let msg;
|
||||
|
||||
switch (this.messages[index].format) {
|
||||
case 'ascii':
|
||||
msg = Buffer.from(this.messages[index].message, 'ascii');
|
||||
case 'utf-8':
|
||||
msg = Buffer.from(this.messages[index].message, 'utf-8');
|
||||
break;
|
||||
case 'hex':
|
||||
msg = Buffer.from(this.messages[index].message.replace(/\s|0x/g, ''), 'hex');
|
||||
|
@ -75,7 +75,16 @@ class Server {
|
||||
this.sendLog(null, '', 'clientConnectedOnPort', { port });
|
||||
|
||||
socket.on('data', (msg: Buffer) => {
|
||||
const msgString = msg.toString();
|
||||
let msgString: string;
|
||||
|
||||
try {
|
||||
new TextDecoder('utf8', { fatal: true }).decode(msg);
|
||||
msgString = msg.toString('utf-8');
|
||||
}
|
||||
catch (err) {
|
||||
msgString = msg.toString('hex');
|
||||
}
|
||||
|
||||
if (this.echo) socket.write(msg);
|
||||
this.nBytes[i] += msg.length;
|
||||
this.nMsgs[i]++;
|
||||
|
@ -27,8 +27,8 @@
|
||||
<option value="" disabled>
|
||||
{{ t('word.select') }}
|
||||
</option>
|
||||
<option value="ascii">
|
||||
ASCII
|
||||
<option value="utf-8">
|
||||
UTF-8
|
||||
</option>
|
||||
<option value="hex">
|
||||
HEX
|
||||
|
@ -27,8 +27,8 @@
|
||||
<option value="" disabled>
|
||||
{{ t('word.select') }}
|
||||
</option>
|
||||
<option value="ascii">
|
||||
ASCII
|
||||
<option value="utf-8">
|
||||
UTF-8
|
||||
</option>
|
||||
<option value="hex">
|
||||
HEX
|
||||
|
@ -13,7 +13,7 @@ export const useClientStore = defineStore('client', {
|
||||
}]) as ClientHost[],
|
||||
messages: persistentStore.get('messages', [{
|
||||
enabled: true,
|
||||
format: 'ascii',
|
||||
format: 'utf-8',
|
||||
message: 'Hello, World!',
|
||||
name: 'Hello, World!'
|
||||
}]) as ClientMessage[]
|
||||
|
Loading…
Reference in New Issue
Block a user