@@ -5,7 +5,7 @@ export class Writer {
55 private offset : number = 5 ;
66 private headerPosition : number = 0 ;
77 constructor ( private size = 256 ) {
8- this . buffer = Buffer . alloc ( size )
8+ this . buffer = Buffer . alloc ( size ) ;
99 }
1010
1111 private ensure ( size : number ) : void {
@@ -22,36 +22,35 @@ export class Writer {
2222
2323 public addInt32 ( num : number ) : Writer {
2424 this . ensure ( 4 ) ;
25- this . buffer [ this . offset ++ ] = ( num >>> 24 & 0xFF ) ;
26- this . buffer [ this . offset ++ ] = ( num >>> 16 & 0xFF ) ;
27- this . buffer [ this . offset ++ ] = ( num >>> 8 & 0xFF ) ;
28- this . buffer [ this . offset ++ ] = ( num >>> 0 & 0xFF ) ;
25+ this . buffer [ this . offset ++ ] = ( num >>> 24 ) & 0xff ;
26+ this . buffer [ this . offset ++ ] = ( num >>> 16 ) & 0xff ;
27+ this . buffer [ this . offset ++ ] = ( num >>> 8 ) & 0xff ;
28+ this . buffer [ this . offset ++ ] = ( num >>> 0 ) & 0xff ;
2929 return this ;
3030 }
3131
3232 public addInt16 ( num : number ) : Writer {
3333 this . ensure ( 2 ) ;
34- this . buffer [ this . offset ++ ] = ( num >>> 8 & 0xFF ) ;
35- this . buffer [ this . offset ++ ] = ( num >>> 0 & 0xFF ) ;
34+ this . buffer [ this . offset ++ ] = ( num >>> 8 ) & 0xff ;
35+ this . buffer [ this . offset ++ ] = ( num >>> 0 ) & 0xff ;
3636 return this ;
3737 }
3838
39-
4039 public addCString ( string : string ) : Writer {
4140 if ( ! string ) {
4241 this . ensure ( 1 ) ;
4342 } else {
4443 var len = Buffer . byteLength ( string ) ;
4544 this . ensure ( len + 1 ) ; // +1 for null terminator
46- this . buffer . write ( string , this . offset , 'utf-8' )
45+ this . buffer . write ( string , this . offset , 'utf-8' ) ;
4746 this . offset += len ;
4847 }
4948
5049 this . buffer [ this . offset ++ ] = 0 ; // null terminator
5150 return this ;
5251 }
5352
54- public addString ( string : string = "" ) : Writer {
53+ public addString ( string : string = '' ) : Writer {
5554 var len = Buffer . byteLength ( string ) ;
5655 this . ensure ( len ) ;
5756 this . buffer . write ( string , this . offset ) ;
@@ -70,8 +69,8 @@ export class Writer {
7069 if ( code ) {
7170 this . buffer [ this . headerPosition ] = code ;
7271 //length is everything in this packet minus the code
73- const length = this . offset - ( this . headerPosition + 1 )
74- this . buffer . writeInt32BE ( length , this . headerPosition + 1 )
72+ const length = this . offset - ( this . headerPosition + 1 ) ;
73+ this . buffer . writeInt32BE ( length , this . headerPosition + 1 ) ;
7574 }
7675 return this . buffer . slice ( code ? 0 : 5 , this . offset ) ;
7776 }
@@ -80,8 +79,7 @@ export class Writer {
8079 var result = this . join ( code ) ;
8180 this . offset = 5 ;
8281 this . headerPosition = 0 ;
83- this . buffer = Buffer . allocUnsafe ( this . size )
82+ this . buffer = Buffer . allocUnsafe ( this . size ) ;
8483 return result ;
8584 }
8685}
87-
0 commit comments