Latest packet handling, parsing, enums, generators, etc..
This commit is contained in:
@@ -25,4 +25,52 @@ export class ImageDataPacket implements Packet
|
||||
return (this.ImageData['Data'].length + 2) + 23;
|
||||
}
|
||||
|
||||
writeToBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
this.ImageID['ID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
buf.writeUInt8(this.ImageID['Codec'], pos++);
|
||||
buf.writeUInt32LE(this.ImageID['Size'], pos);
|
||||
pos += 4;
|
||||
buf.writeUInt16LE(this.ImageID['Packets'], pos);
|
||||
pos += 2;
|
||||
buf.write(this.ImageData['Data'], pos);
|
||||
pos += this.ImageData['Data'].length;
|
||||
return pos - startPos;
|
||||
}
|
||||
|
||||
readFromBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
const newObjImageID: {
|
||||
ID: UUID,
|
||||
Codec: number,
|
||||
Size: number,
|
||||
Packets: number
|
||||
} = {
|
||||
ID: UUID.zero(),
|
||||
Codec: 0,
|
||||
Size: 0,
|
||||
Packets: 0
|
||||
};
|
||||
newObjImageID['ID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjImageID['Codec'] = buf.readUInt8(pos++);
|
||||
newObjImageID['Size'] = buf.readUInt32LE(pos);
|
||||
pos += 4;
|
||||
newObjImageID['Packets'] = buf.readUInt16LE(pos);
|
||||
pos += 2;
|
||||
this.ImageID = newObjImageID;
|
||||
const newObjImageData: {
|
||||
Data: string
|
||||
} = {
|
||||
Data: ''
|
||||
};
|
||||
newObjImageData['Data'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
this.ImageData = newObjImageData;
|
||||
return pos - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user