@@ -328,7 +328,7 @@ function decodeMessageProperties(dataResponse: DataReader) {
328328 dataResponse . rewind ( 3 )
329329 const type = dataResponse . readInt8 ( )
330330 if ( type !== 0 ) {
331- throw new Error ( `invalid composite header : ${ type } ` )
331+ throw new Error ( `invalid message properties : ${ type } ` )
332332 }
333333
334334 const nextType = dataResponse . readInt8 ( )
@@ -347,8 +347,7 @@ function decodeMessageHeader(dataResponse: DataReader) {
347347 throw new Error ( `invalid composite header: ${ type } ` )
348348 }
349349
350- // next, the composite type is encoded as an AMQP uint8
351- dataResponse . readUInt64 ( )
350+ decodeAmqpValue ( dataResponse )
352351
353352 const formatCode = dataResponse . readUInt8 ( )
354353 const headerLength = decodeFormatCode ( dataResponse , formatCode )
@@ -365,8 +364,7 @@ function decodeApplicationData(dataResponse: DataReader) {
365364
366365function decodeAmqpValue ( dataResponse : DataReader ) {
367366 const amqpFormatCode = dataResponse . readUInt8 ( )
368- dataResponse . rewind ( 1 )
369- return decodeFormatCode ( dataResponse , amqpFormatCode , true ) as string
367+ return decodeFormatCode ( dataResponse , amqpFormatCode ) as string
370368}
371369
372370function readFormatCodeType ( dataResponse : DataReader ) {
@@ -379,13 +377,12 @@ function readFormatCodeType(dataResponse: DataReader) {
379377export function readUTF8String ( dataResponse : DataReader ) {
380378 const formatCode = dataResponse . readUInt8 ( )
381379 const decodedString = decodeFormatCode ( dataResponse , formatCode )
382- if ( ! decodedString ) throw new Error ( `invalid formatCode %#02x: ${ formatCode } ` )
380+ if ( ! decodedString ) throw new Error ( `invalid formatCode 0x ${ formatCode . toString ( 16 ) } ` )
383381
384382 return decodedString as string
385383}
386384
387- export function decodeBooleanType ( dataResponse : DataReader , defaultValue : boolean ) {
388- const boolType = dataResponse . readInt8 ( )
385+ export function decodeBooleanType ( dataResponse : DataReader , boolType : number ) {
389386 switch ( boolType ) {
390387 case FormatCode . Bool :
391388 const boolValue = dataResponse . readInt8 ( )
@@ -395,11 +392,11 @@ export function decodeBooleanType(dataResponse: DataReader, defaultValue: boolea
395392 case FormatCode . BoolFalse :
396393 return false
397394 default :
398- return defaultValue
395+ throw new Error ( `Expected boolean format code, got 0x ${ boolType . toString ( 16 ) } ` )
399396 }
400397}
401398
402- export function decodeFormatCode ( dataResponse : DataReader , formatCode : number , skipByte = false ) {
399+ export function decodeFormatCode ( dataResponse : DataReader , formatCode : number ) {
403400 switch ( formatCode ) {
404401 case FormatCode . Map8 :
405402 // Read first empty byte
@@ -412,7 +409,6 @@ export function decodeFormatCode(dataResponse: DataReader, formatCode: number, s
412409 case FormatCode . SmallUlong :
413410 return dataResponse . readInt8 ( ) // Read a SmallUlong
414411 case FormatCode . Ubyte :
415- dataResponse . forward ( 1 )
416412 return dataResponse . readUInt8 ( )
417413 case FormatCode . ULong :
418414 return dataResponse . readUInt64 ( ) // Read an ULong
@@ -430,35 +426,30 @@ export function decodeFormatCode(dataResponse: DataReader, formatCode: number, s
430426 return dataResponse . readUInt32 ( )
431427 case FormatCode . Str8 :
432428 case FormatCode . Sym8 :
433- if ( skipByte ) dataResponse . forward ( 1 )
434429 return dataResponse . readString8 ( )
435430 case FormatCode . Str32 :
436431 case FormatCode . Sym32 :
437- if ( skipByte ) dataResponse . forward ( 1 )
438432 return dataResponse . readString32 ( )
439433 case FormatCode . Uint0 :
440434 return 0
441435 case FormatCode . SmallUint :
442- dataResponse . forward ( 1 ) // Skipping formatCode
443436 return dataResponse . readUInt8 ( )
444437 case FormatCode . Uint :
445- dataResponse . forward ( 1 ) // Skipping formatCode
446438 return dataResponse . readUInt32 ( )
447439 case FormatCode . SmallInt :
448- dataResponse . forward ( 1 ) // Skipping formatCode
449440 return dataResponse . readInt8 ( )
450441 case FormatCode . Int :
451- dataResponse . forward ( 1 ) // Skipping formatCode
452442 return dataResponse . readInt32 ( )
453443 case FormatCode . Bool :
454444 case FormatCode . BoolTrue :
455445 case FormatCode . BoolFalse :
456- return decodeBooleanType ( dataResponse , true )
446+ return decodeBooleanType ( dataResponse , formatCode )
457447 case FormatCode . Null :
458- dataResponse . forward ( 1 ) // Skipping formatCode
448+ return 0
449+ case FormatCode . ULong0 :
459450 return 0
460451 default :
461- throw new Error ( `ReadCompositeHeader Invalid type ${ formatCode } ` )
452+ throw new Error ( `FormatCode Invalid type ${ formatCode } ` )
462453 }
463454}
464455
0 commit comments