@@ -427,41 +427,20 @@ Writer.prototype[TypeCode.DECIMAL] = function writeDecimal(value) {
427
427
} ;
428
428
429
429
Writer . prototype [ TypeCode . NSTRING ] = function writeNString ( value ) {
430
- if ( this . _useCesu8 ) {
431
- var encoded = util . convert . encode ( value , true ) ;
432
- this . push ( createBinaryOutBuffer ( TypeCode . NSTRING , encoded ) ) ;
433
- } else {
434
- this . writeCharacters ( value , 'utf8' ) ;
435
- }
430
+ this . writeCharacters ( TypeCode . NSTRING , value ) ;
436
431
} ;
437
432
438
433
Writer . prototype [ TypeCode . STRING ] = function writeString ( value ) {
439
- this . writeCharacters ( value , 'ascii' ) ;
434
+ this . writeCharacters ( TypeCode . STRING , value ) ;
440
435
} ;
441
436
442
- Writer . prototype . writeCharacters = function writeCharacters ( value , encoding ) {
443
- var type = encoding === 'ascii' ? TypeCode . STRING : TypeCode . NSTRING ;
444
- var length = Buffer . byteLength ( value , encoding ) ;
445
- var buffer ;
446
- if ( length <= 245 ) {
447
- buffer = new Buffer ( 2 + length ) ;
448
- buffer [ 0 ] = type ;
449
- buffer [ 1 ] = length ;
450
- buffer . write ( value , 2 , length , encoding ) ;
451
- } else if ( length <= 32767 ) {
452
- buffer = new Buffer ( 4 + length ) ;
453
- buffer [ 0 ] = type ;
454
- buffer [ 1 ] = 246 ;
455
- buffer . writeInt16LE ( length , 2 ) ;
456
- buffer . write ( value , 4 , length , encoding ) ;
457
- } else {
458
- buffer = new Buffer ( 6 + length ) ;
459
- buffer [ 0 ] = type ;
460
- buffer [ 1 ] = 247 ;
461
- buffer . writeInt32LE ( length , 2 ) ;
462
- buffer . write ( value , 6 , length , encoding ) ;
437
+ Writer . prototype . writeCharacters = function writeCharacters ( type , value ) {
438
+ if ( typeof value !== 'string' ) {
439
+ throw new TypeError ( 'Argument must be a string' ) ;
463
440
}
464
- this . push ( buffer ) ;
441
+
442
+ var encoded = util . convert . encode ( value , this . _useCesu8 ) ;
443
+ this . push ( createBinaryOutBuffer ( type , encoded ) ) ;
465
444
} ;
466
445
467
446
Writer . prototype [ TypeCode . BINARY ] = function writeBinary ( value ) {
0 commit comments