server/hotrod/src/main/java/org/infinispan/server/hotrod/HotRodDecoder.java
/**
    * Reads the header and returns whether we should try to continue
    *
    * @param buffer the buffer to read the header from
    * @return whether or not we should continue
    * @throws Exception
    */
Reads the header and returns whether we should try to continue
@param buffer the buffer to read the header from
@return whether or not we should continue
@throws Exception
Reads the header and returns whether we should try to continue @param buffer the buffer to read the header from @return whether or not we should continue @throws Exception
boolean readHeader(ByteBuf buffer) throws Exception {
      VersionedDecoder decoder = decodeCtx.decoder;
      HotRodHeader header = decodeCtx.header;
      if (decoder == null) {
         if (buffer.readableBytes() < 1) {
            buffer.resetReaderIndex();
            return false;
         }
         short magic = buffer.readUnsignedByte();
         if (CacheDecodeContext.isTrace)
            log.tracef("Header magic: %d", magic);
         if (magic != Constants.MAGIC_REQ) {
            if (previousException == null) {
               dumpBuffer("Invalid magic id", buffer);
               throw new InvalidMagicIdException("Error reading magic byte or message id: " + magic);
            } else {
               if (CacheDecodeContext.isTrace) {
                  log.tracef("Error happened previously, ignoring %d byte until we find the magic number again", magic);
               }
               return false;
            }
         } else {
            previousException = null;
         }
         long messageId = ExtendedByteBufJava.readMaybeVLong(buffer);
         if (messageId == Long.MIN_VALUE) {
            return false;
         }
         if (CacheDecodeContext.isTrace) {
            log.tracef("Header message id: %d", messageId);
         }
         header.messageId = messageId;
         if (buffer.readableBytes() < 1) {
            buffer.resetReaderIndex();
            return false;
         }
         byte version = (byte) buffer.readUnsignedByte();
         header.version = version;
         if (CacheDecodeContext.isTrace) {
            log.tracef("Header version: %d", version);
         }
         if (Constants.isVersion2x(version)) {
            decoder = new Decoder2x();
         } else if (Constants.isVersion1x(version)) {
            decoder = new Decoder10();
         } else {
            throw new UnknownVersionException("Unknown version:" + version, version, messageId);
         }
         decodeCtx.decoder = decoder;
         buffer.markReaderIndex();
      }
      try {
         if (!decoder.readHeader(buffer, header.version, header.messageId, header)) {
            return false;
         }
         if (CacheDecodeContext.isTrace) {
            log.tracef("Decoded header %s", header);
         }
         return true;
      } catch (HotRodUnknownOperationException | SecurityException e) {
         throw e;
      } catch (Exception e) {
         throw new RequestParsingException("Unable to parse header", header.version, header.messageId, e);
      }
   }
boolean readHeader ( ByteBuf buffer ) throws Exception { VersionedDecoder decoder = decodeCtx . decoder ; HotRodHeader header = decodeCtx . header ; if ( decoder == null ) { if ( buffer . readableBytes ( ) < 1 ) { buffer . resetReaderIndex ( ) ; return false ; } short magic = buffer . readUnsignedByte ( ) ; if ( CacheDecodeContext . isTrace ) log . tracef ( "Header magic: %d" , magic ) ; if ( magic != Constants . MAGIC_REQ ) { if ( previousException == null ) { dumpBuffer ( "Invalid magic id" , buffer ) ; throw new InvalidMagicIdException ( "Error reading magic byte or message id: " + magic ) ; } else { if ( CacheDecodeContext . isTrace ) { log . tracef ( "Error happened previously, ignoring %d byte until we find the magic number again" , magic ) ; } return false ; } } else { previousException = null ; } long messageId = ExtendedByteBufJava . readMaybeVLong ( buffer ) ; if ( messageId == Long . MIN_VALUE ) { return false ; } if ( CacheDecodeContext . isTrace ) { log . tracef ( "Header message id: %d" , messageId ) ; } header . messageId = messageId ; if ( buffer . readableBytes ( ) < 1 ) { buffer . resetReaderIndex ( ) ; return false ; } byte version = ( byte ) buffer . readUnsignedByte ( ) ; header . version = version ; if ( CacheDecodeContext . isTrace ) { log . tracef ( "Header version: %d" , version ) ; } if ( Constants . isVersion2x ( version ) ) { decoder = new Decoder2x ( ) ; } else if ( Constants . isVersion1x ( version ) ) { decoder = new Decoder10 ( ) ; } else { throw new UnknownVersionException ( "Unknown version:" + version , version , messageId ) ; } decodeCtx . decoder = decoder ; buffer . markReaderIndex ( ) ; } try { if ( ! decoder . readHeader ( buffer , header . version , header . messageId , header ) ) { return false ; } if ( CacheDecodeContext . isTrace ) { log . tracef ( "Decoded header %s" , header ) ; } return true ; } catch ( HotRodUnknownOperationException | SecurityException e ) { throw e ; } catch ( Exception e ) { throw new RequestParsingException ( "Unable to parse header" , header . version , header . messageId , e ) ; } }
Reads the header and returns whether we should try to continue
 @param buffer the buffer to read the header from
 @return whether or not we should continue
 @throws Exception
Reads the header and returns whether we should try to continue @param buffer the buffer to read the header from @return whether or not we should continue @throws Exception
// This way we won't have to reread the decoder related material again