mirror of
https://github.com/Fabio286/mizar.git
synced 2024-12-22 04:56:53 +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 {
|
export interface ClientMessage {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
format: 'hex' | 'ascii' | 'binary';
|
format: 'hex' | 'utf-8' | 'binary';
|
||||||
message: string;
|
message: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
@ -142,8 +142,8 @@ class Sender {
|
|||||||
let msg;
|
let msg;
|
||||||
|
|
||||||
switch (this.messages[index].format) {
|
switch (this.messages[index].format) {
|
||||||
case 'ascii':
|
case 'utf-8':
|
||||||
msg = Buffer.from(this.messages[index].message, 'ascii');
|
msg = Buffer.from(this.messages[index].message, 'utf-8');
|
||||||
break;
|
break;
|
||||||
case 'hex':
|
case 'hex':
|
||||||
msg = Buffer.from(this.messages[index].message.replace(/\s|0x/g, ''), 'hex');
|
msg = Buffer.from(this.messages[index].message.replace(/\s|0x/g, ''), 'hex');
|
||||||
|
@ -75,7 +75,16 @@ class Server {
|
|||||||
this.sendLog(null, '', 'clientConnectedOnPort', { port });
|
this.sendLog(null, '', 'clientConnectedOnPort', { port });
|
||||||
|
|
||||||
socket.on('data', (msg: Buffer) => {
|
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);
|
if (this.echo) socket.write(msg);
|
||||||
this.nBytes[i] += msg.length;
|
this.nBytes[i] += msg.length;
|
||||||
this.nMsgs[i]++;
|
this.nMsgs[i]++;
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
<option value="" disabled>
|
<option value="" disabled>
|
||||||
{{ t('word.select') }}
|
{{ t('word.select') }}
|
||||||
</option>
|
</option>
|
||||||
<option value="ascii">
|
<option value="utf-8">
|
||||||
ASCII
|
UTF-8
|
||||||
</option>
|
</option>
|
||||||
<option value="hex">
|
<option value="hex">
|
||||||
HEX
|
HEX
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
<option value="" disabled>
|
<option value="" disabled>
|
||||||
{{ t('word.select') }}
|
{{ t('word.select') }}
|
||||||
</option>
|
</option>
|
||||||
<option value="ascii">
|
<option value="utf-8">
|
||||||
ASCII
|
UTF-8
|
||||||
</option>
|
</option>
|
||||||
<option value="hex">
|
<option value="hex">
|
||||||
HEX
|
HEX
|
||||||
|
@ -13,7 +13,7 @@ export const useClientStore = defineStore('client', {
|
|||||||
}]) as ClientHost[],
|
}]) as ClientHost[],
|
||||||
messages: persistentStore.get('messages', [{
|
messages: persistentStore.get('messages', [{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
format: 'ascii',
|
format: 'utf-8',
|
||||||
message: 'Hello, World!',
|
message: 'Hello, World!',
|
||||||
name: 'Hello, World!'
|
name: 'Hello, World!'
|
||||||
}]) as ClientMessage[]
|
}]) as ClientMessage[]
|
||||||
|
Loading…
Reference in New Issue
Block a user