AuthMetadataCodec { public static WellKnownAuthType readWellKnownAuthType(ByteBuf metadata) { if (metadata.readableBytes() < 1) { throw new IllegalStateException( "Unable to decode Well Know Auth type. Not enough readable bytes"); } byte lengthOrId = metadata.readByte(); int normalizedId = (byte) (lengthOrId & STREAM_METADATA_LENGTH_MASK); if (normalizedId != lengthOrId) { return WellKnownAuthType.fromIdentifier(normalizedId); } return WellKnownAuthType.UNPARSEABLE_AUTH_TYPE; } private  AuthMetadataCodec(); static ByteBuf encodeMetadata(
      ByteBufAllocator allocator, String customAuthType, ByteBuf metadata); static ByteBuf encodeMetadata(
      ByteBufAllocator allocator, WellKnownAuthType authType, ByteBuf metadata); static ByteBuf encodeSimpleMetadata(
      ByteBufAllocator allocator, char[] username, char[] password); static ByteBuf encodeBearerMetadata(ByteBufAllocator allocator, char[] token); static ByteBuf encodeMetadataWithCompression(
      ByteBufAllocator allocator, String authType, ByteBuf metadata); static boolean isWellKnownAuthType(ByteBuf metadata); static WellKnownAuthType readWellKnownAuthType(ByteBuf metadata); static CharSequence readCustomAuthType(ByteBuf metadata); static ByteBuf readPayload(ByteBuf metadata); static ByteBuf readUsername(ByteBuf simpleAuthMetadata); static ByteBuf readPassword(ByteBuf simpleAuthMetadata); static char[] readUsernameAsCharArray(ByteBuf simpleAuthMetadata); static char[] readPasswordAsCharArray(ByteBuf simpleAuthMetadata); static char[] readBearerTokenAsCharArray(ByteBuf bearerAuthMetadata);  }
@Test void shouldThrowExceptionIsNotEnoughReadableBytes() { Assertions.assertThatThrownBy( () -> AuthMetadataCodec.readWellKnownAuthType(Unpooled.EMPTY_BUFFER)) .hasMessage("Unable to decode Well Know Auth type. Not enough readable bytes"); }