public Optional < Integer > detectSchemaId ( byte [ ] data ) { if ( data . length < 5 ) { return Optional . empty ( ) ; } ByteBuffer wrapped = ByteBuffer . wrap ( data ) ; // 5 == MAGIC_BYTE + ID_SIZE if ( wrapped . get ( ) != MAGIC_BYTE ) { return Optional . empty ( ) ; } return Optional . of ( wrapped . getInt ( ) ) ; }
Checks for a magic byte in the data and if present extracts the schemaId