// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! x-user-defined, § 14.5. //! //! Technically a single-byte encoding, defined apart from the others because //! it needs no table: every byte from 0x80 up goes to the private use area at //! U+F780 and back again. That makes it the one legacy encoding that round //! trips arbitrary bytes, which is what it is for -- reading binary through //! something that insists on handing you text. const codec = @import("../codec.zig"); const ByteQueue = codec.ByteQueue; const Decoded = codec.Decoded; const Encoded = codec.Encoded; pub const Decoder = struct { pub fn handle(_: *Decoder, _: *ByteQueue, byte: ?u8) Decoded { const b = byte orelse return .finished; if (b < 0x80) return .{ .code_point = b }; return .{ .code_point = 0xf780 + @as(u21, b) - 0x80 }; } }; pub const Encoder = struct { pub fn handle(_: *Encoder, code_point: ?u21) Encoded { const c = code_point orelse return .finished; if (c < 0x80) return .{ .bytes = .one(@intCast(c)) }; if (c >= 0xf780 and c <= 0xf7ff) return .{ .bytes = .one(@intCast(c - 0xf780 + 0x80)) }; return .{ .failure = c }; } };