reifydb_core/util/encoding/binary.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4// This file includes and modifies code from the toydb project (https://github.com/erikgrinaker/toydb),
5// originally licensed under the Apache License, Version 2.0.
6// Original copyright:
7// Copyright (c) 2024 Erik Grinaker
8//
9// The original Apache License can be found at:
10// http://www.apache.org/licenses/LICENSE-2.0
11
12pub fn decode_binary(s: &str) -> Vec<u8> {
13 let mut buf = [0; 4];
14 let mut bytes = Vec::new();
15 for c in s.chars() {
16 match c as u32 {
17 b @ 0x80..=0xff => bytes.push(b as u8),
18 _ => bytes.extend(c.encode_utf8(&mut buf).as_bytes()),
19 }
20 }
21 bytes
22}