module Crowbar::Encoding

Overview

Binary Input and Output Representation Codecs. Provides transparent conversion between human-friendly CLI string encodings (hexadecimal, C-escapes, bitstrings, base64) and raw binary buffers.

Defined in:

crowbar/encoding.cr

Class Method Summary

Class Method Detail

def self.decode(input : String | Bytes | Buffer, format : Format | String | Symbol = Format::Raw) : Buffer #

Decodes an input string, bytes, or buffer into a raw binary Buffer


def self.decode_base64(str : String) : Buffer #

Decodes Base64 strings to raw binary Buffer


def self.decode_bit(str : String) : Buffer #

Decodes bitstring representations (e.g. "0b01010100 01110010" or "0101010001110010")


def self.decode_escape(str : String) : Buffer #

Decodes C-style escape representations (e.g. "\x64\xaf\x00\r\n\t")


def self.decode_hex(str : String) : Buffer #

Decodes hexadecimal string representations (e.g. "414243", "0x41 0x42", "41:42:43")


def self.detect(input : String) : Format #

Auto-detects the most probable encoding of an input string representation


def self.encode(buffer : Buffer | Bytes, format : Format | String | Symbol = Format::Raw) : String #

Encodes a binary buffer into the requested string representation