R/08-bit-from-raw.R

Defines functions raw_to_uint8 raw_to_int8 raw_to_hex8 raw_to_chr raw_to_utf8

Documented in raw_to_chr raw_to_hex8 raw_to_int8 raw_to_uint8 raw_to_utf8

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' @rdname raw_to_raw
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raw_to_uint8 <- function(raw_vec, ...) {
  stopifnot(is_raw_vec(raw_vec))

  readBin(raw_vec, what = 'int', n = length(raw_vec), size = 1L, signed = FALSE)
}


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' @rdname raw_to_raw
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raw_to_int8 <- function(raw_vec, ...) {
  stopifnot(is_raw_vec(raw_vec))

  readBin(raw_vec, what = 'int', n = length(raw_vec), size = 1L, signed = TRUE)
}


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' @rdname raw_to_raw
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raw_to_hex8 <- function(raw_vec, ...) {
  stopifnot(is_raw_vec(raw_vec))
  uint8_vec <- raw_to_uint8(raw_vec)

  format(as.hexmode(uint8_vec), width = 2L)
}


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' @rdname raw_to_raw
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raw_to_chr <- function(raw_vec, ...) {
  stopifnot(is_raw_vec(raw_vec))

  rawToChar(raw_vec)
}


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' @rdname raw_to_raw
#' @export
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
raw_to_utf8 <- function(raw_vec, ...) {
  stopifnot(is_raw_vec(raw_vec))

  intToUtf8(raw_vec)
}
coolbutuseless/minitypes documentation built on May 27, 2019, 9:55 a.m.