渲染zh-Hans

字节

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.

Primitive byte-buffer type.

Aliases: bytes

Syntax: 字节

Category#

type

Examples#

radix/corpus/octeti/octeti.fab (canonical · keyword)#

Primitive byte-buffer type.

# =============================================================================
# 字节 — Primitive byte-buffer type.
# =============================================================================
#
# What this teaches:
#   • Primitive buffer type — `字节` is the built-in byte buffer, analogous to `Vec<u8>` in Rust.
#   • Literal syntax — Byte buffers can be written with hex literals like `|借自 调用 be ef|`.
#
# Common mistakes:
#   • Writing 字节 hex literals with an odd digit count — each byte requires two hex digits.
#
# See also: 文本, 列表
# =============================================================================

# 字节 — byte-buffer type alias
#
# 类型 Fascis = 字节
#
# GRAMMAR:
#   typeAliasDecl :← '类型' ident '=' typeExpr
#
# EXPECTED OUTPUT:
#   octeti.expected — type-known diagnostic.

type Fascis = bytes

main {
    const bytes sig ← |借自 调用 be ef|
    const bytes hello ← |48 65 6c 6c 6f|
    const bytes empty ← ||
    print "octeti typus notus"
}

Expected output:

octeti typus notus

radix/corpus/bounded/conversio-octeti-to-octeti-decline.fab (supporting · reject)#

Decline: bounded 字节<N> cannot resize directly to bounded 字节<M>.

# =============================================================================
# bounded 字节 resize — unsupported 变换 decline
# =============================================================================
#
# What this teaches:
#   • Bounded byte capacities are not interchangeable through an implicit
#     resize route.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • expecting a bounded byte 变换 to truncate or pad silently.

fn resize(bytes<8> raw) → bytes<4> {
    return raw ↦ bytes<4>
}

Expected: compilation rejects this example.

radix/corpus/bounded/conversio-octeti-to-textus-decline.fab (supporting · reject)#

Decline: bounded 字节<N> cannot convert directly to unbounded 文本.

# =============================================================================
# bounded 字节 to 文本 — unsupported 变换 decline
# =============================================================================
#
# What this teaches:
#   • A bounded byte carrier does not silently become 文本 through `↦`.
#   • The unsupported route fails closed with `SEM016:unsupported_conversio`.
#
# Common mistakes:
#   • assuming byte decoding is the same as a bounded-width 拷贝 — decoding
#     needs an explicit 字节/textus library route, not this 变换.

fn widen(bytes<8> raw) → string {
    return raw ↦ string
}

Expected: compilation rejects this example.