rename: src/Formats -> src/Rosetta, @formats -> @rosetta requires, build/luajit/rosetta + rosetta._compat, build/roblox/Rosetta, ROSETTA_* env/globals, writer vendor strings

This commit is contained in:
4DBug committed 2026-11-01 01:19:16 -05:00
1 parent 2956576d7f
commit 22ddcd78fa
941 files changed
+3364 -3364

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
--!strict
-- data/nbt: Minecraft NBT files (.nbt structures, level.dat / playerdata .dat, servers.dat, Bedrock .mcstructure and
-- level.dat), a thin format over codecs/text/Nbt (which see for the value mapping). Supports: Java big-endian and
-- Bedrock little-endian NBT (the level.dat 8-byte header too; network varint NBT with opts.varint), gzip / zlib /
-- uncompressed, every tag type, exact round trips (Nbt.info(value) remembers the root name, edition, compression
-- and header; encode writes it back the same way unless opts say otherwise). Text SNBT: data/snbt.
-- Not supported: nothing in the format.
-- ------------------------------------------------------------------------------------------------ requires
local Err = require("@rosetta/core/Err")
local Bytes = require("@rosetta/core/Bytes")
local Nbt = require("@rosetta/codecs/text/Nbt")
-- ------------------------------------------------------------------------------------------------ contract
local NbtFormat = {
name = "nbt",
category = "data",
extensions = { "nbt", "dat", "mcstructure", "dat_old" },
mime = { "application/x-minecraft-nbt" },
deps = { "core/Err", "core/Bytes", "codecs/text/Nbt" },
caps = { decode = true, encode = true, binary = true, ordered = true, typed = true },
}
export type DecodeOptions = Nbt.DecodeOptions
export type EncodeOptions = Nbt.EncodeOptions
-- ------------------------------------------------------------------------------------------------ sniff
function NbtFormat.sniff(r: Bytes.Reader): number
local p = Nbt.peek(r.buf, r.base, r.limit - r.base)
if not p or p.rootType ~= "compound" then
return 0
end
if p.compression ~= "none" then
return if p.firstType then 1 else 0.5 -- gzip wrapped NBT: ties with archive/gzip go to the extension
end
return if p.firstType and p.firstName then 0.6 else 0.2
end
-- ------------------------------------------------------------------------------------------------ decode
function NbtFormat.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
local v, info = Nbt.decode(r.buf, opts, r.base, r.limit - r.base)
if v == nil then
return nil, info
end
return v, nil
end
-- ------------------------------------------------------------------------------------------------ encode
function NbtFormat.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
if value == nil then
return nil, Err.new(Err.ARG, "nothing to encode")
end
return Nbt.encode(value, opts)
end
-- ------------------------------------------------------------------------------------------------ extras
NbtFormat.info = Nbt.info -- how a decoded value was stored: { name, endian, compression, header?, varint? }
NbtFormat.Nbt = Nbt
return NbtFormat