@@ -93,7 +93,7 @@ uint32_t TCompactProtocolT<Transport_>::writeMessageBegin(
9393 const int32_t seqid) {
9494 uint32_t wsize = 0 ;
9595 wsize += writeByte (PROTOCOL_ID);
96- wsize += writeByte ((VERSION_N & VERSION_MASK) | ((( int32_t ) messageType << TYPE_SHIFT_AMOUNT) & TYPE_MASK));
96+ wsize += writeByte ((VERSION_N & VERSION_MASK) | ((static_cast < int32_t >( messageType) << TYPE_SHIFT_AMOUNT) & TYPE_MASK));
9797 wsize += writeVarint32 (seqid);
9898 wsize += writeString (name);
9999 return wsize;
@@ -221,7 +221,7 @@ uint32_t TCompactProtocolT<Transport_>::writeBool(const bool value) {
221221
222222template <class Transport_ >
223223uint32_t TCompactProtocolT<Transport_>::writeByte(const int8_t byte) {
224- trans_->write (( uint8_t *) &byte, 1 );
224+ trans_->write (reinterpret_cast < const uint8_t *>( &byte) , 1 );
225225 return 1 ;
226226}
227227
@@ -259,7 +259,7 @@ uint32_t TCompactProtocolT<Transport_>::writeDouble(const double dub) {
259259
260260 auto bits = bitwise_cast<uint64_t >(dub);
261261 bits = THRIFT_htolell (bits);
262- trans_->write (( uint8_t *) &bits, 8 );
262+ trans_->write (reinterpret_cast < const uint8_t *>( &bits) , 8 );
263263 return 8 ;
264264}
265265
@@ -282,7 +282,7 @@ uint32_t TCompactProtocolT<Transport_>::writeBinary(const std::string& str) {
282282 if (ssize > (std::numeric_limits<uint32_t >::max)() - wsize)
283283 throw TProtocolException (TProtocolException::SIZE_LIMIT);
284284 wsize += ssize;
285- trans_->write (( uint8_t *) str.data (), ssize);
285+ trans_->write (reinterpret_cast < const uint8_t *>( str.data () ), ssize);
286286 return wsize;
287287}
288288
@@ -350,10 +350,10 @@ uint32_t TCompactProtocolT<Transport_>::writeVarint32(uint32_t n) {
350350
351351 while (true ) {
352352 if ((n & ~0x7F ) == 0 ) {
353- buf[wsize++] = ( int8_t )n ;
353+ buf[wsize++] = static_cast < int8_t >(n) ;
354354 break ;
355355 } else {
356- buf[wsize++] = ( int8_t ) ((n & 0x7F ) | 0x80 );
356+ buf[wsize++] = static_cast < int8_t > ((n & 0x7F ) | 0x80 );
357357 n >>= 7 ;
358358 }
359359 }
@@ -371,10 +371,10 @@ uint32_t TCompactProtocolT<Transport_>::writeVarint64(uint64_t n) {
371371
372372 while (true ) {
373373 if ((n & ~0x7FL ) == 0 ) {
374- buf[wsize++] = ( int8_t )n ;
374+ buf[wsize++] = static_cast < int8_t >(n) ;
375375 break ;
376376 } else {
377- buf[wsize++] = ( int8_t ) ((n & 0x7F ) | 0x80 );
377+ buf[wsize++] = static_cast < int8_t > ((n & 0x7F ) | 0x80 );
378378 n >>= 7 ;
379379 }
380380 }
@@ -431,12 +431,12 @@ uint32_t TCompactProtocolT<Transport_>::readMessageBegin(
431431 }
432432
433433 rsize += readByte (versionAndType);
434- version = ( int8_t ) (versionAndType & VERSION_MASK);
434+ version = static_cast < int8_t > (versionAndType & VERSION_MASK);
435435 if (version != VERSION_N) {
436436 throw TProtocolException (TProtocolException::BAD_VERSION, " Bad protocol version" );
437437 }
438438
439- messageType = ( TMessageType) ((versionAndType >> TYPE_SHIFT_AMOUNT) & TYPE_BITS);
439+ messageType = static_cast < TMessageType> ((versionAndType >> TYPE_SHIFT_AMOUNT) & TYPE_BITS);
440440 rsize += readVarint32 (seqid);
441441 rsize += readString (name);
442442
@@ -489,12 +489,12 @@ uint32_t TCompactProtocolT<Transport_>::readFieldBegin(std::string& name,
489489 }
490490
491491 // mask off the 4 MSB of the type header. it could contain a field id delta.
492- auto modifier = ( int16_t )((( uint8_t ) byte & 0xf0 ) >> 4 );
492+ auto modifier = static_cast < int16_t >( static_cast < uint8_t >( byte & 0xf0 ) >> 4 );
493493 if (modifier == 0 ) {
494494 // not a delta, look ahead for the zigzag varint field id.
495495 rsize += readI16 (fieldId);
496496 } else {
497- fieldId = ( int16_t ) (lastFieldId_ + modifier);
497+ fieldId = static_cast < int16_t > (lastFieldId_ + modifier);
498498 }
499499 fieldType = getTType (type);
500500
@@ -535,9 +535,9 @@ uint32_t TCompactProtocolT<Transport_>::readMapBegin(TType& keyType,
535535 throw TProtocolException (TProtocolException::SIZE_LIMIT);
536536 }
537537
538- keyType = getTType (( int8_t )(( uint8_t ) kvType >> 4 ));
539- valType = getTType (( int8_t )(( uint8_t ) kvType & 0xf ));
540- size = ( uint32_t ) msize;
538+ keyType = getTType (static_cast < int8_t >( static_cast < uint8_t >( kvType) >> 4 ));
539+ valType = getTType (static_cast < int8_t >( static_cast < uint8_t >( kvType) & 0xf ));
540+ size = static_cast < uint32_t >( msize) ;
541541
542542 TMap map (keyType, valType, size);
543543 checkReadBytesAvailable (map);
@@ -560,7 +560,7 @@ uint32_t TCompactProtocolT<Transport_>::readListBegin(TType& elemType,
560560
561561 rsize += readByte (size_and_type);
562562
563- lsize = (( uint8_t ) size_and_type >> 4 ) & 0x0f ;
563+ lsize = (static_cast < uint8_t >( size_and_type) >> 4 ) & 0x0f ;
564564 if (lsize == 15 ) {
565565 rsize += readVarint32 (lsize);
566566 }
@@ -571,8 +571,8 @@ uint32_t TCompactProtocolT<Transport_>::readListBegin(TType& elemType,
571571 throw TProtocolException (TProtocolException::SIZE_LIMIT);
572572 }
573573
574- elemType = getTType (( int8_t ) (size_and_type & 0x0f ));
575- size = ( uint32_t ) lsize;
574+ elemType = getTType (static_cast < int8_t > (size_and_type & 0x0f ));
575+ size = static_cast < uint32_t >( lsize) ;
576576
577577 TList list (elemType, size);
578578 checkReadBytesAvailable (list);
@@ -618,7 +618,7 @@ template <class Transport_>
618618uint32_t TCompactProtocolT<Transport_>::readByte(int8_t & byte) {
619619 uint8_t b[1 ];
620620 trans_->readAll (b, 1 );
621- byte = *( int8_t *)b ;
621+ byte = static_cast < int8_t >(b[ 0 ]) ;
622622 return 1 ;
623623}
624624
@@ -629,7 +629,7 @@ template <class Transport_>
629629uint32_t TCompactProtocolT<Transport_>::readI16(int16_t & i16 ) {
630630 int32_t value;
631631 uint32_t rsize = readVarint32 (value);
632- i16 = ( int16_t ) zigzagToI32 (value);
632+ i16 = static_cast < int16_t >( zigzagToI32 (value) );
633633 return rsize;
634634}
635635
@@ -702,21 +702,21 @@ uint32_t TCompactProtocolT<Transport_>::readBinary(std::string& str) {
702702 }
703703
704704 // Check against MaxMessageSize before alloc
705- trans_->checkReadBytesAvailable (( uint32_t ) size);
705+ trans_->checkReadBytesAvailable (static_cast < uint32_t >( size) );
706706
707707 // Use the heap here to prevent stack overflow for v. large strings
708708 if (size > string_buf_size_ || string_buf_ == nullptr ) {
709- void * new_string_buf = std::realloc (string_buf_, ( uint32_t ) size);
709+ void * new_string_buf = std::realloc (string_buf_, static_cast < uint32_t >( size) );
710710 if (new_string_buf == nullptr ) {
711711 throw std::bad_alloc ();
712712 }
713- string_buf_ = ( uint8_t *) new_string_buf;
713+ string_buf_ = static_cast < uint8_t *>( new_string_buf) ;
714714 string_buf_size_ = size;
715715 }
716716 trans_->readAll (string_buf_, size);
717- str.assign (( char *) string_buf_, size);
717+ str.assign (reinterpret_cast < char *>( string_buf_) , size);
718718
719- return rsize + ( uint32_t ) size;
719+ return rsize + static_cast < uint32_t >( size) ;
720720}
721721
722722/* *
@@ -727,7 +727,7 @@ template <class Transport_>
727727uint32_t TCompactProtocolT<Transport_>::readVarint32(int32_t & i32 ) {
728728 int64_t val;
729729 uint32_t rsize = readVarint64 (val);
730- i32 = ( int32_t ) val;
730+ i32 = static_cast < int32_t >( val) ;
731731 return rsize;
732732}
733733
@@ -749,7 +749,7 @@ uint32_t TCompactProtocolT<Transport_>::readVarint64(int64_t& i64) {
749749 while (true ) {
750750 uint8_t byte = borrowed[rsize];
751751 rsize++;
752- val |= ( uint64_t ) (byte & 0x7f ) << shift;
752+ val |= static_cast < uint64_t > (byte & 0x7f ) << shift;
753753 shift += 7 ;
754754 if (!(byte & 0x80 )) {
755755 i64 = val;
@@ -768,7 +768,7 @@ uint32_t TCompactProtocolT<Transport_>::readVarint64(int64_t& i64) {
768768 while (true ) {
769769 uint8_t byte;
770770 rsize += trans_->readAll (&byte, 1 );
771- val |= ( uint64_t ) (byte & 0x7f ) << shift;
771+ val |= static_cast < uint64_t > (byte & 0x7f ) << shift;
772772 shift += 7 ;
773773 if (!(byte & 0x80 )) {
774774 i64 = val;
@@ -827,7 +827,7 @@ TType TCompactProtocolT<Transport_>::getTType(int8_t type) {
827827 case detail::compact::CT_STRUCT:
828828 return T_STRUCT;
829829 default :
830- throw TException (std::string (" don't know what type: " ) + ( char ) type);
830+ throw TException (std::string (" don't know what type: " ) + static_cast < char >( type) );
831831 }
832832}
833833
0 commit comments