Fix zerocoder, use buffers instead of strings for vardata, add util for null-terminated string<->buffer conversion
This commit is contained in:
@@ -13,8 +13,8 @@ export class EmailMessageRequestMessage implements MessageBase
|
||||
|
||||
DataBlock: {
|
||||
ObjectID: UUID;
|
||||
FromAddress: string;
|
||||
Subject: string;
|
||||
FromAddress: Buffer;
|
||||
Subject: Buffer;
|
||||
};
|
||||
|
||||
getSize(): number
|
||||
@@ -28,10 +28,10 @@ export class EmailMessageRequestMessage implements MessageBase
|
||||
this.DataBlock['ObjectID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
buf.writeUInt8(this.DataBlock['FromAddress'].length, pos++);
|
||||
buf.write(this.DataBlock['FromAddress'], pos);
|
||||
this.DataBlock['FromAddress'].copy(buf, pos);
|
||||
pos += this.DataBlock['FromAddress'].length;
|
||||
buf.writeUInt8(this.DataBlock['Subject'].length, pos++);
|
||||
buf.write(this.DataBlock['Subject'], pos);
|
||||
this.DataBlock['Subject'].copy(buf, pos);
|
||||
pos += this.DataBlock['Subject'].length;
|
||||
return pos - startPos;
|
||||
}
|
||||
@@ -42,20 +42,20 @@ export class EmailMessageRequestMessage implements MessageBase
|
||||
let varLength = 0;
|
||||
const newObjDataBlock: {
|
||||
ObjectID: UUID,
|
||||
FromAddress: string,
|
||||
Subject: string
|
||||
FromAddress: Buffer,
|
||||
Subject: Buffer
|
||||
} = {
|
||||
ObjectID: UUID.zero(),
|
||||
FromAddress: '',
|
||||
Subject: ''
|
||||
FromAddress: Buffer.allocUnsafe(0),
|
||||
Subject: Buffer.allocUnsafe(0)
|
||||
};
|
||||
newObjDataBlock['ObjectID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
varLength = buf.readUInt8(pos++);
|
||||
newObjDataBlock['FromAddress'] = buf.toString('utf8', pos, pos + (varLength - 1));
|
||||
newObjDataBlock['FromAddress'] = buf.slice(pos, pos + (varLength - 1));
|
||||
pos += varLength;
|
||||
varLength = buf.readUInt8(pos++);
|
||||
newObjDataBlock['Subject'] = buf.toString('utf8', pos, pos + (varLength - 1));
|
||||
newObjDataBlock['Subject'] = buf.slice(pos, pos + (varLength - 1));
|
||||
pos += varLength;
|
||||
this.DataBlock = newObjDataBlock;
|
||||
return pos - startPos;
|
||||
|
||||
Reference in New Issue
Block a user