AuthMetadataCodec { public static ByteBuf encodeBearerMetadata(ByteBufAllocator allocator, char[] token) { int tokenLength = CharByteBufUtil.utf8Bytes(token); int capacity = AUTH_TYPE_ID_LENGTH + tokenLength; final ByteBuf buffer = allocator .buffer(capacity, capacity) .writeByte(WellKnownAuthType.BEARER.getIdentifier() | STREAM_METADATA_KNOWN_MASK); CharByteBufUtil.writeUtf8(buffer, token); return buffer; } 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 shouldEncodeBearerMetadata() { String testToken = TEST_BEARER_TOKEN; ByteBuf byteBuf = AuthMetadataCodec.encodeBearerMetadata(ByteBufAllocator.DEFAULT, testToken.toCharArray()); byteBuf.markReaderIndex(); checkBearerAuthMetadataEncoding(testToken, byteBuf); byteBuf.resetReaderIndex(); checkBearerAuthMetadataEncodingUsingDecoders(testToken, byteBuf); }