1#' Serialize a raw vector to a string
2#'
3#' @description
4#' \Sexpr[results=rd, stage=render]{rlang:::lifecycle("experimental")}
5#'
6#' This function converts a raw vector to a hexadecimal string,
7#' optionally adding a prefix and a suffix.
8#' It is roughly equivalent to
9#' `paste0(prefix, paste(format(x), collapse = ""), suffix)`
10#' and much faster.
11#'
12#' @param x A raw vector.
13#' @param prefix,suffix Prefix and suffix strings, or `NULL.
14#'
15#' @return A string.
16#' @export
17#' @examples
18#' raw_deparse_str(raw())
19#' raw_deparse_str(charToRaw("string"))
20#' raw_deparse_str(raw(10), prefix = "'0x", suffix = "'")
21raw_deparse_str <- function(x, prefix = NULL, suffix = NULL) {
22  if (!is.null(prefix)) {
23    prefix <- enc2utf8(prefix)
24  }
25
26  if (!is.null(suffix)) {
27    suffix <- enc2utf8(suffix)
28  }
29
30  .Call("rlang_raw_deparse_str", x, prefix, suffix)
31}
32