Spaces:
Sleeping
Sleeping
Upload 12 files
Browse files- src/.dockerignore +3 -0
- src/.gitignore +1 -0
- src/Cargo.lock +1622 -0
- src/Cargo.toml +24 -0
- src/Dockerfile +22 -0
- src/README.md +184 -0
- src/src/encoder.rs +705 -0
- src/src/http.rs +570 -0
- src/src/loader.rs +199 -0
- src/src/main.rs +60 -0
- src/src/nbt.rs +1143 -0
- src/src/store.rs +109 -0
src/.dockerignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
target
|
| 2 |
+
.git
|
| 3 |
+
*.zip
|
src/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
target
|
src/Cargo.lock
ADDED
|
@@ -0,0 +1,1622 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
name = "aho-corasick"
|
| 7 |
+
version = "1.1.5"
|
| 8 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 9 |
+
checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
|
| 10 |
+
dependencies = [
|
| 11 |
+
"memchr",
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
[[package]]
|
| 15 |
+
name = "async-trait"
|
| 16 |
+
version = "0.1.92"
|
| 17 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 18 |
+
checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667"
|
| 19 |
+
dependencies = [
|
| 20 |
+
"proc-macro2",
|
| 21 |
+
"quote",
|
| 22 |
+
"syn 3.0.9",
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
[[package]]
|
| 26 |
+
name = "atomic-waker"
|
| 27 |
+
version = "1.1.2"
|
| 28 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 29 |
+
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
| 30 |
+
|
| 31 |
+
[[package]]
|
| 32 |
+
name = "axum"
|
| 33 |
+
version = "0.7.9"
|
| 34 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 35 |
+
checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f"
|
| 36 |
+
dependencies = [
|
| 37 |
+
"async-trait",
|
| 38 |
+
"axum-core",
|
| 39 |
+
"bytes",
|
| 40 |
+
"futures-util",
|
| 41 |
+
"http",
|
| 42 |
+
"http-body",
|
| 43 |
+
"http-body-util",
|
| 44 |
+
"hyper",
|
| 45 |
+
"hyper-util",
|
| 46 |
+
"itoa",
|
| 47 |
+
"matchit",
|
| 48 |
+
"memchr",
|
| 49 |
+
"mime",
|
| 50 |
+
"percent-encoding",
|
| 51 |
+
"pin-project-lite",
|
| 52 |
+
"rustversion",
|
| 53 |
+
"serde",
|
| 54 |
+
"serde_json",
|
| 55 |
+
"serde_path_to_error",
|
| 56 |
+
"serde_urlencoded",
|
| 57 |
+
"sync_wrapper",
|
| 58 |
+
"tokio",
|
| 59 |
+
"tower 0.5.3",
|
| 60 |
+
"tower-layer",
|
| 61 |
+
"tower-service",
|
| 62 |
+
"tracing",
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
[[package]]
|
| 66 |
+
name = "axum-core"
|
| 67 |
+
version = "0.4.5"
|
| 68 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 69 |
+
checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199"
|
| 70 |
+
dependencies = [
|
| 71 |
+
"async-trait",
|
| 72 |
+
"bytes",
|
| 73 |
+
"futures-util",
|
| 74 |
+
"http",
|
| 75 |
+
"http-body",
|
| 76 |
+
"http-body-util",
|
| 77 |
+
"mime",
|
| 78 |
+
"pin-project-lite",
|
| 79 |
+
"rustversion",
|
| 80 |
+
"sync_wrapper",
|
| 81 |
+
"tower-layer",
|
| 82 |
+
"tower-service",
|
| 83 |
+
"tracing",
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
[[package]]
|
| 87 |
+
name = "base64"
|
| 88 |
+
version = "0.22.1"
|
| 89 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 90 |
+
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
| 91 |
+
|
| 92 |
+
[[package]]
|
| 93 |
+
name = "base64"
|
| 94 |
+
version = "0.23.1"
|
| 95 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 96 |
+
checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5"
|
| 97 |
+
|
| 98 |
+
[[package]]
|
| 99 |
+
name = "bitflags"
|
| 100 |
+
version = "2.13.2"
|
| 101 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 102 |
+
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
| 103 |
+
|
| 104 |
+
[[package]]
|
| 105 |
+
name = "bumpalo"
|
| 106 |
+
version = "3.20.3"
|
| 107 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 108 |
+
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
| 109 |
+
|
| 110 |
+
[[package]]
|
| 111 |
+
name = "bytes"
|
| 112 |
+
version = "1.12.1"
|
| 113 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 114 |
+
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
|
| 115 |
+
|
| 116 |
+
[[package]]
|
| 117 |
+
name = "cc"
|
| 118 |
+
version = "1.8.0"
|
| 119 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 120 |
+
checksum = "6651c9ed80effdc7db0ff72512157f901af5e3549e341e24b1dd4887d836d838"
|
| 121 |
+
dependencies = [
|
| 122 |
+
"find-msvc-tools",
|
| 123 |
+
"shlex",
|
| 124 |
+
]
|
| 125 |
+
|
| 126 |
+
[[package]]
|
| 127 |
+
name = "cfg-if"
|
| 128 |
+
version = "1.0.5"
|
| 129 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 130 |
+
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
| 131 |
+
|
| 132 |
+
[[package]]
|
| 133 |
+
name = "cfg_aliases"
|
| 134 |
+
version = "0.2.2"
|
| 135 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 136 |
+
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
|
| 137 |
+
|
| 138 |
+
[[package]]
|
| 139 |
+
name = "chacha20"
|
| 140 |
+
version = "0.10.2"
|
| 141 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 142 |
+
checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
|
| 143 |
+
dependencies = [
|
| 144 |
+
"cfg-if",
|
| 145 |
+
"cpufeatures",
|
| 146 |
+
"rand_core",
|
| 147 |
+
]
|
| 148 |
+
|
| 149 |
+
[[package]]
|
| 150 |
+
name = "cpufeatures"
|
| 151 |
+
version = "0.3.1"
|
| 152 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 153 |
+
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
|
| 154 |
+
dependencies = [
|
| 155 |
+
"libc",
|
| 156 |
+
]
|
| 157 |
+
|
| 158 |
+
[[package]]
|
| 159 |
+
name = "displaydoc"
|
| 160 |
+
version = "0.2.7"
|
| 161 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 162 |
+
checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8"
|
| 163 |
+
dependencies = [
|
| 164 |
+
"proc-macro2",
|
| 165 |
+
"quote",
|
| 166 |
+
"syn 3.0.9",
|
| 167 |
+
]
|
| 168 |
+
|
| 169 |
+
[[package]]
|
| 170 |
+
name = "errno"
|
| 171 |
+
version = "0.3.14"
|
| 172 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 173 |
+
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
| 174 |
+
dependencies = [
|
| 175 |
+
"libc",
|
| 176 |
+
"windows-sys 0.61.2",
|
| 177 |
+
]
|
| 178 |
+
|
| 179 |
+
[[package]]
|
| 180 |
+
name = "find-msvc-tools"
|
| 181 |
+
version = "0.1.14"
|
| 182 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 183 |
+
checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484"
|
| 184 |
+
|
| 185 |
+
[[package]]
|
| 186 |
+
name = "flate2"
|
| 187 |
+
version = "1.1.10"
|
| 188 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 189 |
+
checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
|
| 190 |
+
dependencies = [
|
| 191 |
+
"zlib-rs",
|
| 192 |
+
]
|
| 193 |
+
|
| 194 |
+
[[package]]
|
| 195 |
+
name = "form_urlencoded"
|
| 196 |
+
version = "1.2.2"
|
| 197 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 198 |
+
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
|
| 199 |
+
dependencies = [
|
| 200 |
+
"percent-encoding",
|
| 201 |
+
]
|
| 202 |
+
|
| 203 |
+
[[package]]
|
| 204 |
+
name = "futures-channel"
|
| 205 |
+
version = "0.3.34"
|
| 206 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 207 |
+
checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
|
| 208 |
+
dependencies = [
|
| 209 |
+
"futures-core",
|
| 210 |
+
]
|
| 211 |
+
|
| 212 |
+
[[package]]
|
| 213 |
+
name = "futures-core"
|
| 214 |
+
version = "0.3.34"
|
| 215 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 216 |
+
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
| 217 |
+
|
| 218 |
+
[[package]]
|
| 219 |
+
name = "futures-task"
|
| 220 |
+
version = "0.3.34"
|
| 221 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 222 |
+
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
|
| 223 |
+
|
| 224 |
+
[[package]]
|
| 225 |
+
name = "futures-util"
|
| 226 |
+
version = "0.3.34"
|
| 227 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 228 |
+
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
| 229 |
+
dependencies = [
|
| 230 |
+
"futures-core",
|
| 231 |
+
"futures-task",
|
| 232 |
+
"pin-project-lite",
|
| 233 |
+
"slab",
|
| 234 |
+
]
|
| 235 |
+
|
| 236 |
+
[[package]]
|
| 237 |
+
name = "getrandom"
|
| 238 |
+
version = "0.2.17"
|
| 239 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 240 |
+
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
|
| 241 |
+
dependencies = [
|
| 242 |
+
"cfg-if",
|
| 243 |
+
"js-sys",
|
| 244 |
+
"libc",
|
| 245 |
+
"wasi",
|
| 246 |
+
"wasm-bindgen",
|
| 247 |
+
]
|
| 248 |
+
|
| 249 |
+
[[package]]
|
| 250 |
+
name = "getrandom"
|
| 251 |
+
version = "0.4.3"
|
| 252 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 253 |
+
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
| 254 |
+
dependencies = [
|
| 255 |
+
"cfg-if",
|
| 256 |
+
"js-sys",
|
| 257 |
+
"libc",
|
| 258 |
+
"r-efi",
|
| 259 |
+
"rand_core",
|
| 260 |
+
"wasm-bindgen",
|
| 261 |
+
]
|
| 262 |
+
|
| 263 |
+
[[package]]
|
| 264 |
+
name = "http"
|
| 265 |
+
version = "1.5.0"
|
| 266 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 267 |
+
checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
|
| 268 |
+
dependencies = [
|
| 269 |
+
"bytes",
|
| 270 |
+
"itoa",
|
| 271 |
+
]
|
| 272 |
+
|
| 273 |
+
[[package]]
|
| 274 |
+
name = "http-body"
|
| 275 |
+
version = "1.1.0"
|
| 276 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 277 |
+
checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
|
| 278 |
+
dependencies = [
|
| 279 |
+
"bytes",
|
| 280 |
+
"http",
|
| 281 |
+
]
|
| 282 |
+
|
| 283 |
+
[[package]]
|
| 284 |
+
name = "http-body-util"
|
| 285 |
+
version = "0.1.5"
|
| 286 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 287 |
+
checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c"
|
| 288 |
+
dependencies = [
|
| 289 |
+
"bytes",
|
| 290 |
+
"futures-core",
|
| 291 |
+
"http",
|
| 292 |
+
"http-body",
|
| 293 |
+
"pin-project-lite",
|
| 294 |
+
]
|
| 295 |
+
|
| 296 |
+
[[package]]
|
| 297 |
+
name = "httparse"
|
| 298 |
+
version = "1.10.1"
|
| 299 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 300 |
+
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
| 301 |
+
|
| 302 |
+
[[package]]
|
| 303 |
+
name = "httpdate"
|
| 304 |
+
version = "1.0.3"
|
| 305 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 306 |
+
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
| 307 |
+
|
| 308 |
+
[[package]]
|
| 309 |
+
name = "hyper"
|
| 310 |
+
version = "1.12.0"
|
| 311 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 312 |
+
checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c"
|
| 313 |
+
dependencies = [
|
| 314 |
+
"atomic-waker",
|
| 315 |
+
"bytes",
|
| 316 |
+
"futures-core",
|
| 317 |
+
"http",
|
| 318 |
+
"http-body",
|
| 319 |
+
"httparse",
|
| 320 |
+
"httpdate",
|
| 321 |
+
"itoa",
|
| 322 |
+
"pin-project-lite",
|
| 323 |
+
"smallvec",
|
| 324 |
+
"tokio",
|
| 325 |
+
"want",
|
| 326 |
+
]
|
| 327 |
+
|
| 328 |
+
[[package]]
|
| 329 |
+
name = "hyper-rustls"
|
| 330 |
+
version = "0.27.10"
|
| 331 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 332 |
+
checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53"
|
| 333 |
+
dependencies = [
|
| 334 |
+
"http",
|
| 335 |
+
"hyper",
|
| 336 |
+
"hyper-util",
|
| 337 |
+
"rustls",
|
| 338 |
+
"tokio",
|
| 339 |
+
"tokio-rustls",
|
| 340 |
+
"tower-service",
|
| 341 |
+
"webpki-roots",
|
| 342 |
+
]
|
| 343 |
+
|
| 344 |
+
[[package]]
|
| 345 |
+
name = "hyper-util"
|
| 346 |
+
version = "0.1.21"
|
| 347 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 348 |
+
checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
|
| 349 |
+
dependencies = [
|
| 350 |
+
"base64 0.23.1",
|
| 351 |
+
"bytes",
|
| 352 |
+
"futures-channel",
|
| 353 |
+
"futures-util",
|
| 354 |
+
"http",
|
| 355 |
+
"http-body",
|
| 356 |
+
"httparse",
|
| 357 |
+
"hyper",
|
| 358 |
+
"ipnet",
|
| 359 |
+
"libc",
|
| 360 |
+
"percent-encoding",
|
| 361 |
+
"pin-project-lite",
|
| 362 |
+
"socket2",
|
| 363 |
+
"tokio",
|
| 364 |
+
"tower-service",
|
| 365 |
+
"tracing",
|
| 366 |
+
]
|
| 367 |
+
|
| 368 |
+
[[package]]
|
| 369 |
+
name = "icu_collections"
|
| 370 |
+
version = "2.3.0"
|
| 371 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 372 |
+
checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513"
|
| 373 |
+
dependencies = [
|
| 374 |
+
"displaydoc",
|
| 375 |
+
"potential_utf",
|
| 376 |
+
"utf8_iter",
|
| 377 |
+
"yoke",
|
| 378 |
+
"zerofrom",
|
| 379 |
+
"zerovec",
|
| 380 |
+
]
|
| 381 |
+
|
| 382 |
+
[[package]]
|
| 383 |
+
name = "icu_locale_core"
|
| 384 |
+
version = "2.3.0"
|
| 385 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 386 |
+
checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb"
|
| 387 |
+
dependencies = [
|
| 388 |
+
"displaydoc",
|
| 389 |
+
"litemap",
|
| 390 |
+
"tinystr",
|
| 391 |
+
"writeable",
|
| 392 |
+
"zerovec",
|
| 393 |
+
]
|
| 394 |
+
|
| 395 |
+
[[package]]
|
| 396 |
+
name = "icu_normalizer"
|
| 397 |
+
version = "2.3.0"
|
| 398 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 399 |
+
checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f"
|
| 400 |
+
dependencies = [
|
| 401 |
+
"icu_collections",
|
| 402 |
+
"icu_normalizer_data",
|
| 403 |
+
"icu_properties",
|
| 404 |
+
"icu_provider",
|
| 405 |
+
"smallvec",
|
| 406 |
+
"zerovec",
|
| 407 |
+
]
|
| 408 |
+
|
| 409 |
+
[[package]]
|
| 410 |
+
name = "icu_normalizer_data"
|
| 411 |
+
version = "2.3.0"
|
| 412 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 413 |
+
checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0"
|
| 414 |
+
|
| 415 |
+
[[package]]
|
| 416 |
+
name = "icu_properties"
|
| 417 |
+
version = "2.3.0"
|
| 418 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 419 |
+
checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148"
|
| 420 |
+
dependencies = [
|
| 421 |
+
"displaydoc",
|
| 422 |
+
"icu_collections",
|
| 423 |
+
"icu_locale_core",
|
| 424 |
+
"icu_properties_data",
|
| 425 |
+
"icu_provider",
|
| 426 |
+
"zerotrie",
|
| 427 |
+
"zerovec",
|
| 428 |
+
]
|
| 429 |
+
|
| 430 |
+
[[package]]
|
| 431 |
+
name = "icu_properties_data"
|
| 432 |
+
version = "2.3.0"
|
| 433 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 434 |
+
checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa"
|
| 435 |
+
|
| 436 |
+
[[package]]
|
| 437 |
+
name = "icu_provider"
|
| 438 |
+
version = "2.3.1"
|
| 439 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 440 |
+
checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73"
|
| 441 |
+
dependencies = [
|
| 442 |
+
"displaydoc",
|
| 443 |
+
"icu_locale_core",
|
| 444 |
+
"writeable",
|
| 445 |
+
"yoke",
|
| 446 |
+
"zerofrom",
|
| 447 |
+
"zerotrie",
|
| 448 |
+
"zerovec",
|
| 449 |
+
]
|
| 450 |
+
|
| 451 |
+
[[package]]
|
| 452 |
+
name = "idna"
|
| 453 |
+
version = "1.1.0"
|
| 454 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 455 |
+
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
|
| 456 |
+
dependencies = [
|
| 457 |
+
"idna_adapter",
|
| 458 |
+
"smallvec",
|
| 459 |
+
"utf8_iter",
|
| 460 |
+
]
|
| 461 |
+
|
| 462 |
+
[[package]]
|
| 463 |
+
name = "idna_adapter"
|
| 464 |
+
version = "1.2.2"
|
| 465 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 466 |
+
checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
|
| 467 |
+
dependencies = [
|
| 468 |
+
"icu_normalizer",
|
| 469 |
+
"icu_properties",
|
| 470 |
+
]
|
| 471 |
+
|
| 472 |
+
[[package]]
|
| 473 |
+
name = "ipnet"
|
| 474 |
+
version = "2.12.2"
|
| 475 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 476 |
+
checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0"
|
| 477 |
+
|
| 478 |
+
[[package]]
|
| 479 |
+
name = "itoa"
|
| 480 |
+
version = "1.0.18"
|
| 481 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 482 |
+
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
| 483 |
+
|
| 484 |
+
[[package]]
|
| 485 |
+
name = "js-sys"
|
| 486 |
+
version = "0.3.106"
|
| 487 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 488 |
+
checksum = "7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5"
|
| 489 |
+
dependencies = [
|
| 490 |
+
"cfg-if",
|
| 491 |
+
"futures-util",
|
| 492 |
+
"wasm-bindgen",
|
| 493 |
+
]
|
| 494 |
+
|
| 495 |
+
[[package]]
|
| 496 |
+
name = "lazy_static"
|
| 497 |
+
version = "1.5.1"
|
| 498 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 499 |
+
checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
|
| 500 |
+
|
| 501 |
+
[[package]]
|
| 502 |
+
name = "libc"
|
| 503 |
+
version = "0.2.191"
|
| 504 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 505 |
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
| 506 |
+
|
| 507 |
+
[[package]]
|
| 508 |
+
name = "litemap"
|
| 509 |
+
version = "0.8.3"
|
| 510 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 511 |
+
checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
|
| 512 |
+
|
| 513 |
+
[[package]]
|
| 514 |
+
name = "litematic-host"
|
| 515 |
+
version = "0.1.0"
|
| 516 |
+
dependencies = [
|
| 517 |
+
"axum",
|
| 518 |
+
"flate2",
|
| 519 |
+
"http-body-util",
|
| 520 |
+
"reqwest",
|
| 521 |
+
"serde_json",
|
| 522 |
+
"tokio",
|
| 523 |
+
"tower 0.4.13",
|
| 524 |
+
"tracing",
|
| 525 |
+
"tracing-subscriber",
|
| 526 |
+
"uuid",
|
| 527 |
+
]
|
| 528 |
+
|
| 529 |
+
[[package]]
|
| 530 |
+
name = "lock_api"
|
| 531 |
+
version = "0.4.14"
|
| 532 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 533 |
+
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
|
| 534 |
+
dependencies = [
|
| 535 |
+
"scopeguard",
|
| 536 |
+
]
|
| 537 |
+
|
| 538 |
+
[[package]]
|
| 539 |
+
name = "log"
|
| 540 |
+
version = "0.4.34"
|
| 541 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 542 |
+
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
| 543 |
+
|
| 544 |
+
[[package]]
|
| 545 |
+
name = "lru-slab"
|
| 546 |
+
version = "0.1.3"
|
| 547 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 548 |
+
checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f"
|
| 549 |
+
|
| 550 |
+
[[package]]
|
| 551 |
+
name = "matchers"
|
| 552 |
+
version = "0.2.0"
|
| 553 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 554 |
+
checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9"
|
| 555 |
+
dependencies = [
|
| 556 |
+
"regex-automata",
|
| 557 |
+
]
|
| 558 |
+
|
| 559 |
+
[[package]]
|
| 560 |
+
name = "matchit"
|
| 561 |
+
version = "0.7.3"
|
| 562 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 563 |
+
checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
|
| 564 |
+
|
| 565 |
+
[[package]]
|
| 566 |
+
name = "memchr"
|
| 567 |
+
version = "2.8.3"
|
| 568 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 569 |
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
| 570 |
+
|
| 571 |
+
[[package]]
|
| 572 |
+
name = "mime"
|
| 573 |
+
version = "0.3.17"
|
| 574 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 575 |
+
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
| 576 |
+
|
| 577 |
+
[[package]]
|
| 578 |
+
name = "mio"
|
| 579 |
+
version = "1.2.4"
|
| 580 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 581 |
+
checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee"
|
| 582 |
+
dependencies = [
|
| 583 |
+
"libc",
|
| 584 |
+
"wasi",
|
| 585 |
+
"windows-sys 0.61.2",
|
| 586 |
+
]
|
| 587 |
+
|
| 588 |
+
[[package]]
|
| 589 |
+
name = "nu-ansi-term"
|
| 590 |
+
version = "0.50.3"
|
| 591 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 592 |
+
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
| 593 |
+
dependencies = [
|
| 594 |
+
"windows-sys 0.61.2",
|
| 595 |
+
]
|
| 596 |
+
|
| 597 |
+
[[package]]
|
| 598 |
+
name = "once_cell"
|
| 599 |
+
version = "1.21.4"
|
| 600 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 601 |
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
| 602 |
+
|
| 603 |
+
[[package]]
|
| 604 |
+
name = "parking_lot"
|
| 605 |
+
version = "0.12.5"
|
| 606 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 607 |
+
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
|
| 608 |
+
dependencies = [
|
| 609 |
+
"lock_api",
|
| 610 |
+
"parking_lot_core",
|
| 611 |
+
]
|
| 612 |
+
|
| 613 |
+
[[package]]
|
| 614 |
+
name = "parking_lot_core"
|
| 615 |
+
version = "0.9.12"
|
| 616 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 617 |
+
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
|
| 618 |
+
dependencies = [
|
| 619 |
+
"cfg-if",
|
| 620 |
+
"libc",
|
| 621 |
+
"redox_syscall",
|
| 622 |
+
"smallvec",
|
| 623 |
+
"windows-link",
|
| 624 |
+
]
|
| 625 |
+
|
| 626 |
+
[[package]]
|
| 627 |
+
name = "percent-encoding"
|
| 628 |
+
version = "2.3.2"
|
| 629 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 630 |
+
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
| 631 |
+
|
| 632 |
+
[[package]]
|
| 633 |
+
name = "pin-project"
|
| 634 |
+
version = "1.1.13"
|
| 635 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 636 |
+
checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924"
|
| 637 |
+
dependencies = [
|
| 638 |
+
"pin-project-internal",
|
| 639 |
+
]
|
| 640 |
+
|
| 641 |
+
[[package]]
|
| 642 |
+
name = "pin-project-internal"
|
| 643 |
+
version = "1.1.13"
|
| 644 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 645 |
+
checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b"
|
| 646 |
+
dependencies = [
|
| 647 |
+
"proc-macro2",
|
| 648 |
+
"quote",
|
| 649 |
+
"syn 2.0.119",
|
| 650 |
+
]
|
| 651 |
+
|
| 652 |
+
[[package]]
|
| 653 |
+
name = "pin-project-lite"
|
| 654 |
+
version = "0.2.17"
|
| 655 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 656 |
+
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
| 657 |
+
|
| 658 |
+
[[package]]
|
| 659 |
+
name = "potential_utf"
|
| 660 |
+
version = "0.1.6"
|
| 661 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 662 |
+
checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661"
|
| 663 |
+
dependencies = [
|
| 664 |
+
"zerovec",
|
| 665 |
+
]
|
| 666 |
+
|
| 667 |
+
[[package]]
|
| 668 |
+
name = "proc-macro2"
|
| 669 |
+
version = "1.0.107"
|
| 670 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 671 |
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
| 672 |
+
dependencies = [
|
| 673 |
+
"unicode-ident",
|
| 674 |
+
]
|
| 675 |
+
|
| 676 |
+
[[package]]
|
| 677 |
+
name = "quinn"
|
| 678 |
+
version = "0.11.12"
|
| 679 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 680 |
+
checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11"
|
| 681 |
+
dependencies = [
|
| 682 |
+
"bytes",
|
| 683 |
+
"cfg_aliases",
|
| 684 |
+
"pin-project-lite",
|
| 685 |
+
"quinn-proto",
|
| 686 |
+
"quinn-udp",
|
| 687 |
+
"rustc-hash",
|
| 688 |
+
"rustls",
|
| 689 |
+
"socket2",
|
| 690 |
+
"thiserror",
|
| 691 |
+
"tokio",
|
| 692 |
+
"tracing",
|
| 693 |
+
"web-time",
|
| 694 |
+
]
|
| 695 |
+
|
| 696 |
+
[[package]]
|
| 697 |
+
name = "quinn-proto"
|
| 698 |
+
version = "0.11.19"
|
| 699 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 700 |
+
checksum = "0e750cca55fe4f0439a15d0bb529da9651e79993e8e72c61a899a36d462befbe"
|
| 701 |
+
dependencies = [
|
| 702 |
+
"bytes",
|
| 703 |
+
"getrandom 0.4.3",
|
| 704 |
+
"lru-slab",
|
| 705 |
+
"rand",
|
| 706 |
+
"rand_pcg",
|
| 707 |
+
"ring",
|
| 708 |
+
"rustc-hash",
|
| 709 |
+
"rustls",
|
| 710 |
+
"rustls-pki-types",
|
| 711 |
+
"slab",
|
| 712 |
+
"thiserror",
|
| 713 |
+
"tinyvec",
|
| 714 |
+
"tracing",
|
| 715 |
+
"web-time",
|
| 716 |
+
]
|
| 717 |
+
|
| 718 |
+
[[package]]
|
| 719 |
+
name = "quinn-udp"
|
| 720 |
+
version = "0.5.16"
|
| 721 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 722 |
+
checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016"
|
| 723 |
+
dependencies = [
|
| 724 |
+
"cfg_aliases",
|
| 725 |
+
"libc",
|
| 726 |
+
"once_cell",
|
| 727 |
+
"socket2",
|
| 728 |
+
"tracing",
|
| 729 |
+
"windows-sys 0.61.2",
|
| 730 |
+
]
|
| 731 |
+
|
| 732 |
+
[[package]]
|
| 733 |
+
name = "quote"
|
| 734 |
+
version = "1.0.47"
|
| 735 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 736 |
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
| 737 |
+
dependencies = [
|
| 738 |
+
"proc-macro2",
|
| 739 |
+
]
|
| 740 |
+
|
| 741 |
+
[[package]]
|
| 742 |
+
name = "r-efi"
|
| 743 |
+
version = "6.0.0"
|
| 744 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 745 |
+
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
| 746 |
+
|
| 747 |
+
[[package]]
|
| 748 |
+
name = "rand"
|
| 749 |
+
version = "0.10.3"
|
| 750 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 751 |
+
checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
|
| 752 |
+
dependencies = [
|
| 753 |
+
"chacha20",
|
| 754 |
+
"getrandom 0.4.3",
|
| 755 |
+
"rand_core",
|
| 756 |
+
]
|
| 757 |
+
|
| 758 |
+
[[package]]
|
| 759 |
+
name = "rand_core"
|
| 760 |
+
version = "0.10.1"
|
| 761 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 762 |
+
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
| 763 |
+
|
| 764 |
+
[[package]]
|
| 765 |
+
name = "rand_pcg"
|
| 766 |
+
version = "0.10.2"
|
| 767 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 768 |
+
checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
|
| 769 |
+
dependencies = [
|
| 770 |
+
"rand_core",
|
| 771 |
+
]
|
| 772 |
+
|
| 773 |
+
[[package]]
|
| 774 |
+
name = "redox_syscall"
|
| 775 |
+
version = "0.5.18"
|
| 776 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 777 |
+
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
|
| 778 |
+
dependencies = [
|
| 779 |
+
"bitflags",
|
| 780 |
+
]
|
| 781 |
+
|
| 782 |
+
[[package]]
|
| 783 |
+
name = "regex-automata"
|
| 784 |
+
version = "0.4.18"
|
| 785 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 786 |
+
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
|
| 787 |
+
dependencies = [
|
| 788 |
+
"aho-corasick",
|
| 789 |
+
"memchr",
|
| 790 |
+
"regex-syntax",
|
| 791 |
+
]
|
| 792 |
+
|
| 793 |
+
[[package]]
|
| 794 |
+
name = "regex-syntax"
|
| 795 |
+
version = "0.8.11"
|
| 796 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 797 |
+
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
| 798 |
+
|
| 799 |
+
[[package]]
|
| 800 |
+
name = "reqwest"
|
| 801 |
+
version = "0.12.28"
|
| 802 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 803 |
+
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
|
| 804 |
+
dependencies = [
|
| 805 |
+
"base64 0.22.1",
|
| 806 |
+
"bytes",
|
| 807 |
+
"futures-core",
|
| 808 |
+
"http",
|
| 809 |
+
"http-body",
|
| 810 |
+
"http-body-util",
|
| 811 |
+
"hyper",
|
| 812 |
+
"hyper-rustls",
|
| 813 |
+
"hyper-util",
|
| 814 |
+
"js-sys",
|
| 815 |
+
"log",
|
| 816 |
+
"percent-encoding",
|
| 817 |
+
"pin-project-lite",
|
| 818 |
+
"quinn",
|
| 819 |
+
"rustls",
|
| 820 |
+
"rustls-pki-types",
|
| 821 |
+
"serde",
|
| 822 |
+
"serde_json",
|
| 823 |
+
"serde_urlencoded",
|
| 824 |
+
"sync_wrapper",
|
| 825 |
+
"tokio",
|
| 826 |
+
"tokio-rustls",
|
| 827 |
+
"tower 0.5.3",
|
| 828 |
+
"tower-http",
|
| 829 |
+
"tower-service",
|
| 830 |
+
"url",
|
| 831 |
+
"wasm-bindgen",
|
| 832 |
+
"wasm-bindgen-futures",
|
| 833 |
+
"web-sys",
|
| 834 |
+
"webpki-roots",
|
| 835 |
+
]
|
| 836 |
+
|
| 837 |
+
[[package]]
|
| 838 |
+
name = "ring"
|
| 839 |
+
version = "0.17.14"
|
| 840 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 841 |
+
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
|
| 842 |
+
dependencies = [
|
| 843 |
+
"cc",
|
| 844 |
+
"cfg-if",
|
| 845 |
+
"getrandom 0.2.17",
|
| 846 |
+
"libc",
|
| 847 |
+
"untrusted",
|
| 848 |
+
"windows-sys 0.52.0",
|
| 849 |
+
]
|
| 850 |
+
|
| 851 |
+
[[package]]
|
| 852 |
+
name = "rustc-hash"
|
| 853 |
+
version = "2.1.3"
|
| 854 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 855 |
+
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
|
| 856 |
+
|
| 857 |
+
[[package]]
|
| 858 |
+
name = "rustls"
|
| 859 |
+
version = "0.23.46"
|
| 860 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 861 |
+
checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
|
| 862 |
+
dependencies = [
|
| 863 |
+
"once_cell",
|
| 864 |
+
"ring",
|
| 865 |
+
"rustls-pki-types",
|
| 866 |
+
"rustls-webpki",
|
| 867 |
+
"subtle",
|
| 868 |
+
"zeroize",
|
| 869 |
+
]
|
| 870 |
+
|
| 871 |
+
[[package]]
|
| 872 |
+
name = "rustls-pki-types"
|
| 873 |
+
version = "1.15.1"
|
| 874 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 875 |
+
checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
|
| 876 |
+
dependencies = [
|
| 877 |
+
"web-time",
|
| 878 |
+
"zeroize",
|
| 879 |
+
]
|
| 880 |
+
|
| 881 |
+
[[package]]
|
| 882 |
+
name = "rustls-webpki"
|
| 883 |
+
version = "0.103.15"
|
| 884 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 885 |
+
checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
|
| 886 |
+
dependencies = [
|
| 887 |
+
"ring",
|
| 888 |
+
"rustls-pki-types",
|
| 889 |
+
"untrusted",
|
| 890 |
+
]
|
| 891 |
+
|
| 892 |
+
[[package]]
|
| 893 |
+
name = "rustversion"
|
| 894 |
+
version = "1.0.23"
|
| 895 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 896 |
+
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
| 897 |
+
|
| 898 |
+
[[package]]
|
| 899 |
+
name = "ryu"
|
| 900 |
+
version = "1.0.23"
|
| 901 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 902 |
+
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
| 903 |
+
|
| 904 |
+
[[package]]
|
| 905 |
+
name = "scopeguard"
|
| 906 |
+
version = "1.2.0"
|
| 907 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 908 |
+
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
| 909 |
+
|
| 910 |
+
[[package]]
|
| 911 |
+
name = "serde"
|
| 912 |
+
version = "1.0.229"
|
| 913 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 914 |
+
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
| 915 |
+
dependencies = [
|
| 916 |
+
"serde_core",
|
| 917 |
+
]
|
| 918 |
+
|
| 919 |
+
[[package]]
|
| 920 |
+
name = "serde_core"
|
| 921 |
+
version = "1.0.229"
|
| 922 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 923 |
+
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
| 924 |
+
dependencies = [
|
| 925 |
+
"serde_derive",
|
| 926 |
+
]
|
| 927 |
+
|
| 928 |
+
[[package]]
|
| 929 |
+
name = "serde_derive"
|
| 930 |
+
version = "1.0.229"
|
| 931 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 932 |
+
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
| 933 |
+
dependencies = [
|
| 934 |
+
"proc-macro2",
|
| 935 |
+
"quote",
|
| 936 |
+
"syn 3.0.9",
|
| 937 |
+
]
|
| 938 |
+
|
| 939 |
+
[[package]]
|
| 940 |
+
name = "serde_json"
|
| 941 |
+
version = "1.0.154"
|
| 942 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 943 |
+
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
| 944 |
+
dependencies = [
|
| 945 |
+
"itoa",
|
| 946 |
+
"memchr",
|
| 947 |
+
"serde",
|
| 948 |
+
"serde_core",
|
| 949 |
+
"zmij",
|
| 950 |
+
]
|
| 951 |
+
|
| 952 |
+
[[package]]
|
| 953 |
+
name = "serde_path_to_error"
|
| 954 |
+
version = "0.1.20"
|
| 955 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 956 |
+
checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457"
|
| 957 |
+
dependencies = [
|
| 958 |
+
"itoa",
|
| 959 |
+
"serde",
|
| 960 |
+
"serde_core",
|
| 961 |
+
]
|
| 962 |
+
|
| 963 |
+
[[package]]
|
| 964 |
+
name = "serde_urlencoded"
|
| 965 |
+
version = "0.7.1"
|
| 966 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 967 |
+
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
| 968 |
+
dependencies = [
|
| 969 |
+
"form_urlencoded",
|
| 970 |
+
"itoa",
|
| 971 |
+
"ryu",
|
| 972 |
+
"serde",
|
| 973 |
+
]
|
| 974 |
+
|
| 975 |
+
[[package]]
|
| 976 |
+
name = "sharded-slab"
|
| 977 |
+
version = "0.1.7"
|
| 978 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 979 |
+
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
|
| 980 |
+
dependencies = [
|
| 981 |
+
"lazy_static",
|
| 982 |
+
]
|
| 983 |
+
|
| 984 |
+
[[package]]
|
| 985 |
+
name = "shlex"
|
| 986 |
+
version = "2.0.1"
|
| 987 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 988 |
+
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
| 989 |
+
|
| 990 |
+
[[package]]
|
| 991 |
+
name = "signal-hook-registry"
|
| 992 |
+
version = "1.4.8"
|
| 993 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 994 |
+
checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
|
| 995 |
+
dependencies = [
|
| 996 |
+
"errno",
|
| 997 |
+
"libc",
|
| 998 |
+
]
|
| 999 |
+
|
| 1000 |
+
[[package]]
|
| 1001 |
+
name = "slab"
|
| 1002 |
+
version = "0.4.12"
|
| 1003 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1004 |
+
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
| 1005 |
+
|
| 1006 |
+
[[package]]
|
| 1007 |
+
name = "smallvec"
|
| 1008 |
+
version = "1.16.3"
|
| 1009 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1010 |
+
checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b"
|
| 1011 |
+
|
| 1012 |
+
[[package]]
|
| 1013 |
+
name = "socket2"
|
| 1014 |
+
version = "0.6.5"
|
| 1015 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1016 |
+
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
|
| 1017 |
+
dependencies = [
|
| 1018 |
+
"libc",
|
| 1019 |
+
"windows-sys 0.61.2",
|
| 1020 |
+
]
|
| 1021 |
+
|
| 1022 |
+
[[package]]
|
| 1023 |
+
name = "stable_deref_trait"
|
| 1024 |
+
version = "1.2.1"
|
| 1025 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1026 |
+
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
| 1027 |
+
|
| 1028 |
+
[[package]]
|
| 1029 |
+
name = "subtle"
|
| 1030 |
+
version = "2.6.1"
|
| 1031 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1032 |
+
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
| 1033 |
+
|
| 1034 |
+
[[package]]
|
| 1035 |
+
name = "syn"
|
| 1036 |
+
version = "2.0.119"
|
| 1037 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1038 |
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
| 1039 |
+
dependencies = [
|
| 1040 |
+
"proc-macro2",
|
| 1041 |
+
"quote",
|
| 1042 |
+
"unicode-ident",
|
| 1043 |
+
]
|
| 1044 |
+
|
| 1045 |
+
[[package]]
|
| 1046 |
+
name = "syn"
|
| 1047 |
+
version = "3.0.9"
|
| 1048 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1049 |
+
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
| 1050 |
+
dependencies = [
|
| 1051 |
+
"proc-macro2",
|
| 1052 |
+
"quote",
|
| 1053 |
+
"unicode-ident",
|
| 1054 |
+
]
|
| 1055 |
+
|
| 1056 |
+
[[package]]
|
| 1057 |
+
name = "sync_wrapper"
|
| 1058 |
+
version = "1.0.2"
|
| 1059 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1060 |
+
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
|
| 1061 |
+
dependencies = [
|
| 1062 |
+
"futures-core",
|
| 1063 |
+
]
|
| 1064 |
+
|
| 1065 |
+
[[package]]
|
| 1066 |
+
name = "synstructure"
|
| 1067 |
+
version = "0.14.0"
|
| 1068 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1069 |
+
checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02"
|
| 1070 |
+
dependencies = [
|
| 1071 |
+
"proc-macro2",
|
| 1072 |
+
"quote",
|
| 1073 |
+
"syn 3.0.9",
|
| 1074 |
+
]
|
| 1075 |
+
|
| 1076 |
+
[[package]]
|
| 1077 |
+
name = "thiserror"
|
| 1078 |
+
version = "2.0.21"
|
| 1079 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1080 |
+
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
|
| 1081 |
+
dependencies = [
|
| 1082 |
+
"thiserror-impl",
|
| 1083 |
+
]
|
| 1084 |
+
|
| 1085 |
+
[[package]]
|
| 1086 |
+
name = "thiserror-impl"
|
| 1087 |
+
version = "2.0.21"
|
| 1088 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1089 |
+
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
|
| 1090 |
+
dependencies = [
|
| 1091 |
+
"proc-macro2",
|
| 1092 |
+
"quote",
|
| 1093 |
+
"syn 3.0.9",
|
| 1094 |
+
]
|
| 1095 |
+
|
| 1096 |
+
[[package]]
|
| 1097 |
+
name = "thread_local"
|
| 1098 |
+
version = "1.1.10"
|
| 1099 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1100 |
+
checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070"
|
| 1101 |
+
dependencies = [
|
| 1102 |
+
"cfg-if",
|
| 1103 |
+
]
|
| 1104 |
+
|
| 1105 |
+
[[package]]
|
| 1106 |
+
name = "tinystr"
|
| 1107 |
+
version = "0.8.4"
|
| 1108 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1109 |
+
checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643"
|
| 1110 |
+
dependencies = [
|
| 1111 |
+
"displaydoc",
|
| 1112 |
+
"zerovec",
|
| 1113 |
+
]
|
| 1114 |
+
|
| 1115 |
+
[[package]]
|
| 1116 |
+
name = "tinyvec"
|
| 1117 |
+
version = "1.13.3"
|
| 1118 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1119 |
+
checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee"
|
| 1120 |
+
|
| 1121 |
+
[[package]]
|
| 1122 |
+
name = "tokio"
|
| 1123 |
+
version = "1.53.3"
|
| 1124 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1125 |
+
checksum = "ce3335fa71841cda333a58d7615b03901380ecf09d59b3296d21f8bbac0dde4e"
|
| 1126 |
+
dependencies = [
|
| 1127 |
+
"bytes",
|
| 1128 |
+
"libc",
|
| 1129 |
+
"mio",
|
| 1130 |
+
"parking_lot",
|
| 1131 |
+
"pin-project-lite",
|
| 1132 |
+
"signal-hook-registry",
|
| 1133 |
+
"socket2",
|
| 1134 |
+
"tokio-macros",
|
| 1135 |
+
"windows-sys 0.61.2",
|
| 1136 |
+
]
|
| 1137 |
+
|
| 1138 |
+
[[package]]
|
| 1139 |
+
name = "tokio-macros"
|
| 1140 |
+
version = "2.7.2"
|
| 1141 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1142 |
+
checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
|
| 1143 |
+
dependencies = [
|
| 1144 |
+
"proc-macro2",
|
| 1145 |
+
"quote",
|
| 1146 |
+
"syn 3.0.9",
|
| 1147 |
+
]
|
| 1148 |
+
|
| 1149 |
+
[[package]]
|
| 1150 |
+
name = "tokio-rustls"
|
| 1151 |
+
version = "0.26.6"
|
| 1152 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1153 |
+
checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db"
|
| 1154 |
+
dependencies = [
|
| 1155 |
+
"rustls",
|
| 1156 |
+
"tokio",
|
| 1157 |
+
]
|
| 1158 |
+
|
| 1159 |
+
[[package]]
|
| 1160 |
+
name = "tower"
|
| 1161 |
+
version = "0.4.13"
|
| 1162 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1163 |
+
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
|
| 1164 |
+
dependencies = [
|
| 1165 |
+
"futures-core",
|
| 1166 |
+
"futures-util",
|
| 1167 |
+
"pin-project",
|
| 1168 |
+
"pin-project-lite",
|
| 1169 |
+
"tower-layer",
|
| 1170 |
+
"tower-service",
|
| 1171 |
+
"tracing",
|
| 1172 |
+
]
|
| 1173 |
+
|
| 1174 |
+
[[package]]
|
| 1175 |
+
name = "tower"
|
| 1176 |
+
version = "0.5.3"
|
| 1177 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1178 |
+
checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
|
| 1179 |
+
dependencies = [
|
| 1180 |
+
"futures-core",
|
| 1181 |
+
"futures-util",
|
| 1182 |
+
"pin-project-lite",
|
| 1183 |
+
"sync_wrapper",
|
| 1184 |
+
"tokio",
|
| 1185 |
+
"tower-layer",
|
| 1186 |
+
"tower-service",
|
| 1187 |
+
"tracing",
|
| 1188 |
+
]
|
| 1189 |
+
|
| 1190 |
+
[[package]]
|
| 1191 |
+
name = "tower-http"
|
| 1192 |
+
version = "0.6.11"
|
| 1193 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1194 |
+
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
|
| 1195 |
+
dependencies = [
|
| 1196 |
+
"bitflags",
|
| 1197 |
+
"bytes",
|
| 1198 |
+
"futures-util",
|
| 1199 |
+
"http",
|
| 1200 |
+
"http-body",
|
| 1201 |
+
"pin-project-lite",
|
| 1202 |
+
"tower 0.5.3",
|
| 1203 |
+
"tower-layer",
|
| 1204 |
+
"tower-service",
|
| 1205 |
+
"url",
|
| 1206 |
+
]
|
| 1207 |
+
|
| 1208 |
+
[[package]]
|
| 1209 |
+
name = "tower-layer"
|
| 1210 |
+
version = "0.3.3"
|
| 1211 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1212 |
+
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
|
| 1213 |
+
|
| 1214 |
+
[[package]]
|
| 1215 |
+
name = "tower-service"
|
| 1216 |
+
version = "0.3.3"
|
| 1217 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1218 |
+
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
| 1219 |
+
|
| 1220 |
+
[[package]]
|
| 1221 |
+
name = "tracing"
|
| 1222 |
+
version = "0.1.44"
|
| 1223 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1224 |
+
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
| 1225 |
+
dependencies = [
|
| 1226 |
+
"log",
|
| 1227 |
+
"pin-project-lite",
|
| 1228 |
+
"tracing-attributes",
|
| 1229 |
+
"tracing-core",
|
| 1230 |
+
]
|
| 1231 |
+
|
| 1232 |
+
[[package]]
|
| 1233 |
+
name = "tracing-attributes"
|
| 1234 |
+
version = "0.1.31"
|
| 1235 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1236 |
+
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
|
| 1237 |
+
dependencies = [
|
| 1238 |
+
"proc-macro2",
|
| 1239 |
+
"quote",
|
| 1240 |
+
"syn 2.0.119",
|
| 1241 |
+
]
|
| 1242 |
+
|
| 1243 |
+
[[package]]
|
| 1244 |
+
name = "tracing-core"
|
| 1245 |
+
version = "0.1.36"
|
| 1246 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1247 |
+
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
|
| 1248 |
+
dependencies = [
|
| 1249 |
+
"once_cell",
|
| 1250 |
+
"valuable",
|
| 1251 |
+
]
|
| 1252 |
+
|
| 1253 |
+
[[package]]
|
| 1254 |
+
name = "tracing-log"
|
| 1255 |
+
version = "0.2.0"
|
| 1256 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1257 |
+
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
| 1258 |
+
dependencies = [
|
| 1259 |
+
"log",
|
| 1260 |
+
"once_cell",
|
| 1261 |
+
"tracing-core",
|
| 1262 |
+
]
|
| 1263 |
+
|
| 1264 |
+
[[package]]
|
| 1265 |
+
name = "tracing-subscriber"
|
| 1266 |
+
version = "0.3.23"
|
| 1267 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1268 |
+
checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319"
|
| 1269 |
+
dependencies = [
|
| 1270 |
+
"matchers",
|
| 1271 |
+
"nu-ansi-term",
|
| 1272 |
+
"once_cell",
|
| 1273 |
+
"regex-automata",
|
| 1274 |
+
"sharded-slab",
|
| 1275 |
+
"smallvec",
|
| 1276 |
+
"thread_local",
|
| 1277 |
+
"tracing",
|
| 1278 |
+
"tracing-core",
|
| 1279 |
+
"tracing-log",
|
| 1280 |
+
]
|
| 1281 |
+
|
| 1282 |
+
[[package]]
|
| 1283 |
+
name = "try-lock"
|
| 1284 |
+
version = "0.2.5"
|
| 1285 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1286 |
+
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
| 1287 |
+
|
| 1288 |
+
[[package]]
|
| 1289 |
+
name = "unicode-ident"
|
| 1290 |
+
version = "1.0.27"
|
| 1291 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1292 |
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
| 1293 |
+
|
| 1294 |
+
[[package]]
|
| 1295 |
+
name = "untrusted"
|
| 1296 |
+
version = "0.9.0"
|
| 1297 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1298 |
+
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
| 1299 |
+
|
| 1300 |
+
[[package]]
|
| 1301 |
+
name = "url"
|
| 1302 |
+
version = "2.5.8"
|
| 1303 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1304 |
+
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
| 1305 |
+
dependencies = [
|
| 1306 |
+
"form_urlencoded",
|
| 1307 |
+
"idna",
|
| 1308 |
+
"percent-encoding",
|
| 1309 |
+
"serde",
|
| 1310 |
+
]
|
| 1311 |
+
|
| 1312 |
+
[[package]]
|
| 1313 |
+
name = "utf8_iter"
|
| 1314 |
+
version = "1.0.4"
|
| 1315 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1316 |
+
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
| 1317 |
+
|
| 1318 |
+
[[package]]
|
| 1319 |
+
name = "uuid"
|
| 1320 |
+
version = "1.28.0"
|
| 1321 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1322 |
+
checksum = "7cc1186384beb7dd8eedea376413fd654937285ea6c9cfbb928dc3043ea4b606"
|
| 1323 |
+
dependencies = [
|
| 1324 |
+
"getrandom 0.4.3",
|
| 1325 |
+
"js-sys",
|
| 1326 |
+
"wasm-bindgen",
|
| 1327 |
+
]
|
| 1328 |
+
|
| 1329 |
+
[[package]]
|
| 1330 |
+
name = "valuable"
|
| 1331 |
+
version = "0.1.1"
|
| 1332 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1333 |
+
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
| 1334 |
+
|
| 1335 |
+
[[package]]
|
| 1336 |
+
name = "want"
|
| 1337 |
+
version = "0.3.2"
|
| 1338 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1339 |
+
checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b"
|
| 1340 |
+
dependencies = [
|
| 1341 |
+
"try-lock",
|
| 1342 |
+
]
|
| 1343 |
+
|
| 1344 |
+
[[package]]
|
| 1345 |
+
name = "wasi"
|
| 1346 |
+
version = "0.11.1+wasi-snapshot-preview1"
|
| 1347 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1348 |
+
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
| 1349 |
+
|
| 1350 |
+
[[package]]
|
| 1351 |
+
name = "wasm-bindgen"
|
| 1352 |
+
version = "0.2.129"
|
| 1353 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1354 |
+
checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409"
|
| 1355 |
+
dependencies = [
|
| 1356 |
+
"cfg-if",
|
| 1357 |
+
"once_cell",
|
| 1358 |
+
"rustversion",
|
| 1359 |
+
"wasm-bindgen-macro",
|
| 1360 |
+
"wasm-bindgen-shared",
|
| 1361 |
+
]
|
| 1362 |
+
|
| 1363 |
+
[[package]]
|
| 1364 |
+
name = "wasm-bindgen-futures"
|
| 1365 |
+
version = "0.4.79"
|
| 1366 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1367 |
+
checksum = "3cbab34de2d982e9b48e18d216d04c4a6f641066ff19ffb699980f591ee3610e"
|
| 1368 |
+
dependencies = [
|
| 1369 |
+
"js-sys",
|
| 1370 |
+
"tokio",
|
| 1371 |
+
"wasm-bindgen",
|
| 1372 |
+
]
|
| 1373 |
+
|
| 1374 |
+
[[package]]
|
| 1375 |
+
name = "wasm-bindgen-macro"
|
| 1376 |
+
version = "0.2.129"
|
| 1377 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1378 |
+
checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535"
|
| 1379 |
+
dependencies = [
|
| 1380 |
+
"quote",
|
| 1381 |
+
"wasm-bindgen-macro-support",
|
| 1382 |
+
]
|
| 1383 |
+
|
| 1384 |
+
[[package]]
|
| 1385 |
+
name = "wasm-bindgen-macro-support"
|
| 1386 |
+
version = "0.2.129"
|
| 1387 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1388 |
+
checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7"
|
| 1389 |
+
dependencies = [
|
| 1390 |
+
"bumpalo",
|
| 1391 |
+
"proc-macro2",
|
| 1392 |
+
"quote",
|
| 1393 |
+
"syn 3.0.9",
|
| 1394 |
+
"wasm-bindgen-shared",
|
| 1395 |
+
]
|
| 1396 |
+
|
| 1397 |
+
[[package]]
|
| 1398 |
+
name = "wasm-bindgen-shared"
|
| 1399 |
+
version = "0.2.129"
|
| 1400 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1401 |
+
checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6"
|
| 1402 |
+
dependencies = [
|
| 1403 |
+
"unicode-ident",
|
| 1404 |
+
]
|
| 1405 |
+
|
| 1406 |
+
[[package]]
|
| 1407 |
+
name = "web-sys"
|
| 1408 |
+
version = "0.3.106"
|
| 1409 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1410 |
+
checksum = "88261b9deccee56594c11a3460c462c41f58d148598fe70ad77070126a68aba4"
|
| 1411 |
+
dependencies = [
|
| 1412 |
+
"js-sys",
|
| 1413 |
+
"wasm-bindgen",
|
| 1414 |
+
]
|
| 1415 |
+
|
| 1416 |
+
[[package]]
|
| 1417 |
+
name = "web-time"
|
| 1418 |
+
version = "1.1.0"
|
| 1419 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1420 |
+
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
|
| 1421 |
+
dependencies = [
|
| 1422 |
+
"js-sys",
|
| 1423 |
+
"wasm-bindgen",
|
| 1424 |
+
]
|
| 1425 |
+
|
| 1426 |
+
[[package]]
|
| 1427 |
+
name = "webpki-roots"
|
| 1428 |
+
version = "1.0.9"
|
| 1429 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1430 |
+
checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"
|
| 1431 |
+
dependencies = [
|
| 1432 |
+
"rustls-pki-types",
|
| 1433 |
+
]
|
| 1434 |
+
|
| 1435 |
+
[[package]]
|
| 1436 |
+
name = "windows-link"
|
| 1437 |
+
version = "0.2.1"
|
| 1438 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1439 |
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
| 1440 |
+
|
| 1441 |
+
[[package]]
|
| 1442 |
+
name = "windows-sys"
|
| 1443 |
+
version = "0.52.0"
|
| 1444 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1445 |
+
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
| 1446 |
+
dependencies = [
|
| 1447 |
+
"windows-targets",
|
| 1448 |
+
]
|
| 1449 |
+
|
| 1450 |
+
[[package]]
|
| 1451 |
+
name = "windows-sys"
|
| 1452 |
+
version = "0.61.2"
|
| 1453 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1454 |
+
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
| 1455 |
+
dependencies = [
|
| 1456 |
+
"windows-link",
|
| 1457 |
+
]
|
| 1458 |
+
|
| 1459 |
+
[[package]]
|
| 1460 |
+
name = "windows-targets"
|
| 1461 |
+
version = "0.52.6"
|
| 1462 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1463 |
+
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
| 1464 |
+
dependencies = [
|
| 1465 |
+
"windows_aarch64_gnullvm",
|
| 1466 |
+
"windows_aarch64_msvc",
|
| 1467 |
+
"windows_i686_gnu",
|
| 1468 |
+
"windows_i686_gnullvm",
|
| 1469 |
+
"windows_i686_msvc",
|
| 1470 |
+
"windows_x86_64_gnu",
|
| 1471 |
+
"windows_x86_64_gnullvm",
|
| 1472 |
+
"windows_x86_64_msvc",
|
| 1473 |
+
]
|
| 1474 |
+
|
| 1475 |
+
[[package]]
|
| 1476 |
+
name = "windows_aarch64_gnullvm"
|
| 1477 |
+
version = "0.52.6"
|
| 1478 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1479 |
+
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
| 1480 |
+
|
| 1481 |
+
[[package]]
|
| 1482 |
+
name = "windows_aarch64_msvc"
|
| 1483 |
+
version = "0.52.6"
|
| 1484 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1485 |
+
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
| 1486 |
+
|
| 1487 |
+
[[package]]
|
| 1488 |
+
name = "windows_i686_gnu"
|
| 1489 |
+
version = "0.52.6"
|
| 1490 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1491 |
+
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
| 1492 |
+
|
| 1493 |
+
[[package]]
|
| 1494 |
+
name = "windows_i686_gnullvm"
|
| 1495 |
+
version = "0.52.6"
|
| 1496 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1497 |
+
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
| 1498 |
+
|
| 1499 |
+
[[package]]
|
| 1500 |
+
name = "windows_i686_msvc"
|
| 1501 |
+
version = "0.52.6"
|
| 1502 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1503 |
+
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
| 1504 |
+
|
| 1505 |
+
[[package]]
|
| 1506 |
+
name = "windows_x86_64_gnu"
|
| 1507 |
+
version = "0.52.6"
|
| 1508 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1509 |
+
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
| 1510 |
+
|
| 1511 |
+
[[package]]
|
| 1512 |
+
name = "windows_x86_64_gnullvm"
|
| 1513 |
+
version = "0.52.6"
|
| 1514 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1515 |
+
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
| 1516 |
+
|
| 1517 |
+
[[package]]
|
| 1518 |
+
name = "windows_x86_64_msvc"
|
| 1519 |
+
version = "0.52.6"
|
| 1520 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1521 |
+
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
| 1522 |
+
|
| 1523 |
+
[[package]]
|
| 1524 |
+
name = "writeable"
|
| 1525 |
+
version = "0.6.4"
|
| 1526 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1527 |
+
checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
|
| 1528 |
+
|
| 1529 |
+
[[package]]
|
| 1530 |
+
name = "yoke"
|
| 1531 |
+
version = "0.8.3"
|
| 1532 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1533 |
+
checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5"
|
| 1534 |
+
dependencies = [
|
| 1535 |
+
"stable_deref_trait",
|
| 1536 |
+
"yoke-derive",
|
| 1537 |
+
"zerofrom",
|
| 1538 |
+
]
|
| 1539 |
+
|
| 1540 |
+
[[package]]
|
| 1541 |
+
name = "yoke-derive"
|
| 1542 |
+
version = "0.8.4"
|
| 1543 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1544 |
+
checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71"
|
| 1545 |
+
dependencies = [
|
| 1546 |
+
"proc-macro2",
|
| 1547 |
+
"quote",
|
| 1548 |
+
"syn 3.0.9",
|
| 1549 |
+
"synstructure",
|
| 1550 |
+
]
|
| 1551 |
+
|
| 1552 |
+
[[package]]
|
| 1553 |
+
name = "zerofrom"
|
| 1554 |
+
version = "0.1.8"
|
| 1555 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1556 |
+
checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"
|
| 1557 |
+
dependencies = [
|
| 1558 |
+
"zerofrom-derive",
|
| 1559 |
+
]
|
| 1560 |
+
|
| 1561 |
+
[[package]]
|
| 1562 |
+
name = "zerofrom-derive"
|
| 1563 |
+
version = "0.1.8"
|
| 1564 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1565 |
+
checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a"
|
| 1566 |
+
dependencies = [
|
| 1567 |
+
"proc-macro2",
|
| 1568 |
+
"quote",
|
| 1569 |
+
"syn 3.0.9",
|
| 1570 |
+
"synstructure",
|
| 1571 |
+
]
|
| 1572 |
+
|
| 1573 |
+
[[package]]
|
| 1574 |
+
name = "zeroize"
|
| 1575 |
+
version = "1.9.1"
|
| 1576 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1577 |
+
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
|
| 1578 |
+
|
| 1579 |
+
[[package]]
|
| 1580 |
+
name = "zerotrie"
|
| 1581 |
+
version = "0.2.5"
|
| 1582 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1583 |
+
checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f"
|
| 1584 |
+
dependencies = [
|
| 1585 |
+
"displaydoc",
|
| 1586 |
+
"yoke",
|
| 1587 |
+
"zerofrom",
|
| 1588 |
+
]
|
| 1589 |
+
|
| 1590 |
+
[[package]]
|
| 1591 |
+
name = "zerovec"
|
| 1592 |
+
version = "0.11.8"
|
| 1593 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1594 |
+
checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8"
|
| 1595 |
+
dependencies = [
|
| 1596 |
+
"yoke",
|
| 1597 |
+
"zerofrom",
|
| 1598 |
+
"zerovec-derive",
|
| 1599 |
+
]
|
| 1600 |
+
|
| 1601 |
+
[[package]]
|
| 1602 |
+
name = "zerovec-derive"
|
| 1603 |
+
version = "0.11.6"
|
| 1604 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1605 |
+
checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da"
|
| 1606 |
+
dependencies = [
|
| 1607 |
+
"proc-macro2",
|
| 1608 |
+
"quote",
|
| 1609 |
+
"syn 3.0.9",
|
| 1610 |
+
]
|
| 1611 |
+
|
| 1612 |
+
[[package]]
|
| 1613 |
+
name = "zlib-rs"
|
| 1614 |
+
version = "0.6.8"
|
| 1615 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1616 |
+
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
|
| 1617 |
+
|
| 1618 |
+
[[package]]
|
| 1619 |
+
name = "zmij"
|
| 1620 |
+
version = "1.0.23"
|
| 1621 |
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
| 1622 |
+
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
src/Cargo.toml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[package]
|
| 2 |
+
name = "litematic-host"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
edition = "2021"
|
| 5 |
+
|
| 6 |
+
[dependencies]
|
| 7 |
+
axum = "0.7"
|
| 8 |
+
tokio = { version = "1", features = ["full"] }
|
| 9 |
+
serde_json = "1"
|
| 10 |
+
uuid = { version = "1", features = ["v4"] }
|
| 11 |
+
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
|
| 12 |
+
flate2 = { version = "1.1", default-features = false, features = ["zlib-rs"] }
|
| 13 |
+
tracing = "0.1"
|
| 14 |
+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
| 15 |
+
|
| 16 |
+
[dev-dependencies]
|
| 17 |
+
tower = { version = "0.4", features = ["util"] }
|
| 18 |
+
http-body-util = "0.1"
|
| 19 |
+
|
| 20 |
+
[profile.release]
|
| 21 |
+
opt-level = 3
|
| 22 |
+
lto = true
|
| 23 |
+
codegen-units = 1
|
| 24 |
+
strip = true
|
src/Dockerfile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- сборка ---
|
| 2 |
+
FROM rust:1-bookworm AS build
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
# кэш зависимостей
|
| 5 |
+
COPY Cargo.toml Cargo.lock* ./
|
| 6 |
+
RUN mkdir src && echo "fn main() {}" > src/main.rs \
|
| 7 |
+
&& cargo build --release \
|
| 8 |
+
&& rm -rf src
|
| 9 |
+
COPY src ./src
|
| 10 |
+
RUN touch src/main.rs && cargo build --release
|
| 11 |
+
|
| 12 |
+
# --- рантайм ---
|
| 13 |
+
FROM debian:bookworm-slim
|
| 14 |
+
RUN apt-get update \
|
| 15 |
+
&& apt-get install -y --no-install-recommends ca-certificates \
|
| 16 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 17 |
+
&& useradd -m -u 1000 user
|
| 18 |
+
COPY --from=build /app/target/release/litematic-host /usr/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Litematic Host
|
| 3 |
+
emoji: 🧱
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# litematic-host
|
| 12 |
+
|
| 13 |
+
HTTP-сервис на Rust. Скачивает `.litematic` по прямой ссылке, разбирает блоки и NBT и отдаёт
|
| 14 |
+
их текстом из ячеек по 28 символов, нарезанным на части. Рассчитан на клиента с таймаутом
|
| 15 |
+
3 секунды.
|
| 16 |
+
|
| 17 |
+
Слушает `0.0.0.0:7860` (переменная `PORT`). Логи — `tracing`, уровень через `RUST_LOG`.
|
| 18 |
+
|
| 19 |
+
## Запуск
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
cargo test
|
| 23 |
+
cargo run --release
|
| 24 |
+
|
| 25 |
+
docker build -t litematic-host .
|
| 26 |
+
docker run --rm -p 7860:7860 litematic-host
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Hugging Face Spaces: Space с SDK **Docker**, залей содержимое проекта. YAML-шапка этого
|
| 30 |
+
файла уже настроена (`sdk: docker`, `app_port: 7860`).
|
| 31 |
+
|
| 32 |
+
## Эндпоинты
|
| 33 |
+
|
| 34 |
+
Все ответы — `application/json`. Ошибки: `{"error": "текст"}`.
|
| 35 |
+
|
| 36 |
+
| Метод | Путь | Ответ |
|
| 37 |
+
|---|---|---|
|
| 38 |
+
| POST | `/upload?x=0&y=0&z=0` | UUID строкой: `"3f2a…"`. Тело — ссылка на `.litematic`. `x`, `y`, `z` — необязательный сдвиг, целые числа, по умолчанию 0 |
|
| 39 |
+
| GET | `/get/{uuid}/blocks` | `{"unique_blocks": N, "parts": K}` |
|
| 40 |
+
| GET | `/get/{uuid}/blocks/{index}` | `{"index": i, "blocks": {"0000": "dirt", …}}` |
|
| 41 |
+
| GET | `/get/{uuid}/nbt` | `{"unique_nbt": N, "parts": K}` |
|
| 42 |
+
| GET | `/get/{uuid}/nbt/{index}` | `{"index": i, "nbt": {"0001": "{id:\"minecraft:chest\"}", …}}` |
|
| 43 |
+
| GET | `/get/{uuid}/parts` | `{"parts": K}` |
|
| 44 |
+
| GET | `/get/{uuid}/parts/{index}` | `{"index": i, "data": "<до 23 996 символов>"}` |
|
| 45 |
+
| GET | `/{uuid}/status` (то же: `/get/{uuid}/status`) | `{"status": "ready", "unique_blocks": N, "unique_nbt": M, "blocks_parts": K, "nbt_parts": L, "parts": P, "text_chars": T}` |
|
| 46 |
+
|
| 47 |
+
Коды: `400` — некорректный UUID или индекс (не число), плохая ссылка, ошибка загрузки,
|
| 48 |
+
файл не `.litematic` или битый, превышен лимит или срок. `404` — UUID не найден, индекс
|
| 49 |
+
вне диапазона. Индексы с нуля. JSON каждой части словаря ≤ 24 000 символов.
|
| 50 |
+
|
| 51 |
+
### Пример
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
# сдвиг (100, 64, -20) сервер прибавит ко всем позициям
|
| 55 |
+
ID=$(curl -s -X POST 'http://localhost:7860/upload?x=100&y=64&z=-20' \
|
| 56 |
+
-d 'https://example.com/castle.litematic' | tr -d '"')
|
| 57 |
+
|
| 58 |
+
curl -s http://localhost:7860/$ID/status
|
| 59 |
+
curl -s http://localhost:7860/get/$ID/blocks/0
|
| 60 |
+
curl -s http://localhost:7860/get/$ID/nbt/0
|
| 61 |
+
curl -s http://localhost:7860/get/$ID/parts/0
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## Формат текста
|
| 65 |
+
|
| 66 |
+
Текст — последовательность ячеек по **28 символов**.
|
| 67 |
+
|
| 68 |
+
```
|
| 69 |
+
{"x":0000,"y":0000,"z":0000} ячейка позиции
|
| 70 |
+
{"k":0000,"n":0000,"l":0000} ячейка-заголовок серии
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
* `k` — ключ блока в словаре блоков (`/blocks/{index}`), с `0000`.
|
| 74 |
+
* `n` — ключ NBT в словаре NBT (`/nbt/{index}`). `0000` — нет NBT. Ключи NBT — с `0001`.
|
| 75 |
+
* `l` — сколько ячеек позиций идёт сразу за заголовком.
|
| 76 |
+
* Значение — ровно 4 символа. `5` → `0005`, `0` → `0000`. Отрицательная координата: первый
|
| 77 |
+
символ `-`: `-1` → `-001`, `-123` → `-123`. Диапазон координат: `-999 … 9999`
|
| 78 |
+
(проверяется после сдвига из `/upload`).
|
| 79 |
+
`k`, `n`, `l` — от `0000` до `9999`.
|
| 80 |
+
* Ячейка **не является валидным JSON** (ведущие нули, `-001`): `JSON.parse` и `json.loads`
|
| 81 |
+
её не примут. Читать по фиксированным смещениям: `x` — символы 5–8, `y` — 14–17,
|
| 82 |
+
`z` — 23–26 (то же для `k`, `n`, `l`).
|
| 83 |
+
|
| 84 |
+
Пример. Камень в `(0,0,0)` и `(-1,2,3)`, `k=2`, NBT нет:
|
| 85 |
+
|
| 86 |
+
```
|
| 87 |
+
{"k":0002,"n":0000,"l":0002}{"x":0000,"y":0000,"z":0000}{"x":-001,"y":0002,"z":0003}
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### Границы частей (вариант B)
|
| 91 |
+
|
| 92 |
+
Часть = до **857 ячеек = 23 996 символов**. Серия позиций не пересекает границу части:
|
| 93 |
+
сервер режет её и пишет в начале следующей части новый заголовок с теми же `k` и `n`
|
| 94 |
+
(`l` — сколько позиций осталось в этой части). Поэтому:
|
| 95 |
+
|
| 96 |
+
* каждая часть начинается с заголовка и состоит из целых серий;
|
| 97 |
+
* клиент не хранит состояние между частями, части можно читать параллельно;
|
| 98 |
+
* один блок может встретиться в нескольких за��оловках — клиент объединяет по паре `(k, n)`;
|
| 99 |
+
* если в конце части не хватает места на заголовок и одну позицию, часть закрывается на
|
| 100 |
+
ячейку короче (856 ячеек). Поэтому не считай границы как `index * 23996` — читай части
|
| 101 |
+
по одной через `/parts/{index}`.
|
| 102 |
+
|
| 103 |
+
Чтение без разбора каждой ячейки (Python):
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
def read_part(part, runs):
|
| 107 |
+
i = 0
|
| 108 |
+
while i < len(part):
|
| 109 |
+
k = part[i + 5:i + 9]
|
| 110 |
+
n = part[i + 14:i + 18]
|
| 111 |
+
l = int(part[i + 23:i + 27])
|
| 112 |
+
i += 28
|
| 113 |
+
runs.setdefault((k, n), []).append(part[i:i + 28 * l]) # срез, ячейки не разбираются
|
| 114 |
+
i += 28 * l
|
| 115 |
+
|
| 116 |
+
runs = {}
|
| 117 |
+
for part in parts: # parts[0], parts[1], …
|
| 118 |
+
read_part(part, runs)
|
| 119 |
+
cells = {key: "".join(chunks) for key, chunks in runs.items()} # одна склейка на блок
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
Срез по `l` быстрее чтения по ячейкам: на серию приходится один заголовок, остальное берётся
|
| 123 |
+
срезом. Склеивать лучше один раз в конце (`join`), а не `+=` в цикле. Выигрыша нет только
|
| 124 |
+
когда у каждого блока по одной позиции: на позицию приходится 56 символов вместо 28.
|
| 125 |
+
|
| 126 |
+
## Скорость и лимиты
|
| 127 |
+
|
| 128 |
+
Цель: `/upload` не должен упираться в клиентский таймаут 3 с. Для этого:
|
| 129 |
+
|
| 130 |
+
| Что | Значение |
|
| 131 |
+
|---|---|
|
| 132 |
+
| Срок на весь `/upload` | 2,5 с (иначе `400` с текстом, клиент получает ответ раньше таймаута) |
|
| 133 |
+
| Скачивание | 1,5 с на запрос, 1 с на соединение |
|
| 134 |
+
| Размер файла | 10 МБ |
|
| 135 |
+
| Размер после распаковки gzip | 64 МБ |
|
| 136 |
+
| Непустых блоков | 500 000 (≈ 14 МБ текста, ≈ 590 частей) |
|
| 137 |
+
| Уникальных блоков / NBT | до 10 000 / до 9 999 |
|
| 138 |
+
| Тело `/upload` | 16 КБ |
|
| 139 |
+
|
| 140 |
+
При превышении срока взводится флаг отмены: поток разбора останавливается на ближайшем слое
|
| 141 |
+
по `y`, а не доедает впустую.
|
| 142 |
+
|
| 143 |
+
Оптимизации: ячейки пишутся прямо в буфер в горячем цикле (без промежуточных списков координат
|
| 144 |
+
и без `format!`/`write!`), массивы NBT не копируются (`BlockStates` читается из распакованного
|
| 145 |
+
буфера), для gzip включён быстрый backend `zlib-rs`, воздух пропускается без записи.
|
| 146 |
+
Цифры оценочные, замеров на реальных файлах не было.
|
| 147 |
+
|
| 148 |
+
## Решения по неоднозначностям
|
| 149 |
+
|
| 150 |
+
1. **Часть `/parts`** — 857 ячеек (23 996 символов): 24 000 не делится на 28. Меняется
|
| 151 |
+
константой `CELLS_PER_PART` в `src/encoder.rs`.
|
| 152 |
+
2. **Ключи** — `k` по порядку сортировки названий блоков, `n` по порядку сортировки SNBT-строк.
|
| 153 |
+
3. **NBT** — берётся из `TileEntities` региона (координаты tile entity считаются локальными
|
| 154 |
+
в регионе, как в litematica). Из записи убираются `x`, `y`, `z`, остаток сохраняется как
|
| 155 |
+
SNBT-строка. Блоки с разным NBT идут разными сериями `(k, n)`. Entities (мобы, рамки)
|
| 156 |
+
не обрабатываются.
|
| 157 |
+
4. **Несколько регионов** — поддержаны, координаты абсолютные (`Position` + локальная позиция,
|
| 158 |
+
отрицательный `Size` учтён). Регионы обходятся по имени.
|
| 159 |
+
5. **Название блока** без префикса `minecraft:` и с состоянием: `oak_stairs[facing=north,half=bottom]`.
|
| 160 |
+
Другие пространства имён сохраняются (`create:cogwheel`). В SNBT внутри NBT префикс не убирается.
|
| 161 |
+
6. **Воздух** (`air`, `cave_air`, `void_air`) пропускается.
|
| 162 |
+
7. **Хранение** — только память процесса, после перезапуска UUID пропадают.
|
| 163 |
+
8. **`/status`** всегда `ready`: `/upload` отвечает после полной обработки.
|
| 164 |
+
9. **Сдвиг.** Сервер возвращает позиции = `Position` региона + локальная позиция + `(x, y, z)` из
|
| 165 |
+
`/upload`. Сдвиг одинаков для всех регионов и NBT-блоков, считается один раз при разборе,
|
| 166 |
+
на скорость не влияет. Хранится уже сдвинутый результат; другой сдвиг — новый `/upload`.
|
| 167 |
+
|
| 168 |
+
SSRF: ссылки на localhost, частные и служебные IP отклоняются, в том числе при
|
| 169 |
+
перенаправлениях. DNS-имена, указывающие на внутренние адреса, не проверяются.
|
| 170 |
+
Число хранимых схематик не ограничено — для публичного Space добавь лимит.
|
| 171 |
+
|
| 172 |
+
## Структура
|
| 173 |
+
|
| 174 |
+
```
|
| 175 |
+
src/main.rs запуск, порт, graceful shutdown
|
| 176 |
+
src/http.rs роуты, ошибки, дедлайн /upload
|
| 177 |
+
src/loader.rs скачивание, лимиты, проверка адреса
|
| 178 |
+
src/nbt.rs gzip, NBT, SNBT, разбор регионов (пишет ячейки позиций)
|
| 179 |
+
src/encoder.rs ячейки, раскладка по частям, словари (чистые функции)
|
| 180 |
+
src/store.rs HashMap<Uuid, Schematic> за RwLock
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
Детерминизм: ключи сортируются (`BTreeMap`), регионы — по имени, позиции — в порядке индекса
|
| 184 |
+
litematica (y, z, x). Один файл → один и тот же текст.
|
src/src/encoder.rs
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! Кодирование в текст из ячеек по 28 символов, раскладка по частям, словари.
|
| 2 |
+
//!
|
| 3 |
+
//! Ячейка позиции: `{"x":0000,"y":0000,"z":0000}`
|
| 4 |
+
//! Ячейка-заголовок: `{"k":0000,"n":0000,"l":0000}`
|
| 5 |
+
//! k — ключ блока в словаре блоков, n — ключ NBT в словаре NBT (0000 — нет NBT),
|
| 6 |
+
//! l — сколько ячеек позиций идёт сразу за заголовком.
|
| 7 |
+
//! Значения — ровно 4 символа: `0005`; отрицательные координаты — `-001`.
|
| 8 |
+
//! Это НЕ валидный JSON (ведущие нули): читать по фиксированным смещениям
|
| 9 |
+
//! 5..9, 14..18, 23..27.
|
| 10 |
+
//!
|
| 11 |
+
//! Раскладка по частям (вариант B): часть = до 857 ячеек (23 996 символов).
|
| 12 |
+
//! Серия позиций не переходит границу части: сервер режет её и пишет в начале
|
| 13 |
+
//! следующей части новый заголовок с теми же k и n. Каждая часть начинается
|
| 14 |
+
//! с заголовка и состоит из целых серий. Если в конце части остаётся одна
|
| 15 |
+
//! ячейка (заголовок с позицией не влезает), часть закрывается на ячейку короче.
|
| 16 |
+
|
| 17 |
+
use std::collections::{BTreeMap, BTreeSet};
|
| 18 |
+
use std::fmt;
|
| 19 |
+
|
| 20 |
+
use serde_json::{Map, Value};
|
| 21 |
+
|
| 22 |
+
/// (название блока, SNBT или "") → ячейки позиций подряд, по 28 байт на позицию.
|
| 23 |
+
pub type Groups = BTreeMap<(String, String), Vec<u8>>;
|
| 24 |
+
|
| 25 |
+
pub const CELL_LEN: usize = 28;
|
| 26 |
+
pub const CELLS_PER_PART: usize = 857;
|
| 27 |
+
/// 857 × 28 = 23 996 ≤ 24 000.
|
| 28 |
+
pub const PART_CHARS: usize = CELL_LEN * CELLS_PER_PART;
|
| 29 |
+
/// Максимум позиций в одной серии (поле `l` — 4 цифры).
|
| 30 |
+
pub const MAX_RUN: usize = 9_999;
|
| 31 |
+
/// Максимальный ключ (поля `k`, `n` — 4 цифры).
|
| 32 |
+
pub const MAX_KEY: usize = 9_999;
|
| 33 |
+
pub const COORD_MIN: i32 = -999;
|
| 34 |
+
pub const COORD_MAX: i32 = 9_999;
|
| 35 |
+
/// Максимум символов в JSON одной части словаря.
|
| 36 |
+
pub const DICT_PART_JSON_MAX: usize = 24_000;
|
| 37 |
+
/// Запас под обёртку `{"blocks":{...},"index":N}`.
|
| 38 |
+
const DICT_JSON_RESERVE: usize = 64;
|
| 39 |
+
|
| 40 |
+
const POS_TEMPLATE: &[u8; CELL_LEN] = br#"{"x":0000,"y":0000,"z":0000}"#;
|
| 41 |
+
const HEADER_TEMPLATE: &[u8; CELL_LEN] = br#"{"k":0000,"n":0000,"l":0000}"#;
|
| 42 |
+
|
| 43 |
+
const _: () = assert!(PART_CHARS <= 24_000);
|
| 44 |
+
const _: () = assert!(CELLS_PER_PART >= 2);
|
| 45 |
+
|
| 46 |
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
| 47 |
+
pub struct DictEntry {
|
| 48 |
+
pub key: String,
|
| 49 |
+
pub value: String,
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
| 53 |
+
pub enum EncodeError {
|
| 54 |
+
CoordOutOfRange(i32),
|
| 55 |
+
TooManyUniqueBlocks(usize),
|
| 56 |
+
TooManyUniqueNbt(usize),
|
| 57 |
+
EntryTooLong(usize),
|
| 58 |
+
InvalidCells,
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
impl fmt::Display for EncodeError {
|
| 62 |
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
| 63 |
+
match self {
|
| 64 |
+
EncodeError::CoordOutOfRange(v) => write!(
|
| 65 |
+
f,
|
| 66 |
+
"координата {v} вне диапазона {COORD_MIN}..{COORD_MAX}, ячейка из 4 символов её не вмещает"
|
| 67 |
+
),
|
| 68 |
+
EncodeError::TooManyUniqueBlocks(n) => write!(
|
| 69 |
+
f,
|
| 70 |
+
"уникальных блоков {n}, максимум {} (ключ блока — 4 цифры)",
|
| 71 |
+
MAX_KEY + 1
|
| 72 |
+
),
|
| 73 |
+
EncodeError::TooManyUniqueNbt(n) => write!(
|
| 74 |
+
f,
|
| 75 |
+
"уникальных NBT {n}, максимум {MAX_KEY} (ключ NBT — 4 цифры, 0000 занят под «нет NBT»)"
|
| 76 |
+
),
|
| 77 |
+
EncodeError::EntryTooLong(n) => write!(
|
| 78 |
+
f,
|
| 79 |
+
"запись словаря ({n} символов JSON) не помещается в одну часть"
|
| 80 |
+
),
|
| 81 |
+
EncodeError::InvalidCells => write!(f, "внутренняя ошибка: некорректные ячейки позиций"),
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
impl std::error::Error for EncodeError {}
|
| 87 |
+
|
| 88 |
+
// ---------------------------------------------------------------- ячейки
|
| 89 |
+
|
| 90 |
+
#[inline]
|
| 91 |
+
fn put4(dst: &mut [u8], v: u32) {
|
| 92 |
+
dst[0] = b'0' + (v / 1000 % 10) as u8;
|
| 93 |
+
dst[1] = b'0' + (v / 100 % 10) as u8;
|
| 94 |
+
dst[2] = b'0' + (v / 10 % 10) as u8;
|
| 95 |
+
dst[3] = b'0' + (v % 10) as u8;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
#[inline]
|
| 99 |
+
fn put_coord(dst: &mut [u8], v: i32) -> Result<(), EncodeError> {
|
| 100 |
+
if !(COORD_MIN..=COORD_MAX).contains(&v) {
|
| 101 |
+
return Err(EncodeError::CoordOutOfRange(v));
|
| 102 |
+
}
|
| 103 |
+
if v >= 0 {
|
| 104 |
+
put4(dst, v as u32);
|
| 105 |
+
} else {
|
| 106 |
+
let a = (-v) as u32;
|
| 107 |
+
dst[0] = b'-';
|
| 108 |
+
dst[1] = b'0' + (a / 100) as u8;
|
| 109 |
+
dst[2] = b'0' + (a / 10 % 10) as u8;
|
| 110 |
+
dst[3] = b'0' + (a % 10) as u8;
|
| 111 |
+
}
|
| 112 |
+
Ok(())
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
/// Координ��та → ровно 4 символа. `-1` → `-001`, `5` → `0005`, `-123` → `-123`.
|
| 116 |
+
pub fn encode_coord(v: i32) -> Result<String, EncodeError> {
|
| 117 |
+
let mut b = [0u8; 4];
|
| 118 |
+
put_coord(&mut b, v)?;
|
| 119 |
+
Ok(String::from_utf8_lossy(&b).into_owned())
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/// Дописывает ячейку позиции (28 байт). Без форматирования строк — горячий путь.
|
| 123 |
+
#[inline]
|
| 124 |
+
pub fn push_position(buf: &mut Vec<u8>, x: i32, y: i32, z: i32) -> Result<(), EncodeError> {
|
| 125 |
+
let mut cell = *POS_TEMPLATE;
|
| 126 |
+
put_coord(&mut cell[5..9], x)?;
|
| 127 |
+
put_coord(&mut cell[14..18], y)?;
|
| 128 |
+
put_coord(&mut cell[23..27], z)?;
|
| 129 |
+
buf.extend_from_slice(&cell);
|
| 130 |
+
Ok(())
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
fn push_header(buf: &mut Vec<u8>, k: usize, n: usize, l: usize) {
|
| 134 |
+
debug_assert!(k <= MAX_KEY && n <= MAX_KEY && l <= MAX_RUN);
|
| 135 |
+
let mut cell = *HEADER_TEMPLATE;
|
| 136 |
+
put4(&mut cell[5..9], k as u32);
|
| 137 |
+
put4(&mut cell[14..18], n as u32);
|
| 138 |
+
put4(&mut cell[23..27], l as u32);
|
| 139 |
+
buf.extend_from_slice(&cell);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
// ---------------------------------------------------------------- раскладка по частям
|
| 143 |
+
|
| 144 |
+
/// Раскладывает серии по частям (вариант B). Чистая структура без ввода-вывода.
|
| 145 |
+
pub struct Layout {
|
| 146 |
+
text: Vec<u8>,
|
| 147 |
+
part_ends: Vec<usize>,
|
| 148 |
+
cells_in_part: usize,
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
impl Layout {
|
| 152 |
+
pub fn with_capacity(bytes: usize) -> Self {
|
| 153 |
+
Layout {
|
| 154 |
+
text: Vec::with_capacity(bytes),
|
| 155 |
+
part_ends: Vec::new(),
|
| 156 |
+
cells_in_part: 0,
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
fn close_part(&mut self) {
|
| 161 |
+
if self.cells_in_part > 0 {
|
| 162 |
+
self.part_ends.push(self.text.len());
|
| 163 |
+
self.cells_in_part = 0;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/// Добавляет все позиции блока `k` с NBT `n`. `cells` — ячейки позиций, кратно 28 байт.
|
| 168 |
+
pub fn push_group(&mut self, k: usize, n: usize, cells: &[u8]) {
|
| 169 |
+
debug_assert_eq!(cells.len() % CELL_LEN, 0);
|
| 170 |
+
let count = cells.len() / CELL_LEN;
|
| 171 |
+
let mut done = 0usize;
|
| 172 |
+
while done < count {
|
| 173 |
+
// заголовок + хотя бы одна позиция должны влезть
|
| 174 |
+
if CELLS_PER_PART - self.cells_in_part < 2 {
|
| 175 |
+
self.close_part();
|
| 176 |
+
}
|
| 177 |
+
let space = CELLS_PER_PART - self.cells_in_part;
|
| 178 |
+
let take = (count - done).min(space - 1).min(MAX_RUN);
|
| 179 |
+
push_header(&mut self.text, k, n, take);
|
| 180 |
+
self.text
|
| 181 |
+
.extend_from_slice(&cells[done * CELL_LEN..(done + take) * CELL_LEN]);
|
| 182 |
+
self.cells_in_part += 1 + take;
|
| 183 |
+
done += take;
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/// Текст и конец каждой части (смещение в байтах).
|
| 188 |
+
pub fn finish(mut self) -> (Vec<u8>, Vec<usize>) {
|
| 189 |
+
self.close_part();
|
| 190 |
+
(self.text, self.part_ends)
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/// Часть текста с номером `index` (с нуля). `None` — индекс вне диапазона.
|
| 195 |
+
pub fn text_part<'a>(text: &'a str, part_ends: &[usize], index: usize) -> Option<&'a str> {
|
| 196 |
+
let end = *part_ends.get(index)?;
|
| 197 |
+
let start = if index == 0 { 0 } else { part_ends[index - 1] };
|
| 198 |
+
text.get(start..end)
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
// ---------------------------------------------------------------- кодирование
|
| 202 |
+
|
| 203 |
+
pub struct Encoded {
|
| 204 |
+
pub text: String,
|
| 205 |
+
pub part_ends: Vec<usize>,
|
| 206 |
+
pub blocks: Vec<DictEntry>,
|
| 207 |
+
pub nbt: Vec<DictEntry>,
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/// Группы позиций → текст, границы частей, словарь блоков и словарь NBT.
|
| 211 |
+
/// Ключи блоков — по порядку сортировки названий (с 0000), ключи NBT — по порядку
|
| 212 |
+
/// сортировки строк (с 0001; 0000 — «нет NBT»). Результат детерминирован.
|
| 213 |
+
pub fn encode(groups: &Groups) -> Result<Encoded, EncodeError> {
|
| 214 |
+
if groups
|
| 215 |
+
.values()
|
| 216 |
+
.any(|c| c.is_empty() || c.len() % CELL_LEN != 0)
|
| 217 |
+
{
|
| 218 |
+
return Err(EncodeError::InvalidCells);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
let mut block_names: Vec<&str> = Vec::new();
|
| 222 |
+
for (name, _) in groups.keys() {
|
| 223 |
+
if block_names.last().copied() != Some(name.as_str()) {
|
| 224 |
+
block_names.push(name.as_str());
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
if block_names.len() > MAX_KEY + 1 {
|
| 228 |
+
return Err(EncodeError::TooManyUniqueBlocks(block_names.len()));
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
let nbt_set: BTreeSet<&str> = groups
|
| 232 |
+
.keys()
|
| 233 |
+
.filter(|key| !key.1.is_empty())
|
| 234 |
+
.map(|key| key.1.as_str())
|
| 235 |
+
.collect();
|
| 236 |
+
let nbt_list: Vec<&str> = nbt_set.into_iter().collect();
|
| 237 |
+
if nbt_list.len() > MAX_KEY {
|
| 238 |
+
return Err(EncodeError::TooManyUniqueNbt(nbt_list.len()));
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
let total: usize = groups.values().map(|c| c.len()).sum();
|
| 242 |
+
let mut layout = Layout::with_capacity(total + groups.len() * CELL_LEN * 2 + CELL_LEN * 64);
|
| 243 |
+
for ((name, snbt), cells) in groups {
|
| 244 |
+
let k = block_names
|
| 245 |
+
.binary_search(&name.as_str())
|
| 246 |
+
.map_err(|_| EncodeError::InvalidCells)?;
|
| 247 |
+
let n = if snbt.is_empty() {
|
| 248 |
+
0
|
| 249 |
+
} else {
|
| 250 |
+
nbt_list
|
| 251 |
+
.binary_search(&snbt.as_str())
|
| 252 |
+
.map_err(|_| EncodeError::InvalidCells)?
|
| 253 |
+
+ 1
|
| 254 |
+
};
|
| 255 |
+
layout.push_group(k, n, cells);
|
| 256 |
+
}
|
| 257 |
+
let (bytes, part_ends) = layout.finish();
|
| 258 |
+
let text = String::from_utf8(bytes).map_err(|_| EncodeError::InvalidCells)?;
|
| 259 |
+
|
| 260 |
+
let blocks = block_names
|
| 261 |
+
.iter()
|
| 262 |
+
.enumerate()
|
| 263 |
+
.map(|(i, name)| DictEntry {
|
| 264 |
+
key: format!("{i:04}"),
|
| 265 |
+
value: name.to_string(),
|
| 266 |
+
})
|
| 267 |
+
.collect();
|
| 268 |
+
let nbt = nbt_list
|
| 269 |
+
.iter()
|
| 270 |
+
.enumerate()
|
| 271 |
+
.map(|(i, s)| DictEntry {
|
| 272 |
+
key: format!("{:04}", i + 1),
|
| 273 |
+
value: s.to_string(),
|
| 274 |
+
})
|
| 275 |
+
.collect();
|
| 276 |
+
|
| 277 |
+
Ok(Encoded {
|
| 278 |
+
text,
|
| 279 |
+
part_ends,
|
| 280 |
+
blocks,
|
| 281 |
+
nbt,
|
| 282 |
+
})
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
// ---------------------------------------------------------------- нарезка словарей
|
| 286 |
+
|
| 287 |
+
/// Длина записи `"ключ":"значение",` в JSON (символов, с запятой).
|
| 288 |
+
pub fn entry_json_len(e: &DictEntry) -> usize {
|
| 289 |
+
let key = Value::String(e.key.clone()).to_string().chars().count();
|
| 290 |
+
let val = Value::String(e.value.clone()).to_string().chars().count();
|
| 291 |
+
key + 1 + val + 1 // двоеточие и запятая
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
/// Тело ответа части словаря: `{"index": i, "<field>": {"0000": "..."}}`.
|
| 295 |
+
/// `field` — `blocks` или `nbt`.
|
| 296 |
+
pub fn dict_part_json(field: &str, index: usize, entries: &[DictEntry]) -> Value {
|
| 297 |
+
let mut map = Map::new();
|
| 298 |
+
for e in entries {
|
| 299 |
+
map.insert(e.key.clone(), Value::String(e.value.clone()));
|
| 300 |
+
}
|
| 301 |
+
let mut obj = Map::new();
|
| 302 |
+
obj.insert("index".to_string(), Value::from(index));
|
| 303 |
+
obj.insert(field.to_string(), Value::Object(map));
|
| 304 |
+
Value::Object(obj)
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/// Режет словарь так, чтобы JSON каждой части был ≤ `max_json_chars` символов.
|
| 308 |
+
pub fn split_dict(
|
| 309 |
+
entries: &[DictEntry],
|
| 310 |
+
max_json_chars: usize,
|
| 311 |
+
) -> Result<Vec<Vec<DictEntry>>, EncodeError> {
|
| 312 |
+
let budget = max_json_chars.saturating_sub(DICT_JSON_RESERVE);
|
| 313 |
+
let mut parts: Vec<Vec<DictEntry>> = Vec::new();
|
| 314 |
+
let mut current: Vec<DictEntry> = Vec::new();
|
| 315 |
+
let mut used = 0usize;
|
| 316 |
+
for e in entries {
|
| 317 |
+
let len = entry_json_len(e);
|
| 318 |
+
if len > budget {
|
| 319 |
+
return Err(EncodeError::EntryTooLong(len));
|
| 320 |
+
}
|
| 321 |
+
if used + len > budget && !current.is_empty() {
|
| 322 |
+
parts.push(std::mem::take(&mut current));
|
| 323 |
+
used = 0;
|
| 324 |
+
}
|
| 325 |
+
current.push(e.clone());
|
| 326 |
+
used += len;
|
| 327 |
+
}
|
| 328 |
+
if !current.is_empty() {
|
| 329 |
+
parts.push(current);
|
| 330 |
+
}
|
| 331 |
+
Ok(parts)
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
#[cfg(test)]
|
| 335 |
+
mod tests {
|
| 336 |
+
use super::*;
|
| 337 |
+
use serde_json::json;
|
| 338 |
+
|
| 339 |
+
// ---- помощники ----
|
| 340 |
+
fn cells(n: usize) -> Vec<u8> {
|
| 341 |
+
let mut b = Vec::new();
|
| 342 |
+
for i in 0..n {
|
| 343 |
+
push_position(&mut b, i as i32, 0, 0).unwrap();
|
| 344 |
+
}
|
| 345 |
+
b
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
fn cv(c: &str) -> i32 {
|
| 349 |
+
if let Some(rest) = c.strip_prefix('-') {
|
| 350 |
+
-rest.parse::<i32>().unwrap()
|
| 351 |
+
} else {
|
| 352 |
+
c.parse().unwrap()
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
/// Читает часть так, как её читает клиент: заголовок, затем срез из l ячеек.
|
| 357 |
+
fn runs(part: &str) -> Vec<(usize, usize, Vec<i32>)> {
|
| 358 |
+
assert_eq!(part.len() % CELL_LEN, 0);
|
| 359 |
+
let mut out = Vec::new();
|
| 360 |
+
let mut i = 0;
|
| 361 |
+
while i < part.len() {
|
| 362 |
+
let h = &part[i..i + CELL_LEN];
|
| 363 |
+
assert!(h.starts_with("{\"k\":") && h.ends_with('}'), "заголовок: {h}");
|
| 364 |
+
let k: usize = h[5..9].parse().unwrap();
|
| 365 |
+
let n: usize = h[14..18].parse().unwrap();
|
| 366 |
+
let l: usize = h[23..27].parse().unwrap();
|
| 367 |
+
i += CELL_LEN;
|
| 368 |
+
let slice = &part[i..i + l * CELL_LEN];
|
| 369 |
+
let xs = (0..l)
|
| 370 |
+
.map(|j| cv(&slice[j * CELL_LEN + 5..j * CELL_LEN + 9]))
|
| 371 |
+
.collect();
|
| 372 |
+
i += l * CELL_LEN;
|
| 373 |
+
out.push((k, n, xs));
|
| 374 |
+
}
|
| 375 |
+
out
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
fn layout(groups: &[(usize, usize, usize)]) -> (String, Vec<usize>) {
|
| 379 |
+
let mut l = Layout::with_capacity(0);
|
| 380 |
+
for &(k, n, count) in groups {
|
| 381 |
+
l.push_group(k, n, &cells(count));
|
| 382 |
+
}
|
| 383 |
+
let (bytes, ends) = l.finish();
|
| 384 |
+
(String::from_utf8(bytes).unwrap(), ends)
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
fn all_parts<'a>(text: &'a str, ends: &[usize]) -> Vec<&'a str> {
|
| 388 |
+
(0..ends.len()).map(|i| text_part(text, ends, i).unwrap()).collect()
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
fn merged(parts: &[&str]) -> BTreeMap<(usize, usize), Vec<i32>> {
|
| 392 |
+
let mut m: BTreeMap<(usize, usize), Vec<i32>> = BTreeMap::new();
|
| 393 |
+
for p in parts {
|
| 394 |
+
for (k, n, xs) in runs(p) {
|
| 395 |
+
m.entry((k, n)).or_default().extend(xs);
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
m
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
// ---- ячейки ----
|
| 402 |
+
#[test]
|
| 403 |
+
fn coord_cells() {
|
| 404 |
+
assert_eq!(encode_coord(0).unwrap(), "0000");
|
| 405 |
+
assert_eq!(encode_coord(5).unwrap(), "0005");
|
| 406 |
+
assert_eq!(encode_coord(123).unwrap(), "0123");
|
| 407 |
+
assert_eq!(encode_coord(-1).unwrap(), "-001");
|
| 408 |
+
assert_eq!(encode_coord(-123).unwrap(), "-123");
|
| 409 |
+
assert_eq!(encode_coord(COORD_MAX).unwrap(), "9999");
|
| 410 |
+
assert_eq!(encode_coord(COORD_MIN).unwrap(), "-999");
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
#[test]
|
| 414 |
+
fn coord_out_of_range() {
|
| 415 |
+
assert_eq!(encode_coord(10_000), Err(EncodeError::CoordOutOfRange(10_000)));
|
| 416 |
+
assert_eq!(encode_coord(-1000), Err(EncodeError::CoordOutOfRange(-1000)));
|
| 417 |
+
assert!(encode_coord(i32::MIN).is_err());
|
| 418 |
+
assert!(encode_coord(i32::MAX).is_err());
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
#[test]
|
| 422 |
+
fn position_cell_format() {
|
| 423 |
+
let mut b = Vec::new();
|
| 424 |
+
push_position(&mut b, 1, -1, 9999).unwrap();
|
| 425 |
+
assert_eq!(b.len(), CELL_LEN);
|
| 426 |
+
assert_eq!(String::from_utf8(b).unwrap(), r#"{"x":0001,"y":-001,"z":9999}"#);
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
#[test]
|
| 430 |
+
fn position_cell_zero_and_min() {
|
| 431 |
+
let mut b = Vec::new();
|
| 432 |
+
push_position(&mut b, 0, -999, 0).unwrap();
|
| 433 |
+
assert_eq!(String::from_utf8(b).unwrap(), r#"{"x":0000,"y":-999,"z":0000}"#);
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
#[test]
|
| 437 |
+
fn position_cell_rejects_range() {
|
| 438 |
+
let mut b = Vec::new();
|
| 439 |
+
assert_eq!(push_position(&mut b, 0, 0, 10_000), Err(EncodeError::CoordOutOfRange(10_000)));
|
| 440 |
+
assert_eq!(push_position(&mut b, -1000, 0, 0), Err(EncodeError::CoordOutOfRange(-1000)));
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
#[test]
|
| 444 |
+
fn header_cell_format() {
|
| 445 |
+
let mut b = Vec::new();
|
| 446 |
+
push_header(&mut b, 12, 3, 456);
|
| 447 |
+
assert_eq!(b.len(), CELL_LEN);
|
| 448 |
+
assert_eq!(String::from_utf8(b).unwrap(), r#"{"k":0012,"n":0003,"l":0456}"#);
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
#[test]
|
| 452 |
+
fn part_size_constants() {
|
| 453 |
+
assert_eq!(PART_CHARS, 23_996);
|
| 454 |
+
assert_eq!(PART_CHARS % CELL_LEN, 0);
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
// ---- раскладка по частям ----
|
| 458 |
+
#[test]
|
| 459 |
+
fn layout_empty() {
|
| 460 |
+
let (text, ends) = layout(&[]);
|
| 461 |
+
assert!(text.is_empty());
|
| 462 |
+
assert!(ends.is_empty());
|
| 463 |
+
assert_eq!(text_part(&text, &ends, 0), None);
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
#[test]
|
| 467 |
+
fn layout_one_position() {
|
| 468 |
+
let (text, ends) = layout(&[(0, 0, 1)]);
|
| 469 |
+
assert_eq!(ends, vec![2 * CELL_LEN]);
|
| 470 |
+
assert_eq!(
|
| 471 |
+
text,
|
| 472 |
+
[r#"{"k":0000,"n":0000,"l":0001}"#, r#"{"x":0000,"y":0000,"z":0000}"#].concat()
|
| 473 |
+
);
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
#[test]
|
| 477 |
+
fn layout_exactly_one_full_part() {
|
| 478 |
+
let (text, ends) = layout(&[(0, 0, CELLS_PER_PART - 1)]);
|
| 479 |
+
assert_eq!(ends, vec![PART_CHARS]);
|
| 480 |
+
assert_eq!(text.len(), PART_CHARS);
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
#[test]
|
| 484 |
+
fn layout_one_over_splits_run_with_new_header() {
|
| 485 |
+
let (text, ends) = layout(&[(3, 7, CELLS_PER_PART)]);
|
| 486 |
+
assert_eq!(ends, vec![PART_CHARS, PART_CHARS + 2 * CELL_LEN]);
|
| 487 |
+
let parts = all_parts(&text, &ends);
|
| 488 |
+
let r0 = runs(parts[0]);
|
| 489 |
+
let r1 = runs(parts[1]);
|
| 490 |
+
assert_eq!(r0.len(), 1);
|
| 491 |
+
assert_eq!(r1.len(), 1);
|
| 492 |
+
assert_eq!((r0[0].0, r0[0].1, r0[0].2.len()), (3, 7, CELLS_PER_PART - 1));
|
| 493 |
+
assert_eq!((r1[0].0, r1[0].1, r1[0].2.len()), (3, 7, 1));
|
| 494 |
+
let merged = merged(&parts);
|
| 495 |
+
assert_eq!(merged[&(3, 7)], (0..CELLS_PER_PART as i32).collect::<Vec<_>>());
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
#[test]
|
| 499 |
+
fn layout_one_cell_left_closes_part_early() {
|
| 500 |
+
// 1 + 855 = 856 ячеек; остаётся 1 — заголовок с позицией не влезет
|
| 501 |
+
let (text, ends) = layout(&[(0, 0, CELLS_PER_PART - 2), (1, 0, 1)]);
|
| 502 |
+
assert_eq!(ends, vec![(CELLS_PER_PART - 1) * CELL_LEN, (CELLS_PER_PART + 1) * CELL_LEN]);
|
| 503 |
+
let parts = all_parts(&text, &ends);
|
| 504 |
+
assert_eq!(runs(parts[1]), vec![(1, 0, vec![0])]);
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
#[test]
|
| 508 |
+
fn layout_two_cells_left_fit_exactly() {
|
| 509 |
+
// 1 + 854 = 855 ячеек; остаётся 2 — влезает заголовок и одна позиция
|
| 510 |
+
let (_, ends) = layout(&[(0, 0, CELLS_PER_PART - 3), (1, 0, 1)]);
|
| 511 |
+
assert_eq!(ends, vec![PART_CHARS]);
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
#[test]
|
| 515 |
+
fn layout_part_not_closed_when_not_full() {
|
| 516 |
+
let (_, ends) = layout(&[(0, 0, CELLS_PER_PART - 2)]);
|
| 517 |
+
assert_eq!(ends, vec![(CELLS_PER_PART - 1) * CELL_LEN]);
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
#[test]
|
| 521 |
+
fn layout_big_input_parts_are_self_contained() {
|
| 522 |
+
let (text, ends) = layout(&[(0, 0, 3000), (1, 1, 10), (2, 0, 900)]);
|
| 523 |
+
let parts = all_parts(&text, &ends);
|
| 524 |
+
assert!(parts.len() > 3);
|
| 525 |
+
for p in &parts {
|
| 526 |
+
assert!(p.len() <= PART_CHARS);
|
| 527 |
+
assert_eq!(p.len() % CELL_LEN, 0);
|
| 528 |
+
assert!(!runs(p).is_empty()); // каждая часть читается с первого заголовка
|
| 529 |
+
}
|
| 530 |
+
let m = merged(&parts);
|
| 531 |
+
assert_eq!(m[&(0, 0)], (0..3000).collect::<Vec<_>>());
|
| 532 |
+
assert_eq!(m[&(1, 1)], (0..10).collect::<Vec<_>>());
|
| 533 |
+
assert_eq!(m[&(2, 0)], (0..900).collect::<Vec<_>>());
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
#[test]
|
| 537 |
+
fn text_part_bounds() {
|
| 538 |
+
let (text, ends) = layout(&[(0, 0, CELLS_PER_PART)]);
|
| 539 |
+
assert!(text_part(&text, &ends, 0).is_some());
|
| 540 |
+
assert!(text_part(&text, &ends, 1).is_some());
|
| 541 |
+
assert_eq!(text_part(&text, &ends, 2), None);
|
| 542 |
+
assert_eq!(text_part(&text, &ends, usize::MAX), None);
|
| 543 |
+
assert_eq!(text_part(&text, &ends, 0).unwrap().len(), PART_CHARS);
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
// ---- encode ----
|
| 547 |
+
fn group(cells_n: usize) -> Vec<u8> {
|
| 548 |
+
cells(cells_n)
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
#[test]
|
| 552 |
+
fn encode_empty() {
|
| 553 |
+
let e = encode(&Groups::new()).unwrap();
|
| 554 |
+
assert!(e.text.is_empty());
|
| 555 |
+
assert!(e.part_ends.is_empty());
|
| 556 |
+
assert!(e.blocks.is_empty());
|
| 557 |
+
assert!(e.nbt.is_empty());
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
#[test]
|
| 561 |
+
fn encode_assigns_keys_in_sorted_order() {
|
| 562 |
+
let mut g = Groups::new();
|
| 563 |
+
g.insert(("minecraft:dirt".into(), String::new()), group(2));
|
| 564 |
+
g.insert(("minecraft:chest".into(), r#"{id:"c"}"#.into()), group(1));
|
| 565 |
+
g.insert(("minecraft:chest".into(), r#"{id:"a"}"#.into()), group(1));
|
| 566 |
+
let e = encode(&g).unwrap();
|
| 567 |
+
assert_eq!(
|
| 568 |
+
e.blocks,
|
| 569 |
+
vec![
|
| 570 |
+
DictEntry { key: "0000".into(), value: "minecraft:chest".into() },
|
| 571 |
+
DictEntry { key: "0001".into(), value: "minecraft:dirt".into() },
|
| 572 |
+
]
|
| 573 |
+
);
|
| 574 |
+
assert_eq!(
|
| 575 |
+
e.nbt,
|
| 576 |
+
vec![
|
| 577 |
+
DictEntry { key: "0001".into(), value: r#"{id:"a"}"#.into() },
|
| 578 |
+
DictEntry { key: "0002".into(), value: r#"{id:"c"}"#.into() },
|
| 579 |
+
]
|
| 580 |
+
);
|
| 581 |
+
assert_eq!(e.part_ends.len(), 1);
|
| 582 |
+
let r = runs(&e.text);
|
| 583 |
+
assert_eq!(r, vec![(0, 1, vec![0]), (0, 2, vec![0]), (1, 0, vec![0, 1])]);
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
#[test]
|
| 587 |
+
fn encode_is_deterministic() {
|
| 588 |
+
let mut g = Groups::new();
|
| 589 |
+
g.insert(("b".into(), String::new()), group(3));
|
| 590 |
+
g.insert(("a".into(), String::new()), group(2));
|
| 591 |
+
let e1 = encode(&g).unwrap();
|
| 592 |
+
let e2 = encode(&g).unwrap();
|
| 593 |
+
assert_eq!(e1.text, e2.text);
|
| 594 |
+
assert_eq!(e1.part_ends, e2.part_ends);
|
| 595 |
+
assert_eq!(e1.blocks[0].value, "a");
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
#[test]
|
| 599 |
+
fn encode_rejects_bad_cells() {
|
| 600 |
+
let mut g = Groups::new();
|
| 601 |
+
g.insert(("a".into(), String::new()), vec![0u8; CELL_LEN - 1]);
|
| 602 |
+
assert!(matches!(encode(&g), Err(EncodeError::InvalidCells)));
|
| 603 |
+
let mut g = Groups::new();
|
| 604 |
+
g.insert(("a".into(), String::new()), Vec::new());
|
| 605 |
+
assert!(matches!(encode(&g), Err(EncodeError::InvalidCells)));
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
#[test]
|
| 609 |
+
fn encode_too_many_unique_blocks() {
|
| 610 |
+
let mut g = Groups::new();
|
| 611 |
+
for i in 0..=MAX_KEY + 1 {
|
| 612 |
+
g.insert((format!("b{i:05}"), String::new()), group(1));
|
| 613 |
+
}
|
| 614 |
+
assert!(matches!(encode(&g), Err(EncodeError::TooManyUniqueBlocks(_))));
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
#[test]
|
| 618 |
+
fn encode_max_unique_blocks_ok() {
|
| 619 |
+
let mut g = Groups::new();
|
| 620 |
+
for i in 0..=MAX_KEY {
|
| 621 |
+
g.insert((format!("b{i:05}"), String::new()), group(1));
|
| 622 |
+
}
|
| 623 |
+
let e = encode(&g).unwrap();
|
| 624 |
+
assert_eq!(e.blocks.len(), MAX_KEY + 1);
|
| 625 |
+
assert_eq!(e.blocks.last().unwrap().key, "9999");
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
#[test]
|
| 629 |
+
fn encode_too_many_unique_nbt() {
|
| 630 |
+
let mut g = Groups::new();
|
| 631 |
+
for i in 0..=MAX_KEY {
|
| 632 |
+
g.insert(("a".into(), format!("s{i}")), group(1));
|
| 633 |
+
}
|
| 634 |
+
assert!(matches!(encode(&g), Err(EncodeError::TooManyUniqueNbt(_))));
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
// ---- словари ----
|
| 638 |
+
fn entries(n: usize, value_len: usize) -> Vec<DictEntry> {
|
| 639 |
+
(0..n)
|
| 640 |
+
.map(|i| DictEntry {
|
| 641 |
+
key: format!("{i:04}"),
|
| 642 |
+
value: format!("{:0>width$}", i, width = value_len),
|
| 643 |
+
})
|
| 644 |
+
.collect()
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
fn json_len(index: usize, part: &[DictEntry]) -> usize {
|
| 648 |
+
dict_part_json("blocks", index, part).to_string().chars().count()
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
#[test]
|
| 652 |
+
fn dict_json_shape() {
|
| 653 |
+
let e = vec![DictEntry { key: "0000".into(), value: "minecraft:dirt".into() }];
|
| 654 |
+
assert_eq!(
|
| 655 |
+
dict_part_json("blocks", 0, &e),
|
| 656 |
+
json!({ "index": 0, "blocks": { "0000": "minecraft:dirt" } })
|
| 657 |
+
);
|
| 658 |
+
assert_eq!(
|
| 659 |
+
dict_part_json("nbt", 2, &e),
|
| 660 |
+
json!({ "index": 2, "nbt": { "0000": "minecraft:dirt" } })
|
| 661 |
+
);
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
#[test]
|
| 665 |
+
fn split_dict_empty() {
|
| 666 |
+
assert!(split_dict(&[], DICT_PART_JSON_MAX).unwrap().is_empty());
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
#[test]
|
| 670 |
+
fn split_dict_single_part() {
|
| 671 |
+
let e = entries(10, 20);
|
| 672 |
+
let parts = split_dict(&e, DICT_PART_JSON_MAX).unwrap();
|
| 673 |
+
assert_eq!(parts, vec![e]);
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
#[test]
|
| 677 |
+
fn split_dict_respects_limit_and_keeps_order() {
|
| 678 |
+
let e = entries(3000, 40);
|
| 679 |
+
let parts = split_dict(&e, DICT_PART_JSON_MAX).unwrap();
|
| 680 |
+
assert!(parts.len() > 1);
|
| 681 |
+
for (i, p) in parts.iter().enumerate() {
|
| 682 |
+
assert!(!p.is_empty());
|
| 683 |
+
assert!(json_len(i, p) <= DICT_PART_JSON_MAX, "часть {i}: {}", json_len(i, p));
|
| 684 |
+
}
|
| 685 |
+
let flat: Vec<DictEntry> = parts.into_iter().flatten().collect();
|
| 686 |
+
assert_eq!(flat, e);
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
#[test]
|
| 690 |
+
fn split_dict_small_limit_boundary() {
|
| 691 |
+
let e = entries(5, 10);
|
| 692 |
+
let one = entry_json_len(&e[0]);
|
| 693 |
+
assert_eq!(split_dict(&e, DICT_JSON_RESERVE + one).unwrap().len(), 5);
|
| 694 |
+
assert_eq!(split_dict(&e, DICT_JSON_RESERVE + one * 2).unwrap().len(), 3);
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
#[test]
|
| 698 |
+
fn split_dict_entry_too_long() {
|
| 699 |
+
let e = vec![DictEntry { key: "0000".into(), value: "x".repeat(30_000) }];
|
| 700 |
+
assert!(matches!(
|
| 701 |
+
split_dict(&e, DICT_PART_JSON_MAX),
|
| 702 |
+
Err(EncodeError::EntryTooLong(_))
|
| 703 |
+
));
|
| 704 |
+
}
|
| 705 |
+
}
|
src/src/http.rs
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! HTTP-роуты.
|
| 2 |
+
|
| 3 |
+
use std::sync::atomic::{AtomicBool, Ordering};
|
| 4 |
+
use std::sync::Arc;
|
| 5 |
+
use std::time::{Duration, Instant};
|
| 6 |
+
|
| 7 |
+
use axum::{
|
| 8 |
+
body::Bytes,
|
| 9 |
+
extract::{DefaultBodyLimit, Path, RawQuery, State},
|
| 10 |
+
http::StatusCode,
|
| 11 |
+
response::{IntoResponse, Response},
|
| 12 |
+
routing::{get, post},
|
| 13 |
+
Json, Router,
|
| 14 |
+
};
|
| 15 |
+
use serde_json::{json, Value};
|
| 16 |
+
use tracing::{info, warn};
|
| 17 |
+
use uuid::Uuid;
|
| 18 |
+
|
| 19 |
+
use crate::encoder;
|
| 20 |
+
use crate::loader::{self, LoaderConfig};
|
| 21 |
+
use crate::nbt;
|
| 22 |
+
use crate::store::{Schematic, Store};
|
| 23 |
+
|
| 24 |
+
/// Жёсткий срок на весь `/upload` (скачивание + разбор + кодирование).
|
| 25 |
+
/// Меньше клиентского таймаута в 3 с: клиент всегда получает ответ.
|
| 26 |
+
pub const UPLOAD_DEADLINE: Duration = Duration::from_millis(2500);
|
| 27 |
+
|
| 28 |
+
#[derive(Clone)]
|
| 29 |
+
pub struct AppState {
|
| 30 |
+
pub store: Store,
|
| 31 |
+
pub client: reqwest::Client,
|
| 32 |
+
pub loader: Arc<LoaderConfig>,
|
| 33 |
+
pub deadline: Duration,
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
impl AppState {
|
| 37 |
+
pub fn new(store: Store, client: reqwest::Client, loader: LoaderConfig) -> Self {
|
| 38 |
+
AppState {
|
| 39 |
+
store,
|
| 40 |
+
client,
|
| 41 |
+
loader: Arc::new(loader),
|
| 42 |
+
deadline: UPLOAD_DEADLINE,
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
#[derive(Debug)]
|
| 48 |
+
pub enum ApiError {
|
| 49 |
+
BadRequest(String),
|
| 50 |
+
NotFound(String),
|
| 51 |
+
Internal(String),
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
impl IntoResponse for ApiError {
|
| 55 |
+
fn into_response(self) -> Response {
|
| 56 |
+
let (status, message) = match self {
|
| 57 |
+
ApiError::BadRequest(m) => (StatusCode::BAD_REQUEST, m),
|
| 58 |
+
ApiError::NotFound(m) => (StatusCode::NOT_FOUND, m),
|
| 59 |
+
ApiError::Internal(m) => (StatusCode::INTERNAL_SERVER_ERROR, m),
|
| 60 |
+
};
|
| 61 |
+
(status, Json(json!({ "error": message }))).into_response()
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
pub fn router(state: AppState) -> Router {
|
| 66 |
+
Router::new()
|
| 67 |
+
.route("/", get(index))
|
| 68 |
+
.route("/upload", post(upload))
|
| 69 |
+
.route("/get/:uuid/blocks", get(blocks_info))
|
| 70 |
+
.route("/get/:uuid/blocks/:index", get(blocks_part))
|
| 71 |
+
.route("/get/:uuid/nbt", get(nbt_info))
|
| 72 |
+
.route("/get/:uuid/nbt/:index", get(nbt_part))
|
| 73 |
+
.route("/get/:uuid/parts", get(parts_info))
|
| 74 |
+
.route("/get/:uuid/parts/:index", get(parts_part))
|
| 75 |
+
.route("/:uuid/status", get(status))
|
| 76 |
+
.route("/get/:uuid/status", get(status))
|
| 77 |
+
// тело /upload — одна ссылка
|
| 78 |
+
.layer(DefaultBodyLimit::max(16 * 1024))
|
| 79 |
+
.with_state(state)
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
fn parse_uuid(s: &str) -> Result<Uuid, ApiError> {
|
| 83 |
+
Uuid::parse_str(s).map_err(|_| ApiError::BadRequest(format!("некорректный UUID: {s}")))
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
fn parse_index(s: &str) -> Result<usize, ApiError> {
|
| 87 |
+
s.parse::<usize>()
|
| 88 |
+
.map_err(|_| ApiError::BadRequest(format!("некорректный индекс: {s}")))
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
fn find(state: &AppState, uuid: &str) -> Result<Arc<Schematic>, ApiError> {
|
| 92 |
+
let id = parse_uuid(uuid)?;
|
| 93 |
+
state
|
| 94 |
+
.store
|
| 95 |
+
.get(&id)
|
| 96 |
+
.ok_or_else(|| ApiError::NotFound("схематика с таким UUID не найдена".into()))
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
fn out_of_range(index: usize) -> ApiError {
|
| 100 |
+
ApiError::NotFound(format!("индекс {index} вне диапазона"))
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
async fn index() -> Json<Value> {
|
| 104 |
+
Json(json!({
|
| 105 |
+
"service": "litematic-host",
|
| 106 |
+
"endpoints": [
|
| 107 |
+
"POST /upload?x=0&y=0&z=0",
|
| 108 |
+
"GET /get/{uuid}/blocks",
|
| 109 |
+
"GET /get/{uuid}/blocks/{index}",
|
| 110 |
+
"GET /get/{uuid}/nbt",
|
| 111 |
+
"GET /get/{uuid}/nbt/{index}",
|
| 112 |
+
"GET /get/{uuid}/parts",
|
| 113 |
+
"GET /get/{uuid}/parts/{index}",
|
| 114 |
+
"GET /{uuid}/status",
|
| 115 |
+
],
|
| 116 |
+
}))
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/// Сдвиг из query-строки `/upload?x=..&y=..&z=..`. Нет параметра — 0.
|
| 120 |
+
/// Неизвестные параметры игнорируются. Повтор параметра — побеждает последний.
|
| 121 |
+
fn parse_offset(query: Option<&str>) -> Result<[i32; 3], ApiError> {
|
| 122 |
+
let mut offset = [0i32; 3];
|
| 123 |
+
let Some(q) = query else {
|
| 124 |
+
return Ok(offset);
|
| 125 |
+
};
|
| 126 |
+
for pair in q.split('&').filter(|p| !p.is_empty()) {
|
| 127 |
+
let (key, value) = pair.split_once('=').unwrap_or((pair, ""));
|
| 128 |
+
let slot = match key {
|
| 129 |
+
"x" => 0,
|
| 130 |
+
"y" => 1,
|
| 131 |
+
"z" => 2,
|
| 132 |
+
_ => continue,
|
| 133 |
+
};
|
| 134 |
+
offset[slot] = value.parse::<i32>().map_err(|_| {
|
| 135 |
+
ApiError::BadRequest(format!(
|
| 136 |
+
"параметр {key} должен быть целым числом i32, получено: {value:?}"
|
| 137 |
+
))
|
| 138 |
+
})?;
|
| 139 |
+
}
|
| 140 |
+
Ok(offset)
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/// Скачивание + разбор + кодирование. Без таймаута — его ставит вызывающий.
|
| 144 |
+
async fn process(
|
| 145 |
+
state: &AppState,
|
| 146 |
+
url: reqwest::Url,
|
| 147 |
+
offset: [i32; 3],
|
| 148 |
+
cancel: Arc<AtomicBool>,
|
| 149 |
+
) -> Result<Schematic, ApiError> {
|
| 150 |
+
let data = loader::download(&state.client, url, &state.loader)
|
| 151 |
+
.await
|
| 152 |
+
.map_err(|e| {
|
| 153 |
+
warn!(error = %e, "ошибка скачивания");
|
| 154 |
+
ApiError::BadRequest(e.to_string())
|
| 155 |
+
})?;
|
| 156 |
+
info!(bytes = data.len(), "файл скачан, разбор");
|
| 157 |
+
|
| 158 |
+
// CPU-работа уходит с async-потока. Поток нельзя отменить снаружи,
|
| 159 |
+
// поэтому он сам проверяет флаг `cancel` на каждом слое по y.
|
| 160 |
+
tokio::task::spawn_blocking(move || -> Result<Schematic, String> {
|
| 161 |
+
let groups = nbt::parse_litematic_gz(&data, &nbt::Limits::default(), offset, &cancel)
|
| 162 |
+
.map_err(|e| e.to_string())?;
|
| 163 |
+
Schematic::build(&groups).map_err(|e| e.to_string())
|
| 164 |
+
})
|
| 165 |
+
.await
|
| 166 |
+
.map_err(|e| ApiError::Internal(format!("внутренняя ошибка: {e}")))?
|
| 167 |
+
.map_err(|e| {
|
| 168 |
+
warn!(error = %e, "ошибка разбора");
|
| 169 |
+
ApiError::BadRequest(e)
|
| 170 |
+
})
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
async fn upload(
|
| 174 |
+
State(state): State<AppState>,
|
| 175 |
+
RawQuery(query): RawQuery,
|
| 176 |
+
body: Bytes,
|
| 177 |
+
) -> Result<Json<String>, ApiError> {
|
| 178 |
+
let offset = parse_offset(query.as_deref())?;
|
| 179 |
+
let text = std::str::from_utf8(&body)
|
| 180 |
+
.map_err(|_| ApiError::BadRequest("тело запроса должно быть текстом UTF-8 со ссылкой".into()))?;
|
| 181 |
+
let url = loader::parse_url(text).map_err(|e| ApiError::BadRequest(e.to_string()))?;
|
| 182 |
+
let host = url.host_str().unwrap_or("?").to_string();
|
| 183 |
+
info!(%host, ?offset, "загрузка");
|
| 184 |
+
|
| 185 |
+
let started = Instant::now();
|
| 186 |
+
let cancel = Arc::new(AtomicBool::new(false));
|
| 187 |
+
let schematic = match tokio::time::timeout(state.deadline, process(&state, url, offset, cancel.clone())).await {
|
| 188 |
+
Ok(result) => result?,
|
| 189 |
+
Err(_) => {
|
| 190 |
+
cancel.store(true, Ordering::Relaxed);
|
| 191 |
+
warn!(%host, "не уложились в срок");
|
| 192 |
+
return Err(ApiError::BadRequest(format!(
|
| 193 |
+
"обработка не уложилась в {} мс: файл слишком большой или источник слишком медленный",
|
| 194 |
+
state.deadline.as_millis()
|
| 195 |
+
)));
|
| 196 |
+
}
|
| 197 |
+
};
|
| 198 |
+
|
| 199 |
+
let unique = schematic.unique_blocks;
|
| 200 |
+
let parts = schematic.part_ends.len();
|
| 201 |
+
let id = state.store.insert(schematic);
|
| 202 |
+
info!(
|
| 203 |
+
%id,
|
| 204 |
+
unique_blocks = unique,
|
| 205 |
+
parts,
|
| 206 |
+
elapsed_ms = started.elapsed().as_millis() as u64,
|
| 207 |
+
"схематика сохранена"
|
| 208 |
+
);
|
| 209 |
+
Ok(Json(id.to_string()))
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
async fn blocks_info(
|
| 213 |
+
State(state): State<AppState>,
|
| 214 |
+
Path(uuid): Path<String>,
|
| 215 |
+
) -> Result<Json<Value>, ApiError> {
|
| 216 |
+
let s = find(&state, &uuid)?;
|
| 217 |
+
Ok(Json(json!({
|
| 218 |
+
"unique_blocks": s.unique_blocks,
|
| 219 |
+
"parts": s.block_parts.len(),
|
| 220 |
+
})))
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
async fn blocks_part(
|
| 224 |
+
State(state): State<AppState>,
|
| 225 |
+
Path((uuid, index)): Path<(String, String)>,
|
| 226 |
+
) -> Result<Json<Value>, ApiError> {
|
| 227 |
+
let s = find(&state, &uuid)?;
|
| 228 |
+
let i = parse_index(&index)?;
|
| 229 |
+
let part = s.block_parts.get(i).ok_or_else(|| out_of_range(i))?;
|
| 230 |
+
Ok(Json(encoder::dict_part_json("blocks", i, part)))
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
async fn nbt_info(
|
| 234 |
+
State(state): State<AppState>,
|
| 235 |
+
Path(uuid): Path<String>,
|
| 236 |
+
) -> Result<Json<Value>, ApiError> {
|
| 237 |
+
let s = find(&state, &uuid)?;
|
| 238 |
+
Ok(Json(json!({
|
| 239 |
+
"unique_nbt": s.unique_nbt,
|
| 240 |
+
"parts": s.nbt_parts.len(),
|
| 241 |
+
})))
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
async fn nbt_part(
|
| 245 |
+
State(state): State<AppState>,
|
| 246 |
+
Path((uuid, index)): Path<(String, String)>,
|
| 247 |
+
) -> Result<Json<Value>, ApiError> {
|
| 248 |
+
let s = find(&state, &uuid)?;
|
| 249 |
+
let i = parse_index(&index)?;
|
| 250 |
+
let part = s.nbt_parts.get(i).ok_or_else(|| out_of_range(i))?;
|
| 251 |
+
Ok(Json(encoder::dict_part_json("nbt", i, part)))
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
async fn parts_info(
|
| 255 |
+
State(state): State<AppState>,
|
| 256 |
+
Path(uuid): Path<String>,
|
| 257 |
+
) -> Result<Json<Value>, ApiError> {
|
| 258 |
+
let s = find(&state, &uuid)?;
|
| 259 |
+
Ok(Json(json!({ "parts": s.part_ends.len() })))
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
async fn parts_part(
|
| 263 |
+
State(state): State<AppState>,
|
| 264 |
+
Path((uuid, index)): Path<(String, String)>,
|
| 265 |
+
) -> Result<Json<Value>, ApiError> {
|
| 266 |
+
let s = find(&state, &uuid)?;
|
| 267 |
+
let i = parse_index(&index)?;
|
| 268 |
+
let chunk = encoder::text_part(&s.text, &s.part_ends, i).ok_or_else(|| out_of_range(i))?;
|
| 269 |
+
Ok(Json(json!({ "index": i, "data": chunk })))
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
/// Схематика разбирается прямо в `/upload`, поэтому любая найденная — готова.
|
| 273 |
+
async fn status(
|
| 274 |
+
State(state): State<AppState>,
|
| 275 |
+
Path(uuid): Path<String>,
|
| 276 |
+
) -> Result<Json<Value>, ApiError> {
|
| 277 |
+
let s = find(&state, &uuid)?;
|
| 278 |
+
Ok(Json(json!({
|
| 279 |
+
"status": "ready",
|
| 280 |
+
"unique_blocks": s.unique_blocks,
|
| 281 |
+
"unique_nbt": s.unique_nbt,
|
| 282 |
+
"blocks_parts": s.block_parts.len(),
|
| 283 |
+
"nbt_parts": s.nbt_parts.len(),
|
| 284 |
+
"parts": s.part_ends.len(),
|
| 285 |
+
"text_chars": s.text.len(),
|
| 286 |
+
})))
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
#[cfg(test)]
|
| 290 |
+
mod tests {
|
| 291 |
+
use super::*;
|
| 292 |
+
use crate::encoder::Groups;
|
| 293 |
+
use axum::body::Body;
|
| 294 |
+
use axum::http::Request;
|
| 295 |
+
use http_body_util::BodyExt;
|
| 296 |
+
use tower::ServiceExt;
|
| 297 |
+
|
| 298 |
+
fn app() -> (Router, AppState) {
|
| 299 |
+
let cfg = LoaderConfig::default();
|
| 300 |
+
let client = loader::build_client(&cfg).unwrap();
|
| 301 |
+
let state = AppState::new(Store::default(), client, cfg);
|
| 302 |
+
(router(state.clone()), state)
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
async fn call(app: &Router, req: Request<Body>) -> (StatusCode, String) {
|
| 306 |
+
let resp = app.clone().oneshot(req).await.unwrap();
|
| 307 |
+
let status = resp.status();
|
| 308 |
+
let bytes = resp.into_body().collect().await.unwrap().to_bytes();
|
| 309 |
+
(status, String::from_utf8(bytes.to_vec()).unwrap())
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
async fn get_json(app: &Router, uri: &str) -> (StatusCode, Value) {
|
| 313 |
+
let req = Request::builder().uri(uri).body(Body::empty()).unwrap();
|
| 314 |
+
let (status, body) = call(app, req).await;
|
| 315 |
+
(status, serde_json::from_str(&body).unwrap())
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
fn cells(list: &[(i32, i32, i32)]) -> Vec<u8> {
|
| 319 |
+
let mut b = Vec::new();
|
| 320 |
+
for &(x, y, z) in list {
|
| 321 |
+
encoder::push_position(&mut b, x, y, z).unwrap();
|
| 322 |
+
}
|
| 323 |
+
b
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
fn header(k: usize, n: usize, l: usize) -> String {
|
| 327 |
+
format!(r#"{{"k":{k:04},"n":{n:04},"l":{l:04}}}"#)
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
fn pos(x: &str, y: &str, z: &str) -> String {
|
| 331 |
+
format!(r#"{{"x":{x},"y":{y},"z":{z}}}"#)
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
/// chest с NBT в (1,1,1); dirt в (5,5,5); stone в (0,0,0) и (-1,2,3).
|
| 335 |
+
fn sample_groups() -> Groups {
|
| 336 |
+
let mut g = Groups::new();
|
| 337 |
+
g.insert(
|
| 338 |
+
("chest".into(), r#"{id:"minecraft:chest"}"#.into()),
|
| 339 |
+
cells(&[(1, 1, 1)]),
|
| 340 |
+
);
|
| 341 |
+
g.insert(("dirt".into(), String::new()), cells(&[(5, 5, 5)]));
|
| 342 |
+
g.insert(
|
| 343 |
+
("stone".into(), String::new()),
|
| 344 |
+
cells(&[(0, 0, 0), (-1, 2, 3)]),
|
| 345 |
+
);
|
| 346 |
+
g
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
fn sample_id(state: &AppState) -> Uuid {
|
| 350 |
+
state.store.insert(Schematic::build(&sample_groups()).unwrap())
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
#[tokio::test]
|
| 354 |
+
async fn full_read_cycle() {
|
| 355 |
+
let (app, state) = app();
|
| 356 |
+
let id = sample_id(&state);
|
| 357 |
+
|
| 358 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/blocks")).await;
|
| 359 |
+
assert_eq!(st, StatusCode::OK);
|
| 360 |
+
assert_eq!(v, json!({ "unique_blocks": 3, "parts": 1 }));
|
| 361 |
+
|
| 362 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/blocks/0")).await;
|
| 363 |
+
assert_eq!(st, StatusCode::OK);
|
| 364 |
+
assert_eq!(v["index"], 0);
|
| 365 |
+
assert_eq!(
|
| 366 |
+
v["blocks"],
|
| 367 |
+
json!({
|
| 368 |
+
"0000": "chest",
|
| 369 |
+
"0001": "dirt",
|
| 370 |
+
"0002": "stone",
|
| 371 |
+
})
|
| 372 |
+
);
|
| 373 |
+
|
| 374 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/nbt")).await;
|
| 375 |
+
assert_eq!(st, StatusCode::OK);
|
| 376 |
+
assert_eq!(v, json!({ "unique_nbt": 1, "parts": 1 }));
|
| 377 |
+
|
| 378 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/nbt/0")).await;
|
| 379 |
+
assert_eq!(st, StatusCode::OK);
|
| 380 |
+
assert_eq!(v["nbt"], json!({ "0001": r#"{id:"minecraft:chest"}"# }));
|
| 381 |
+
|
| 382 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/parts")).await;
|
| 383 |
+
assert_eq!(st, StatusCode::OK);
|
| 384 |
+
assert_eq!(v, json!({ "parts": 1 }));
|
| 385 |
+
|
| 386 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/parts/0")).await;
|
| 387 |
+
assert_eq!(st, StatusCode::OK);
|
| 388 |
+
let expected = [
|
| 389 |
+
header(0, 1, 1),
|
| 390 |
+
pos("0001", "0001", "0001"),
|
| 391 |
+
header(1, 0, 1),
|
| 392 |
+
pos("0005", "0005", "0005"),
|
| 393 |
+
header(2, 0, 2),
|
| 394 |
+
pos("0000", "0000", "0000"),
|
| 395 |
+
pos("-001", "0002", "0003"),
|
| 396 |
+
]
|
| 397 |
+
.concat();
|
| 398 |
+
assert_eq!(v["index"], 0);
|
| 399 |
+
assert_eq!(v["data"], json!(expected));
|
| 400 |
+
assert_eq!(expected.len(), 7 * 28);
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
#[tokio::test]
|
| 404 |
+
async fn index_out_of_range_is_404() {
|
| 405 |
+
let (app, state) = app();
|
| 406 |
+
let id = sample_id(&state);
|
| 407 |
+
for tail in ["blocks/1", "nbt/1", "parts/1"] {
|
| 408 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/{tail}")).await;
|
| 409 |
+
assert_eq!(st, StatusCode::NOT_FOUND, "{tail}");
|
| 410 |
+
assert!(v["error"].is_string());
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
#[tokio::test]
|
| 415 |
+
async fn unknown_uuid_is_404() {
|
| 416 |
+
let (app, _) = app();
|
| 417 |
+
let id = Uuid::new_v4();
|
| 418 |
+
for tail in ["blocks", "blocks/0", "nbt", "nbt/0", "parts", "parts/0"] {
|
| 419 |
+
let (st, _) = get_json(&app, &format!("/get/{id}/{tail}")).await;
|
| 420 |
+
assert_eq!(st, StatusCode::NOT_FOUND, "{tail}");
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
#[tokio::test]
|
| 425 |
+
async fn bad_uuid_is_400() {
|
| 426 |
+
let (app, _) = app();
|
| 427 |
+
for tail in ["blocks", "blocks/0", "nbt", "nbt/0", "parts", "parts/0"] {
|
| 428 |
+
let (st, _) = get_json(&app, &format!("/get/not-a-uuid/{tail}")).await;
|
| 429 |
+
assert_eq!(st, StatusCode::BAD_REQUEST, "{tail}");
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
#[tokio::test]
|
| 434 |
+
async fn status_endpoint() {
|
| 435 |
+
let (app, state) = app();
|
| 436 |
+
let id = sample_id(&state);
|
| 437 |
+
for uri in [format!("/{id}/status"), format!("/get/{id}/status")] {
|
| 438 |
+
let (st, v) = get_json(&app, &uri).await;
|
| 439 |
+
assert_eq!(st, StatusCode::OK, "{uri}");
|
| 440 |
+
assert_eq!(
|
| 441 |
+
v,
|
| 442 |
+
json!({
|
| 443 |
+
"status": "ready",
|
| 444 |
+
"unique_blocks": 3,
|
| 445 |
+
"unique_nbt": 1,
|
| 446 |
+
"blocks_parts": 1,
|
| 447 |
+
"nbt_parts": 1,
|
| 448 |
+
"parts": 1,
|
| 449 |
+
"text_chars": 196,
|
| 450 |
+
})
|
| 451 |
+
);
|
| 452 |
+
}
|
| 453 |
+
let (st, _) = get_json(&app, &format!("/{}/status", Uuid::new_v4())).await;
|
| 454 |
+
assert_eq!(st, StatusCode::NOT_FOUND);
|
| 455 |
+
let (st, _) = get_json(&app, "/not-a-uuid/status").await;
|
| 456 |
+
assert_eq!(st, StatusCode::BAD_REQUEST);
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
#[tokio::test]
|
| 460 |
+
async fn bad_index_is_400() {
|
| 461 |
+
let (app, state) = app();
|
| 462 |
+
let id = sample_id(&state);
|
| 463 |
+
let (st, _) = get_json(&app, &format!("/get/{id}/parts/abc")).await;
|
| 464 |
+
assert_eq!(st, StatusCode::BAD_REQUEST);
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
#[tokio::test]
|
| 468 |
+
async fn empty_schematic_has_zero_parts() {
|
| 469 |
+
let (app, state) = app();
|
| 470 |
+
let id = state.store.insert(Schematic::build(&Groups::new()).unwrap());
|
| 471 |
+
let (_, v) = get_json(&app, &format!("/get/{id}/blocks")).await;
|
| 472 |
+
assert_eq!(v, json!({ "unique_blocks": 0, "parts": 0 }));
|
| 473 |
+
let (_, v) = get_json(&app, &format!("/get/{id}/nbt")).await;
|
| 474 |
+
assert_eq!(v, json!({ "unique_nbt": 0, "parts": 0 }));
|
| 475 |
+
let (_, v) = get_json(&app, &format!("/get/{id}/parts")).await;
|
| 476 |
+
assert_eq!(v, json!({ "parts": 0 }));
|
| 477 |
+
let (st, _) = get_json(&app, &format!("/get/{id}/parts/0")).await;
|
| 478 |
+
assert_eq!(st, StatusCode::NOT_FOUND);
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
#[tokio::test]
|
| 482 |
+
async fn long_run_is_split_across_parts_with_new_headers() {
|
| 483 |
+
let (app, state) = app();
|
| 484 |
+
let mut g = Groups::new();
|
| 485 |
+
let list: Vec<(i32, i32, i32)> = (0..2000).map(|i| (i, 0, 0)).collect();
|
| 486 |
+
g.insert(("stone".into(), String::new()), cells(&list));
|
| 487 |
+
let id = state.store.insert(Schematic::build(&g).unwrap());
|
| 488 |
+
|
| 489 |
+
let (_, v) = get_json(&app, &format!("/get/{id}/parts")).await;
|
| 490 |
+
assert_eq!(v, json!({ "parts": 3 }));
|
| 491 |
+
|
| 492 |
+
// 856 + 856 + 288 позиций, перед каждой серией свой заголовок
|
| 493 |
+
let sizes = [857 * 28, 857 * 28, 289 * 28];
|
| 494 |
+
let counts = [856usize, 856, 288];
|
| 495 |
+
for i in 0..3 {
|
| 496 |
+
let (st, v) = get_json(&app, &format!("/get/{id}/parts/{i}")).await;
|
| 497 |
+
assert_eq!(st, StatusCode::OK);
|
| 498 |
+
let data = v["data"].as_str().unwrap();
|
| 499 |
+
assert_eq!(data.len(), sizes[i]);
|
| 500 |
+
assert_eq!(&data[..28], header(0, 0, counts[i]));
|
| 501 |
+
}
|
| 502 |
+
let (st, _) = get_json(&app, &format!("/get/{id}/parts/3")).await;
|
| 503 |
+
assert_eq!(st, StatusCode::NOT_FOUND);
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
#[test]
|
| 508 |
+
fn offset_parsing() {
|
| 509 |
+
assert_eq!(parse_offset(None).unwrap(), [0, 0, 0]);
|
| 510 |
+
assert_eq!(parse_offset(Some("")).unwrap(), [0, 0, 0]);
|
| 511 |
+
assert_eq!(parse_offset(Some("x=1&y=-2&z=3")).unwrap(), [1, -2, 3]);
|
| 512 |
+
assert_eq!(parse_offset(Some("y=5")).unwrap(), [0, 5, 0]);
|
| 513 |
+
assert_eq!(parse_offset(Some("foo=1&z=2")).unwrap(), [0, 0, 2]);
|
| 514 |
+
assert_eq!(parse_offset(Some("x=1&x=2")).unwrap(), [2, 0, 0]);
|
| 515 |
+
assert_eq!(parse_offset(Some("x=+7")).unwrap(), [7, 0, 0]);
|
| 516 |
+
for bad in ["x=abc", "x=", "y=1.5", "z=99999999999", "x"] {
|
| 517 |
+
assert!(
|
| 518 |
+
matches!(parse_offset(Some(bad)), Err(ApiError::BadRequest(_))),
|
| 519 |
+
"{bad}"
|
| 520 |
+
);
|
| 521 |
+
}
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
#[tokio::test]
|
| 525 |
+
async fn upload_rejects_bad_offset() {
|
| 526 |
+
let (app, _) = app();
|
| 527 |
+
for uri in ["/upload?x=abc", "/upload?y=1.5", "/upload?x=1&z=99999999999"] {
|
| 528 |
+
let req = Request::builder()
|
| 529 |
+
.method("POST")
|
| 530 |
+
.uri(uri)
|
| 531 |
+
.body(Body::from("https://example.com/a.litematic"))
|
| 532 |
+
.unwrap();
|
| 533 |
+
let (st, text) = call(&app, req).await;
|
| 534 |
+
assert_eq!(st, StatusCode::BAD_REQUEST, "{uri}");
|
| 535 |
+
let v: Value = serde_json::from_str(&text).unwrap();
|
| 536 |
+
assert!(v["error"].as_str().unwrap().contains("параметр"));
|
| 537 |
+
}
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
#[tokio::test]
|
| 541 |
+
async fn upload_accepts_offset_in_query() {
|
| 542 |
+
// ссылка локальная — отклоняется по ссылке, а не по сдвигу
|
| 543 |
+
let (app, _) = app();
|
| 544 |
+
let req = Request::builder()
|
| 545 |
+
.method("POST")
|
| 546 |
+
.uri("/upload?x=100&y=64&z=-20")
|
| 547 |
+
.body(Body::from("http://127.0.0.1:1/a.litematic"))
|
| 548 |
+
.unwrap();
|
| 549 |
+
let (st, text) = call(&app, req).await;
|
| 550 |
+
assert_eq!(st, StatusCode::BAD_REQUEST);
|
| 551 |
+
let v: Value = serde_json::from_str(&text).unwrap();
|
| 552 |
+
assert!(!v["error"].as_str().unwrap().contains("параметр"));
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
#[tokio::test]
|
| 556 |
+
async fn upload_rejects_bad_links() {
|
| 557 |
+
let (app, _) = app();
|
| 558 |
+
for body in ["", "not a url", "ftp://example.com/a.litematic", "http://127.0.0.1:1/a.litematic"] {
|
| 559 |
+
let req = Request::builder()
|
| 560 |
+
.method("POST")
|
| 561 |
+
.uri("/upload")
|
| 562 |
+
.body(Body::from(body))
|
| 563 |
+
.unwrap();
|
| 564 |
+
let (st, text) = call(&app, req).await;
|
| 565 |
+
assert_eq!(st, StatusCode::BAD_REQUEST, "{body:?}");
|
| 566 |
+
let v: Value = serde_json::from_str(&text).unwrap();
|
| 567 |
+
assert!(v["error"].as_str().unwrap().len() > 5);
|
| 568 |
+
}
|
| 569 |
+
}
|
| 570 |
+
}
|
src/src/loader.rs
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! Скачивание файла по ссылке: лимит размера, таймаут, защита от обращений во внутреннюю сеть.
|
| 2 |
+
|
| 3 |
+
use std::fmt;
|
| 4 |
+
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
| 5 |
+
use std::time::Duration;
|
| 6 |
+
|
| 7 |
+
use reqwest::{redirect, Client, Url};
|
| 8 |
+
|
| 9 |
+
#[derive(Debug, Clone)]
|
| 10 |
+
pub struct LoaderConfig {
|
| 11 |
+
pub max_bytes: usize,
|
| 12 |
+
pub timeout: Duration,
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
impl Default for LoaderConfig {
|
| 16 |
+
fn default() -> Self {
|
| 17 |
+
LoaderConfig {
|
| 18 |
+
max_bytes: 10 * 1024 * 1024,
|
| 19 |
+
timeout: Duration::from_millis(1500),
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
#[derive(Debug)]
|
| 25 |
+
pub enum LoadError {
|
| 26 |
+
InvalidUrl(String),
|
| 27 |
+
Forbidden(String),
|
| 28 |
+
Request(String),
|
| 29 |
+
Status(u16),
|
| 30 |
+
TooLarge(usize),
|
| 31 |
+
Timeout,
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
impl fmt::Display for LoadError {
|
| 35 |
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
| 36 |
+
match self {
|
| 37 |
+
LoadError::InvalidUrl(m) => write!(f, "некорректная ссылка: {m}"),
|
| 38 |
+
LoadError::Forbidden(m) => write!(f, "ссылка запрещена: {m}"),
|
| 39 |
+
LoadError::Request(m) => write!(f, "не удалось скачать файл: {m}"),
|
| 40 |
+
LoadError::Status(c) => write!(f, "сервер ответил кодом {c}"),
|
| 41 |
+
LoadError::TooLarge(n) => write!(f, "файл больше {n} байт"),
|
| 42 |
+
LoadError::Timeout => write!(f, "превышено время ожидания при скачивании"),
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
impl std::error::Error for LoadError {}
|
| 48 |
+
|
| 49 |
+
fn is_public_v4(ip: Ipv4Addr) -> bool {
|
| 50 |
+
let o = ip.octets();
|
| 51 |
+
!(ip.is_loopback()
|
| 52 |
+
|| ip.is_private()
|
| 53 |
+
|| ip.is_link_local()
|
| 54 |
+
|| ip.is_unspecified()
|
| 55 |
+
|| ip.is_broadcast()
|
| 56 |
+
|| ip.is_documentation()
|
| 57 |
+
|| o[0] == 0
|
| 58 |
+
|| (o[0] == 100 && (o[1] & 0xC0) == 64)) // 100.64.0.0/10
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
fn is_public_v6(ip: Ipv6Addr) -> bool {
|
| 62 |
+
if let Some(v4) = ip.to_ipv4_mapped() {
|
| 63 |
+
return is_public_v4(v4);
|
| 64 |
+
}
|
| 65 |
+
let s = ip.segments();
|
| 66 |
+
!(ip.is_loopback()
|
| 67 |
+
|| ip.is_unspecified()
|
| 68 |
+
|| (s[0] & 0xfe00) == 0xfc00 // fc00::/7
|
| 69 |
+
|| (s[0] & 0xffc0) == 0xfe80) // fe80::/10
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/// Разрешён ли хост: только публичные адреса, без localhost и служебных зон.
|
| 73 |
+
/// DNS-имена, резолвящиеся во внутренние адреса, эта проверка не ловит.
|
| 74 |
+
pub fn host_allowed(url: &Url) -> bool {
|
| 75 |
+
if !matches!(url.scheme(), "http" | "https") {
|
| 76 |
+
return false;
|
| 77 |
+
}
|
| 78 |
+
let host = match url.host_str() {
|
| 79 |
+
Some(h) => h.trim_start_matches('[').trim_end_matches(']').to_ascii_lowercase(),
|
| 80 |
+
None => return false,
|
| 81 |
+
};
|
| 82 |
+
if let Ok(ip) = host.parse::<IpAddr>() {
|
| 83 |
+
return match ip {
|
| 84 |
+
IpAddr::V4(v4) => is_public_v4(v4),
|
| 85 |
+
IpAddr::V6(v6) => is_public_v6(v6),
|
| 86 |
+
};
|
| 87 |
+
}
|
| 88 |
+
!(host == "localhost"
|
| 89 |
+
|| host.ends_with(".localhost")
|
| 90 |
+
|| host.ends_with(".local")
|
| 91 |
+
|| host.ends_with(".internal"))
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/// Тело запроса → проверенный URL.
|
| 95 |
+
pub fn parse_url(text: &str) -> Result<Url, LoadError> {
|
| 96 |
+
let t = text.trim();
|
| 97 |
+
if t.is_empty() {
|
| 98 |
+
return Err(LoadError::InvalidUrl("пустое тело запроса, ожидается прямая ссылка".into()));
|
| 99 |
+
}
|
| 100 |
+
let url = Url::parse(t).map_err(|e| LoadError::InvalidUrl(e.to_string()))?;
|
| 101 |
+
if !matches!(url.scheme(), "http" | "https") {
|
| 102 |
+
return Err(LoadError::InvalidUrl("поддерживаются только http и https".into()));
|
| 103 |
+
}
|
| 104 |
+
if !host_allowed(&url) {
|
| 105 |
+
return Err(LoadError::Forbidden("адрес локальный или служебный".into()));
|
| 106 |
+
}
|
| 107 |
+
Ok(url)
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
pub fn build_client(cfg: &LoaderConfig) -> Result<Client, reqwest::Error> {
|
| 111 |
+
let policy = redirect::Policy::custom(|attempt| {
|
| 112 |
+
if attempt.previous().len() >= 5 {
|
| 113 |
+
attempt.error("слишком много перенаправлений")
|
| 114 |
+
} else if !host_allowed(attempt.url()) {
|
| 115 |
+
attempt.error("перенаправление на запрещённый адрес")
|
| 116 |
+
} else {
|
| 117 |
+
attempt.follow()
|
| 118 |
+
}
|
| 119 |
+
});
|
| 120 |
+
Client::builder()
|
| 121 |
+
.timeout(cfg.timeout)
|
| 122 |
+
.connect_timeout(Duration::from_millis(1000))
|
| 123 |
+
.redirect(policy)
|
| 124 |
+
.user_agent("litematic-host/0.1")
|
| 125 |
+
.build()
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
fn map_err(e: reqwest::Error) -> LoadError {
|
| 129 |
+
if e.is_timeout() {
|
| 130 |
+
LoadError::Timeout
|
| 131 |
+
} else {
|
| 132 |
+
LoadError::Request(e.to_string())
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
/// Скачивает файл, не читая больше `cfg.max_bytes`.
|
| 137 |
+
pub async fn download(client: &Client, url: Url, cfg: &LoaderConfig) -> Result<Vec<u8>, LoadError> {
|
| 138 |
+
let mut resp = client.get(url).send().await.map_err(map_err)?;
|
| 139 |
+
if !resp.status().is_success() {
|
| 140 |
+
return Err(LoadError::Status(resp.status().as_u16()));
|
| 141 |
+
}
|
| 142 |
+
if let Some(len) = resp.content_length() {
|
| 143 |
+
if len > cfg.max_bytes as u64 {
|
| 144 |
+
return Err(LoadError::TooLarge(cfg.max_bytes));
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
let mut buf: Vec<u8> = Vec::new();
|
| 148 |
+
while let Some(chunk) = resp.chunk().await.map_err(map_err)? {
|
| 149 |
+
if buf.len() + chunk.len() > cfg.max_bytes {
|
| 150 |
+
return Err(LoadError::TooLarge(cfg.max_bytes));
|
| 151 |
+
}
|
| 152 |
+
buf.extend_from_slice(&chunk);
|
| 153 |
+
}
|
| 154 |
+
Ok(buf)
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
#[cfg(test)]
|
| 158 |
+
mod tests {
|
| 159 |
+
use super::*;
|
| 160 |
+
|
| 161 |
+
#[test]
|
| 162 |
+
fn accepts_public_urls() {
|
| 163 |
+
assert!(parse_url("https://example.com/a.litematic").is_ok());
|
| 164 |
+
assert!(parse_url(" http://8.8.8.8/x \n").is_ok());
|
| 165 |
+
assert!(parse_url("https://cdn.example.com/file?id=1&x=2").is_ok());
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
#[test]
|
| 169 |
+
fn rejects_bad_input() {
|
| 170 |
+
assert!(matches!(parse_url(""), Err(LoadError::InvalidUrl(_))));
|
| 171 |
+
assert!(matches!(parse_url(" "), Err(LoadError::InvalidUrl(_))));
|
| 172 |
+
assert!(matches!(parse_url("not a url"), Err(LoadError::InvalidUrl(_))));
|
| 173 |
+
assert!(matches!(parse_url("ftp://example.com/a"), Err(LoadError::InvalidUrl(_))));
|
| 174 |
+
assert!(matches!(parse_url("file:///etc/passwd"), Err(LoadError::InvalidUrl(_))));
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
#[test]
|
| 178 |
+
fn rejects_internal_hosts() {
|
| 179 |
+
for u in [
|
| 180 |
+
"http://localhost/x",
|
| 181 |
+
"http://foo.localhost/x",
|
| 182 |
+
"http://127.0.0.1:8080/x",
|
| 183 |
+
"http://10.0.0.1/",
|
| 184 |
+
"http://192.168.1.1/",
|
| 185 |
+
"http://172.16.0.1/",
|
| 186 |
+
"http://169.254.169.254/latest/meta-data",
|
| 187 |
+
"http://100.64.0.1/",
|
| 188 |
+
"http://0.0.0.0/",
|
| 189 |
+
"http://[::1]/",
|
| 190 |
+
"http://[fe80::1]/",
|
| 191 |
+
"http://[fd00::1]/",
|
| 192 |
+
"http://[::ffff:127.0.0.1]/",
|
| 193 |
+
"http://2130706433/",
|
| 194 |
+
"http://printer.local/",
|
| 195 |
+
] {
|
| 196 |
+
assert!(matches!(parse_url(u), Err(LoadError::Forbidden(_))), "{u}");
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
}
|
src/src/main.rs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mod encoder;
|
| 2 |
+
mod http;
|
| 3 |
+
mod loader;
|
| 4 |
+
mod nbt;
|
| 5 |
+
mod store;
|
| 6 |
+
|
| 7 |
+
use std::net::SocketAddr;
|
| 8 |
+
|
| 9 |
+
use tracing::info;
|
| 10 |
+
use tracing_subscriber::EnvFilter;
|
| 11 |
+
|
| 12 |
+
#[tokio::main]
|
| 13 |
+
async fn main() {
|
| 14 |
+
tracing_subscriber::fmt()
|
| 15 |
+
.with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")))
|
| 16 |
+
.init();
|
| 17 |
+
|
| 18 |
+
let port = std::env::var("PORT")
|
| 19 |
+
.ok()
|
| 20 |
+
.and_then(|p| p.parse::<u16>().ok())
|
| 21 |
+
.unwrap_or(7860);
|
| 22 |
+
let addr = SocketAddr::from(([0, 0, 0, 0], port));
|
| 23 |
+
|
| 24 |
+
let loader_cfg = loader::LoaderConfig::default();
|
| 25 |
+
let client = loader::build_client(&loader_cfg).expect("не удалось создать HTTP-клиент");
|
| 26 |
+
let state = http::AppState::new(store::Store::default(), client, loader_cfg);
|
| 27 |
+
let app = http::router(state);
|
| 28 |
+
|
| 29 |
+
let listener = tokio::net::TcpListener::bind(addr)
|
| 30 |
+
.await
|
| 31 |
+
.expect("не удалось занять порт");
|
| 32 |
+
info!(%addr, "сервис запущен");
|
| 33 |
+
axum::serve(listener, app)
|
| 34 |
+
.with_graceful_shutdown(shutdown_signal())
|
| 35 |
+
.await
|
| 36 |
+
.expect("ошибка сервера");
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
async fn shutdown_signal() {
|
| 40 |
+
let ctrl_c = async {
|
| 41 |
+
let _ = tokio::signal::ctrl_c().await;
|
| 42 |
+
};
|
| 43 |
+
#[cfg(unix)]
|
| 44 |
+
let term = async {
|
| 45 |
+
match tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()) {
|
| 46 |
+
Ok(mut s) => {
|
| 47 |
+
s.recv().await;
|
| 48 |
+
}
|
| 49 |
+
Err(_) => std::future::pending::<()>().await,
|
| 50 |
+
}
|
| 51 |
+
};
|
| 52 |
+
#[cfg(not(unix))]
|
| 53 |
+
let term = std::future::pending::<()>();
|
| 54 |
+
|
| 55 |
+
tokio::select! {
|
| 56 |
+
_ = ctrl_c => {},
|
| 57 |
+
_ = term => {},
|
| 58 |
+
}
|
| 59 |
+
info!("остановка");
|
| 60 |
+
}
|
src/src/nbt.rs
ADDED
|
@@ -0,0 +1,1143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! Разбор .litematic: gzip → NBT → группы позиций.
|
| 2 |
+
//!
|
| 3 |
+
//! Результат — `Groups`: (название блока, SNBT tile entity или "") → готовые ячейки
|
| 4 |
+
//! позиций по 28 байт. Ячейки пишутся прямо в горячем цикле (без промежуточных
|
| 5 |
+
//! списков координат и без форматирования строк). Массивы NBT не копируются:
|
| 6 |
+
//! `BlockStates` читается прямо из распакованного буфера.
|
| 7 |
+
|
| 8 |
+
use std::collections::btree_map::Entry;
|
| 9 |
+
use std::collections::BTreeMap;
|
| 10 |
+
use std::fmt::{self, Write as _};
|
| 11 |
+
use std::io::Read;
|
| 12 |
+
use std::sync::atomic::{AtomicBool, Ordering};
|
| 13 |
+
|
| 14 |
+
use crate::encoder::{self, Groups};
|
| 15 |
+
|
| 16 |
+
pub type Pos = (i32, i32, i32);
|
| 17 |
+
/// Сдвиг (x, y, z), который прибавляется ко всем позициям.
|
| 18 |
+
pub type Offset = [i32; 3];
|
| 19 |
+
|
| 20 |
+
const MAX_DEPTH: usize = 64;
|
| 21 |
+
const AIR: [&str; 3] = ["minecraft:air", "minecraft:cave_air", "minecraft:void_air"];
|
| 22 |
+
|
| 23 |
+
#[derive(Debug, Clone)]
|
| 24 |
+
pub struct Limits {
|
| 25 |
+
/// Максимум байт после распаковки gzip.
|
| 26 |
+
pub max_decompressed: usize,
|
| 27 |
+
/// Максимум непустых (не воздух) блоков.
|
| 28 |
+
pub max_blocks: usize,
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
impl Default for Limits {
|
| 32 |
+
fn default() -> Self {
|
| 33 |
+
Limits {
|
| 34 |
+
max_decompressed: 64 * 1024 * 1024,
|
| 35 |
+
max_blocks: 500_000,
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
| 41 |
+
pub enum NbtError {
|
| 42 |
+
Gzip(String),
|
| 43 |
+
TooLarge(usize),
|
| 44 |
+
Malformed(String),
|
| 45 |
+
NotLitematic(String),
|
| 46 |
+
TooManyBlocks(usize),
|
| 47 |
+
Coord(String),
|
| 48 |
+
Cancelled,
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
impl fmt::Display for NbtError {
|
| 52 |
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
| 53 |
+
match self {
|
| 54 |
+
NbtError::Gzip(m) => write!(f, "не удалось распаковать gzip: {m}"),
|
| 55 |
+
NbtError::TooLarge(n) => write!(f, "после распаковки файл больше {n} байт"),
|
| 56 |
+
NbtError::Malformed(m) => write!(f, "повреждённый файл: {m}"),
|
| 57 |
+
NbtError::NotLitematic(m) => write!(f, "это не .litematic: {m}"),
|
| 58 |
+
NbtError::TooManyBlocks(n) => {
|
| 59 |
+
write!(f, "схематика слишком большая: больше {n} непустых блоков")
|
| 60 |
+
}
|
| 61 |
+
NbtError::Coord(m) => write!(f, "{m}"),
|
| 62 |
+
NbtError::Cancelled => write!(f, "обработка отменена: не уложились в срок"),
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
impl std::error::Error for NbtError {}
|
| 68 |
+
|
| 69 |
+
fn malformed(msg: impl Into<String>) -> NbtError {
|
| 70 |
+
NbtError::Malformed(msg.into())
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// ---------------------------------------------------------------- gzip
|
| 74 |
+
|
| 75 |
+
/// Распаковывает gzip с ограничением размера результата.
|
| 76 |
+
pub fn gunzip(data: &[u8], limit: usize) -> Result<Vec<u8>, NbtError> {
|
| 77 |
+
if data.len() < 2 || data[0] != 0x1f || data[1] != 0x8b {
|
| 78 |
+
return Err(NbtError::NotLitematic(
|
| 79 |
+
"ожидается gzip-сжатый NBT (файл не начинается с gzip-заголовка)".to_string(),
|
| 80 |
+
));
|
| 81 |
+
}
|
| 82 |
+
let decoder = flate2::read::GzDecoder::new(data);
|
| 83 |
+
let mut out = Vec::new();
|
| 84 |
+
decoder
|
| 85 |
+
.take(limit as u64 + 1)
|
| 86 |
+
.read_to_end(&mut out)
|
| 87 |
+
.map_err(|e| NbtError::Gzip(e.to_string()))?;
|
| 88 |
+
if out.len() > limit {
|
| 89 |
+
return Err(NbtError::TooLarge(limit));
|
| 90 |
+
}
|
| 91 |
+
Ok(out)
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// ---------------------------------------------------------------- NBT
|
| 95 |
+
|
| 96 |
+
/// Массивы хранятся как сырые байты (big-endian) — без копирования.
|
| 97 |
+
#[allow(dead_code)]
|
| 98 |
+
#[derive(Debug, Clone, PartialEq)]
|
| 99 |
+
pub enum Tag<'a> {
|
| 100 |
+
Byte(i8),
|
| 101 |
+
Short(i16),
|
| 102 |
+
Int(i32),
|
| 103 |
+
Long(i64),
|
| 104 |
+
Float(f32),
|
| 105 |
+
Double(f64),
|
| 106 |
+
ByteArray(&'a [u8]),
|
| 107 |
+
String(String),
|
| 108 |
+
List(Vec<Tag<'a>>),
|
| 109 |
+
Compound(BTreeMap<String, Tag<'a>>),
|
| 110 |
+
IntArray(&'a [u8]),
|
| 111 |
+
LongArray(&'a [u8]),
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
impl<'a> Tag<'a> {
|
| 115 |
+
fn get(&self, key: &str) -> Option<&Tag<'a>> {
|
| 116 |
+
if let Tag::Compound(m) = self {
|
| 117 |
+
m.get(key)
|
| 118 |
+
} else {
|
| 119 |
+
None
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
fn as_int(&self) -> Option<i32> {
|
| 124 |
+
if let Tag::Int(v) = self {
|
| 125 |
+
Some(*v)
|
| 126 |
+
} else {
|
| 127 |
+
None
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
fn as_str(&self) -> Option<&str> {
|
| 132 |
+
if let Tag::String(s) = self {
|
| 133 |
+
Some(s.as_str())
|
| 134 |
+
} else {
|
| 135 |
+
None
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
struct Reader<'a> {
|
| 141 |
+
buf: &'a [u8],
|
| 142 |
+
pos: usize,
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
impl<'a> Reader<'a> {
|
| 146 |
+
fn new(buf: &'a [u8]) -> Self {
|
| 147 |
+
Reader { buf, pos: 0 }
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
fn remaining(&self) -> usize {
|
| 151 |
+
self.buf.len() - self.pos
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
fn take(&mut self, n: usize) -> Result<&'a [u8], NbtError> {
|
| 155 |
+
let end = self
|
| 156 |
+
.pos
|
| 157 |
+
.checked_add(n)
|
| 158 |
+
.filter(|&e| e <= self.buf.len())
|
| 159 |
+
.ok_or_else(|| malformed("неожиданный конец данных"))?;
|
| 160 |
+
let slice = &self.buf[self.pos..end];
|
| 161 |
+
self.pos = end;
|
| 162 |
+
Ok(slice)
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
fn u8(&mut self) -> Result<u8, NbtError> {
|
| 166 |
+
Ok(self.take(1)?[0])
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
fn u16(&mut self) -> Result<u16, NbtError> {
|
| 170 |
+
Ok(u16::from_be_bytes(self.take(2)?.try_into().unwrap()))
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
fn i16(&mut self) -> Result<i16, NbtError> {
|
| 174 |
+
Ok(i16::from_be_bytes(self.take(2)?.try_into().unwrap()))
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
fn i32(&mut self) -> Result<i32, NbtError> {
|
| 178 |
+
Ok(i32::from_be_bytes(self.take(4)?.try_into().unwrap()))
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
fn i64(&mut self) -> Result<i64, NbtError> {
|
| 182 |
+
Ok(i64::from_be_bytes(self.take(8)?.try_into().unwrap()))
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
fn len(&mut self) -> Result<usize, NbtError> {
|
| 186 |
+
let n = self.i32()?;
|
| 187 |
+
usize::try_from(n).map_err(|_| malformed("отрицательная длина"))
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
fn string(&mut self) -> Result<String, NbtError> {
|
| 191 |
+
let n = self.u16()? as usize;
|
| 192 |
+
let bytes = self.take(n)?;
|
| 193 |
+
Ok(String::from_utf8_lossy(bytes).into_owned())
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
fn payload(&mut self, id: u8, depth: usize) -> Result<Tag<'a>, NbtError> {
|
| 197 |
+
if depth > MAX_DEPTH {
|
| 198 |
+
return Err(malformed("слишком глубокая вложенность"));
|
| 199 |
+
}
|
| 200 |
+
Ok(match id {
|
| 201 |
+
1 => Tag::Byte(self.u8()? as i8),
|
| 202 |
+
2 => Tag::Short(self.i16()?),
|
| 203 |
+
3 => Tag::Int(self.i32()?),
|
| 204 |
+
4 => Tag::Long(self.i64()?),
|
| 205 |
+
5 => Tag::Float(f32::from_bits(self.i32()? as u32)),
|
| 206 |
+
6 => Tag::Double(f64::from_bits(self.i64()? as u64)),
|
| 207 |
+
7 => {
|
| 208 |
+
let n = self.len()?;
|
| 209 |
+
Tag::ByteArray(self.take(n)?)
|
| 210 |
+
}
|
| 211 |
+
8 => Tag::String(self.string()?),
|
| 212 |
+
9 => {
|
| 213 |
+
let elem = self.u8()?;
|
| 214 |
+
let n = self.len()?;
|
| 215 |
+
if n > 0 && elem == 0 {
|
| 216 |
+
return Err(malformed("список с типом элементов End"));
|
| 217 |
+
}
|
| 218 |
+
if n > self.remaining() {
|
| 219 |
+
return Err(malformed("длина списка больше оставшихся данных"));
|
| 220 |
+
}
|
| 221 |
+
let mut items = Vec::with_capacity(n);
|
| 222 |
+
for _ in 0..n {
|
| 223 |
+
items.push(self.payload(elem, depth + 1)?);
|
| 224 |
+
}
|
| 225 |
+
Tag::List(items)
|
| 226 |
+
}
|
| 227 |
+
10 => {
|
| 228 |
+
let mut map = BTreeMap::new();
|
| 229 |
+
loop {
|
| 230 |
+
let t = self.u8()?;
|
| 231 |
+
if t == 0 {
|
| 232 |
+
break;
|
| 233 |
+
}
|
| 234 |
+
let name = self.string()?;
|
| 235 |
+
let value = self.payload(t, depth + 1)?;
|
| 236 |
+
map.insert(name, value);
|
| 237 |
+
}
|
| 238 |
+
Tag::Compound(map)
|
| 239 |
+
}
|
| 240 |
+
11 => {
|
| 241 |
+
let n = self.len()?;
|
| 242 |
+
let size = n.checked_mul(4).ok_or_else(|| malformed("длина массива"))?;
|
| 243 |
+
Tag::IntArray(self.take(size)?)
|
| 244 |
+
}
|
| 245 |
+
12 => {
|
| 246 |
+
let n = self.len()?;
|
| 247 |
+
let size = n.checked_mul(8).ok_or_else(|| malformed("длина массива"))?;
|
| 248 |
+
Tag::LongArray(self.take(size)?)
|
| 249 |
+
}
|
| 250 |
+
other => return Err(malformed(format!("неизвестный тип тега {other}"))),
|
| 251 |
+
})
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/// Разбирает несжатый NBT. Корень обязан быть compound.
|
| 256 |
+
pub fn parse_nbt(data: &[u8]) -> Result<Tag<'_>, NbtError> {
|
| 257 |
+
let mut r = Reader::new(data);
|
| 258 |
+
let id = r.u8()?;
|
| 259 |
+
if id != 10 {
|
| 260 |
+
return Err(malformed("корневой тег не compound"));
|
| 261 |
+
}
|
| 262 |
+
let _root_name = r.string()?;
|
| 263 |
+
r.payload(10, 0)
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
// ---------------------------------------------------------------- SNBT
|
| 267 |
+
|
| 268 |
+
fn write_quoted(s: &str, out: &mut String) {
|
| 269 |
+
out.push('"');
|
| 270 |
+
for c in s.chars() {
|
| 271 |
+
match c {
|
| 272 |
+
'"' => out.push_str("\\\""),
|
| 273 |
+
'\\' => out.push_str("\\\\"),
|
| 274 |
+
_ => out.push(c),
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
out.push('"');
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
fn write_key(k: &str, out: &mut String) {
|
| 281 |
+
let plain = !k.is_empty()
|
| 282 |
+
&& k.chars()
|
| 283 |
+
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '_' | '-' | '.' | '+'));
|
| 284 |
+
if plain {
|
| 285 |
+
out.push_str(k);
|
| 286 |
+
} else {
|
| 287 |
+
write_quoted(k, out);
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
fn write_compound(map: &BTreeMap<String, Tag<'_>>, skip: &[&str], out: &mut String) {
|
| 292 |
+
out.push('{');
|
| 293 |
+
let mut first = true;
|
| 294 |
+
for (k, v) in map {
|
| 295 |
+
if skip.iter().any(|s| *s == k.as_str()) {
|
| 296 |
+
continue;
|
| 297 |
+
}
|
| 298 |
+
if !first {
|
| 299 |
+
out.push(',');
|
| 300 |
+
}
|
| 301 |
+
first = false;
|
| 302 |
+
write_key(k, out);
|
| 303 |
+
out.push(':');
|
| 304 |
+
write_snbt(v, out);
|
| 305 |
+
}
|
| 306 |
+
out.push('}');
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
fn write_snbt(tag: &Tag<'_>, out: &mut String) {
|
| 310 |
+
match tag {
|
| 311 |
+
Tag::Byte(v) => {
|
| 312 |
+
let _ = write!(out, "{v}b");
|
| 313 |
+
}
|
| 314 |
+
Tag::Short(v) => {
|
| 315 |
+
let _ = write!(out, "{v}s");
|
| 316 |
+
}
|
| 317 |
+
Tag::Int(v) => {
|
| 318 |
+
let _ = write!(out, "{v}");
|
| 319 |
+
}
|
| 320 |
+
Tag::Long(v) => {
|
| 321 |
+
let _ = write!(out, "{v}L");
|
| 322 |
+
}
|
| 323 |
+
Tag::Float(v) => {
|
| 324 |
+
let _ = write!(out, "{v}f");
|
| 325 |
+
}
|
| 326 |
+
Tag::Double(v) => {
|
| 327 |
+
let _ = write!(out, "{v}d");
|
| 328 |
+
}
|
| 329 |
+
Tag::String(s) => write_quoted(s, out),
|
| 330 |
+
Tag::ByteArray(b) => {
|
| 331 |
+
out.push_str("[B;");
|
| 332 |
+
for (i, x) in b.iter().enumerate() {
|
| 333 |
+
if i > 0 {
|
| 334 |
+
out.push(',');
|
| 335 |
+
}
|
| 336 |
+
let _ = write!(out, "{}b", *x as i8);
|
| 337 |
+
}
|
| 338 |
+
out.push(']');
|
| 339 |
+
}
|
| 340 |
+
Tag::IntArray(b) => {
|
| 341 |
+
out.push_str("[I;");
|
| 342 |
+
for (i, c) in b.chunks_exact(4).enumerate() {
|
| 343 |
+
if i > 0 {
|
| 344 |
+
out.push(',');
|
| 345 |
+
}
|
| 346 |
+
let _ = write!(out, "{}", i32::from_be_bytes(c.try_into().unwrap()));
|
| 347 |
+
}
|
| 348 |
+
out.push(']');
|
| 349 |
+
}
|
| 350 |
+
Tag::LongArray(b) => {
|
| 351 |
+
out.push_str("[L;");
|
| 352 |
+
for (i, c) in b.chunks_exact(8).enumerate() {
|
| 353 |
+
if i > 0 {
|
| 354 |
+
out.push(',');
|
| 355 |
+
}
|
| 356 |
+
let _ = write!(out, "{}L", i64::from_be_bytes(c.try_into().unwrap()));
|
| 357 |
+
}
|
| 358 |
+
out.push(']');
|
| 359 |
+
}
|
| 360 |
+
Tag::List(items) => {
|
| 361 |
+
out.push('[');
|
| 362 |
+
for (i, t) in items.iter().enumerate() {
|
| 363 |
+
if i > 0 {
|
| 364 |
+
out.push(',');
|
| 365 |
+
}
|
| 366 |
+
write_snbt(t, out);
|
| 367 |
+
}
|
| 368 |
+
out.push(']');
|
| 369 |
+
}
|
| 370 |
+
Tag::Compound(m) => write_compound(m, &[], out),
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
/// SNBT compound без ключей из `skip`. Ключи по алфавиту — результат детерминирован.
|
| 375 |
+
pub fn compound_snbt(map: &BTreeMap<String, Tag<'_>>, skip: &[&str]) -> String {
|
| 376 |
+
let mut s = String::new();
|
| 377 |
+
write_compound(map, skip, &mut s);
|
| 378 |
+
s
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
// ---------------------------------------------------------------- litematic
|
| 382 |
+
|
| 383 |
+
/// Gzip → группы позиций со сдвигом `offset`.
|
| 384 |
+
pub fn parse_litematic_gz(
|
| 385 |
+
gz: &[u8],
|
| 386 |
+
limits: &Limits,
|
| 387 |
+
offset: Offset,
|
| 388 |
+
cancel: &AtomicBool,
|
| 389 |
+
) -> Result<Groups, NbtError> {
|
| 390 |
+
let raw = gunzip(gz, limits.max_decompressed)?;
|
| 391 |
+
parse_litematic(&raw, limits.max_blocks, offset, cancel)
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
/// Несжатый NBT → группы «(блок, SNBT) → ячейки позиций».
|
| 395 |
+
/// Воздух пропускается. Регионы обходятся по имени, внутри региона — в порядке
|
| 396 |
+
/// индекса litematica (y, затем z, затем x), поэтому результат детерминирован.
|
| 397 |
+
/// Позиция = `Position` региона + локальная позиция + `offset`.
|
| 398 |
+
/// `cancel` проверяется на каждом слое по y: взведён — вернётся `Cancelled`.
|
| 399 |
+
pub fn parse_litematic(
|
| 400 |
+
data: &[u8],
|
| 401 |
+
max_blocks: usize,
|
| 402 |
+
offset: Offset,
|
| 403 |
+
cancel: &AtomicBool,
|
| 404 |
+
) -> Result<Groups, NbtError> {
|
| 405 |
+
let root = parse_nbt(data)?;
|
| 406 |
+
let regions = match root.get("Regions") {
|
| 407 |
+
Some(Tag::Compound(m)) => m,
|
| 408 |
+
_ => return Err(NbtError::NotLitematic("нет тега Regions".to_string())),
|
| 409 |
+
};
|
| 410 |
+
let mut groups = Groups::new();
|
| 411 |
+
let mut total = 0usize;
|
| 412 |
+
for (name, region) in regions {
|
| 413 |
+
parse_region(name, region, max_blocks, offset, cancel, &mut total, &mut groups)?;
|
| 414 |
+
}
|
| 415 |
+
Ok(groups)
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
fn bad(region: &str, msg: &str) -> NbtError {
|
| 419 |
+
malformed(format!("регион «{region}»: {msg}"))
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
fn read_vec3(region: &Tag<'_>, key: &str, name: &str) -> Result<[i32; 3], NbtError> {
|
| 423 |
+
let tag = region
|
| 424 |
+
.get(key)
|
| 425 |
+
.ok_or_else(|| bad(name, &format!("нет поля {key}")))?;
|
| 426 |
+
let mut out = [0i32; 3];
|
| 427 |
+
for (slot, axis) in out.iter_mut().zip(["x", "y", "z"]) {
|
| 428 |
+
*slot = tag
|
| 429 |
+
.get(axis)
|
| 430 |
+
.and_then(|t| t.as_int())
|
| 431 |
+
.ok_or_else(|| bad(name, &format!("{key}.{axis} не является числом")))?;
|
| 432 |
+
}
|
| 433 |
+
Ok(out)
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
/// Название блока с состоянием, без префикса `minecraft:`:
|
| 437 |
+
/// `oak_stairs[facing=north,half=bottom]`. Другие пространства имён (`create:cogwheel`)
|
| 438 |
+
/// остаются как есть. Для воздуха возвращает `None`.
|
| 439 |
+
fn palette_name(entry: &Tag<'_>, region: &str) -> Result<Option<String>, NbtError> {
|
| 440 |
+
let name = entry
|
| 441 |
+
.get("Name")
|
| 442 |
+
.and_then(|t| t.as_str())
|
| 443 |
+
.ok_or_else(|| bad(region, "в палитре нет Name"))?;
|
| 444 |
+
if AIR.iter().any(|a| *a == name) {
|
| 445 |
+
return Ok(None);
|
| 446 |
+
}
|
| 447 |
+
let mut s = name.strip_prefix("minecraft:").unwrap_or(name).to_string();
|
| 448 |
+
if let Some(Tag::Compound(props)) = entry.get("Properties") {
|
| 449 |
+
let parts: Vec<String> = props
|
| 450 |
+
.iter()
|
| 451 |
+
.filter_map(|(k, v)| v.as_str().map(|v| format!("{k}={v}")))
|
| 452 |
+
.collect();
|
| 453 |
+
if !parts.is_empty() {
|
| 454 |
+
s.push('[');
|
| 455 |
+
s.push_str(&parts.join(","));
|
| 456 |
+
s.push(']');
|
| 457 |
+
}
|
| 458 |
+
}
|
| 459 |
+
Ok(Some(s))
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
/// Tile entities региона: (индекс ячейки в массиве блоков, SNBT без x/y/z),
|
| 463 |
+
/// по возрастанию индекса. Координаты tile entity — локальные в регионе.
|
| 464 |
+
/// Записи без координат, вне региона или без данных пропускаются.
|
| 465 |
+
fn tile_entities(region: &Tag<'_>, abs: [u64; 3]) -> Vec<(u64, String)> {
|
| 466 |
+
let list = match region.get("TileEntities") {
|
| 467 |
+
Some(Tag::List(l)) => l,
|
| 468 |
+
_ => return Vec::new(),
|
| 469 |
+
};
|
| 470 |
+
let mut found: BTreeMap<u64, String> = BTreeMap::new();
|
| 471 |
+
for te in list {
|
| 472 |
+
let coord = |k: &str| te.get(k).and_then(|t| t.as_int());
|
| 473 |
+
let (x, y, z) = match (coord("x"), coord("y"), coord("z")) {
|
| 474 |
+
(Some(x), Some(y), Some(z)) if x >= 0 && y >= 0 && z >= 0 => {
|
| 475 |
+
(x as u64, y as u64, z as u64)
|
| 476 |
+
}
|
| 477 |
+
_ => continue,
|
| 478 |
+
};
|
| 479 |
+
if x >= abs[0] || y >= abs[1] || z >= abs[2] {
|
| 480 |
+
continue;
|
| 481 |
+
}
|
| 482 |
+
let snbt = match te {
|
| 483 |
+
Tag::Compound(m) => compound_snbt(m, &["x", "y", "z"]),
|
| 484 |
+
_ => continue,
|
| 485 |
+
};
|
| 486 |
+
if snbt == "{}" {
|
| 487 |
+
continue;
|
| 488 |
+
}
|
| 489 |
+
found.insert((y * abs[2] + z) * abs[0] + x, snbt);
|
| 490 |
+
}
|
| 491 |
+
found.into_iter().collect()
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
#[inline]
|
| 495 |
+
fn long_at(raw: &[u8], i: usize) -> u64 {
|
| 496 |
+
let b: [u8; 8] = raw[i * 8..i * 8 + 8].try_into().unwrap();
|
| 497 |
+
u64::from_be_bytes(b)
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
/// Достаёт `bits`-битное значение с номером `index` из упакованного массива.
|
| 501 |
+
/// Litematica упаковывает значения подряд, без выравнивания по границе long.
|
| 502 |
+
#[inline]
|
| 503 |
+
fn get_bits(raw: &[u8], index: u64, bits: u64, mask: u64) -> u64 {
|
| 504 |
+
let start = index * bits;
|
| 505 |
+
let first = (start >> 6) as usize;
|
| 506 |
+
let last = ((start + bits - 1) >> 6) as usize;
|
| 507 |
+
let offset = start & 63;
|
| 508 |
+
let low = long_at(raw, first) >> offset;
|
| 509 |
+
if first == last {
|
| 510 |
+
low & mask
|
| 511 |
+
} else {
|
| 512 |
+
(low | (long_at(raw, last) << (64 - offset))) & mask
|
| 513 |
+
}
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
fn merge(groups: &mut Groups, key: (String, String), buf: Vec<u8>) {
|
| 517 |
+
match groups.entry(key) {
|
| 518 |
+
Entry::Vacant(v) => {
|
| 519 |
+
v.insert(buf);
|
| 520 |
+
}
|
| 521 |
+
Entry::Occupied(mut o) => o.get_mut().extend_from_slice(&buf),
|
| 522 |
+
}
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
fn parse_region(
|
| 526 |
+
name: &str,
|
| 527 |
+
region: &Tag<'_>,
|
| 528 |
+
max_blocks: usize,
|
| 529 |
+
offset: Offset,
|
| 530 |
+
cancel: &AtomicBool,
|
| 531 |
+
total: &mut usize,
|
| 532 |
+
groups: &mut Groups,
|
| 533 |
+
) -> Result<(), NbtError> {
|
| 534 |
+
if cancel.load(Ordering::Relaxed) {
|
| 535 |
+
return Err(NbtError::Cancelled);
|
| 536 |
+
}
|
| 537 |
+
let pos = read_vec3(region, "Position", name)?;
|
| 538 |
+
let size = read_vec3(region, "Size", name)?;
|
| 539 |
+
let abs = size.map(|s| u64::from(s.unsigned_abs()));
|
| 540 |
+
let volume = abs[0]
|
| 541 |
+
.checked_mul(abs[1])
|
| 542 |
+
.and_then(|v| v.checked_mul(abs[2]))
|
| 543 |
+
.ok_or_else(|| bad(name, "размер региона слишком велик"))?;
|
| 544 |
+
if volume == 0 {
|
| 545 |
+
return Ok(()); // пустой регион
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
let palette = match region.get("BlockStatePalette") {
|
| 549 |
+
Some(Tag::List(l)) => l,
|
| 550 |
+
_ => return Err(bad(name, "нет BlockStatePalette")),
|
| 551 |
+
};
|
| 552 |
+
let raw: &[u8] = match region.get("BlockStates") {
|
| 553 |
+
Some(Tag::LongArray(a)) => *a,
|
| 554 |
+
_ => return Err(bad(name, "нет BlockStates")),
|
| 555 |
+
};
|
| 556 |
+
if palette.is_empty() {
|
| 557 |
+
return Err(bad(name, "пустая палитра"));
|
| 558 |
+
}
|
| 559 |
+
let names: Vec<Option<String>> = palette
|
| 560 |
+
.iter()
|
| 561 |
+
.map(|e| palette_name(e, name))
|
| 562 |
+
.collect::<Result<_, _>>()?;
|
| 563 |
+
|
| 564 |
+
let bits = u64::from((usize::BITS - (palette.len() - 1).leading_zeros()).max(2));
|
| 565 |
+
let total_bits = volume
|
| 566 |
+
.checked_mul(bits)
|
| 567 |
+
.ok_or_else(|| bad(name, "размер региона слишком велик"))?;
|
| 568 |
+
let needed = total_bits / 64 + u64::from(total_bits % 64 != 0);
|
| 569 |
+
if ((raw.len() / 8) as u64) < needed {
|
| 570 |
+
return Err(bad(name, "BlockStates короче, чем размер региона"));
|
| 571 |
+
}
|
| 572 |
+
let mask = (1u64 << bits) - 1;
|
| 573 |
+
|
| 574 |
+
// Минимальный угол региона со сдвигом. Размер может быть отрицательным.
|
| 575 |
+
let mut min = [0i64; 3];
|
| 576 |
+
for i in 0..3 {
|
| 577 |
+
let back = if size[i] < 0 { i64::from(size[i]) + 1 } else { 0 };
|
| 578 |
+
min[i] = i64::from(pos[i]) + back + i64::from(offset[i]);
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
let te = tile_entities(region, abs);
|
| 582 |
+
let mut ti = 0usize;
|
| 583 |
+
let mut next_te = te.first().map(|t| t.0).unwrap_or(u64::MAX);
|
| 584 |
+
|
| 585 |
+
let (sx, sy, sz) = (abs[0] as i64, abs[1] as i64, abs[2] as i64);
|
| 586 |
+
let mut bufs: Vec<Vec<u8>> = vec![Vec::new(); palette.len()];
|
| 587 |
+
let mut special: BTreeMap<(usize, String), Vec<u8>> = BTreeMap::new();
|
| 588 |
+
let mut index: u64 = 0;
|
| 589 |
+
|
| 590 |
+
for y in 0..sy {
|
| 591 |
+
if cancel.load(Ordering::Relaxed) {
|
| 592 |
+
return Err(NbtError::Cancelled);
|
| 593 |
+
}
|
| 594 |
+
for z in 0..sz {
|
| 595 |
+
for x in 0..sx {
|
| 596 |
+
let id = get_bits(raw, index, bits, mask) as usize;
|
| 597 |
+
let is_te = index == next_te;
|
| 598 |
+
if is_te {
|
| 599 |
+
ti += 1;
|
| 600 |
+
next_te = te.get(ti).map(|t| t.0).unwrap_or(u64::MAX);
|
| 601 |
+
}
|
| 602 |
+
index += 1;
|
| 603 |
+
let slot = names
|
| 604 |
+
.get(id)
|
| 605 |
+
.ok_or_else(|| bad(name, "индекс блока вне палитры"))?;
|
| 606 |
+
if slot.is_none() {
|
| 607 |
+
continue;
|
| 608 |
+
}
|
| 609 |
+
*total += 1;
|
| 610 |
+
if *total > max_blocks {
|
| 611 |
+
return Err(NbtError::TooManyBlocks(max_blocks));
|
| 612 |
+
}
|
| 613 |
+
let wx = i32::try_from(min[0] + x).map_err(|_| bad(name, "координата вне i32"))?;
|
| 614 |
+
let wy = i32::try_from(min[1] + y).map_err(|_| bad(name, "координата вне i32"))?;
|
| 615 |
+
let wz = i32::try_from(min[2] + z).map_err(|_| bad(name, "координата вне i32"))?;
|
| 616 |
+
let target: &mut Vec<u8> = if is_te {
|
| 617 |
+
special.entry((id, te[ti - 1].1.clone())).or_default()
|
| 618 |
+
} else {
|
| 619 |
+
&mut bufs[id]
|
| 620 |
+
};
|
| 621 |
+
encoder::push_position(target, wx, wy, wz)
|
| 622 |
+
.map_err(|e| NbtError::Coord(e.to_string()))?;
|
| 623 |
+
}
|
| 624 |
+
}
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
for (id, buf) in bufs.into_iter().enumerate() {
|
| 628 |
+
if buf.is_empty() {
|
| 629 |
+
continue;
|
| 630 |
+
}
|
| 631 |
+
if let Some(block) = &names[id] {
|
| 632 |
+
merge(groups, (block.clone(), String::new()), buf);
|
| 633 |
+
}
|
| 634 |
+
}
|
| 635 |
+
for ((id, snbt), buf) in special {
|
| 636 |
+
if let Some(block) = &names[id] {
|
| 637 |
+
merge(groups, (block.clone(), snbt), buf);
|
| 638 |
+
}
|
| 639 |
+
}
|
| 640 |
+
Ok(())
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
#[cfg(test)]
|
| 644 |
+
mod tests {
|
| 645 |
+
use super::*;
|
| 646 |
+
use flate2::{write::GzEncoder, Compression};
|
| 647 |
+
use std::io::Write;
|
| 648 |
+
|
| 649 |
+
type Palette = Vec<(&'static str, Vec<(&'static str, &'static str)>)>;
|
| 650 |
+
|
| 651 |
+
// ---- минимальный NBT-писатель для тестов ----
|
| 652 |
+
fn w_str(out: &mut Vec<u8>, s: &str) {
|
| 653 |
+
out.extend((s.len() as u16).to_be_bytes());
|
| 654 |
+
out.extend(s.as_bytes());
|
| 655 |
+
}
|
| 656 |
+
fn named(out: &mut Vec<u8>, id: u8, name: &str) {
|
| 657 |
+
out.push(id);
|
| 658 |
+
w_str(out, name);
|
| 659 |
+
}
|
| 660 |
+
fn int_named(out: &mut Vec<u8>, name: &str, v: i32) {
|
| 661 |
+
named(out, 3, name);
|
| 662 |
+
out.extend(v.to_be_bytes());
|
| 663 |
+
}
|
| 664 |
+
fn vec3(out: &mut Vec<u8>, name: &str, v: [i32; 3]) {
|
| 665 |
+
named(out, 10, name);
|
| 666 |
+
int_named(out, "x", v[0]);
|
| 667 |
+
int_named(out, "y", v[1]);
|
| 668 |
+
int_named(out, "z", v[2]);
|
| 669 |
+
out.push(0);
|
| 670 |
+
}
|
| 671 |
+
fn palette_entry(out: &mut Vec<u8>, name: &str, props: &[(&str, &str)]) {
|
| 672 |
+
named(out, 8, "Name");
|
| 673 |
+
w_str(out, name);
|
| 674 |
+
if !props.is_empty() {
|
| 675 |
+
named(out, 10, "Properties");
|
| 676 |
+
for (k, v) in props {
|
| 677 |
+
named(out, 8, k);
|
| 678 |
+
w_str(out, v);
|
| 679 |
+
}
|
| 680 |
+
out.push(0);
|
| 681 |
+
}
|
| 682 |
+
out.push(0);
|
| 683 |
+
}
|
| 684 |
+
fn region_te(
|
| 685 |
+
out: &mut Vec<u8>,
|
| 686 |
+
name: &str,
|
| 687 |
+
pos: [i32; 3],
|
| 688 |
+
size: [i32; 3],
|
| 689 |
+
palette: &Palette,
|
| 690 |
+
states: &[i64],
|
| 691 |
+
tes: &[(i32, i32, i32, &str)],
|
| 692 |
+
) {
|
| 693 |
+
named(out, 10, name);
|
| 694 |
+
vec3(out, "Position", pos);
|
| 695 |
+
vec3(out, "Size", size);
|
| 696 |
+
named(out, 9, "BlockStatePalette");
|
| 697 |
+
out.push(10);
|
| 698 |
+
out.extend((palette.len() as i32).to_be_bytes());
|
| 699 |
+
for (n, p) in palette {
|
| 700 |
+
palette_entry(out, n, p);
|
| 701 |
+
}
|
| 702 |
+
named(out, 12, "BlockStates");
|
| 703 |
+
out.extend((states.len() as i32).to_be_bytes());
|
| 704 |
+
for s in states {
|
| 705 |
+
out.extend(s.to_be_bytes());
|
| 706 |
+
}
|
| 707 |
+
if !tes.is_empty() {
|
| 708 |
+
named(out, 9, "TileEntities");
|
| 709 |
+
out.push(10);
|
| 710 |
+
out.extend((tes.len() as i32).to_be_bytes());
|
| 711 |
+
for (x, y, z, id) in tes {
|
| 712 |
+
int_named(out, "x", *x);
|
| 713 |
+
int_named(out, "y", *y);
|
| 714 |
+
int_named(out, "z", *z);
|
| 715 |
+
named(out, 8, "id");
|
| 716 |
+
w_str(out, id);
|
| 717 |
+
out.push(0);
|
| 718 |
+
}
|
| 719 |
+
}
|
| 720 |
+
out.push(0);
|
| 721 |
+
}
|
| 722 |
+
fn region(
|
| 723 |
+
out: &mut Vec<u8>,
|
| 724 |
+
name: &str,
|
| 725 |
+
pos: [i32; 3],
|
| 726 |
+
size: [i32; 3],
|
| 727 |
+
palette: &Palette,
|
| 728 |
+
states: &[i64],
|
| 729 |
+
) {
|
| 730 |
+
region_te(out, name, pos, size, palette, states, &[]);
|
| 731 |
+
}
|
| 732 |
+
fn litematic(regions: impl FnOnce(&mut Vec<u8>)) -> Vec<u8> {
|
| 733 |
+
let mut out = Vec::new();
|
| 734 |
+
named(&mut out, 10, "");
|
| 735 |
+
named(&mut out, 10, "Regions");
|
| 736 |
+
regions(&mut out);
|
| 737 |
+
out.push(0); // конец Regions
|
| 738 |
+
out.push(0); // конец корня
|
| 739 |
+
out
|
| 740 |
+
}
|
| 741 |
+
/// Независимая упаковка: бит за битом.
|
| 742 |
+
fn pack(values: &[u64], bits: u64) -> Vec<i64> {
|
| 743 |
+
let total_bits = values.len() as u64 * bits;
|
| 744 |
+
let mut longs = vec![0u64; ((total_bits + 63) / 64) as usize];
|
| 745 |
+
for (i, v) in values.iter().enumerate() {
|
| 746 |
+
for b in 0..bits {
|
| 747 |
+
if (*v >> b) & 1 == 1 {
|
| 748 |
+
let p = i as u64 * bits + b;
|
| 749 |
+
longs[(p / 64) as usize] |= 1u64 << (p % 64);
|
| 750 |
+
}
|
| 751 |
+
}
|
| 752 |
+
}
|
| 753 |
+
longs.into_iter().map(|l| l as i64).collect()
|
| 754 |
+
}
|
| 755 |
+
fn air_stone() -> Palette {
|
| 756 |
+
vec![("minecraft:air", vec![]), ("minecraft:stone", vec![])]
|
| 757 |
+
}
|
| 758 |
+
fn gzip(data: &[u8]) -> Vec<u8> {
|
| 759 |
+
let mut e = GzEncoder::new(Vec::new(), Compression::default());
|
| 760 |
+
e.write_all(data).unwrap();
|
| 761 |
+
e.finish().unwrap()
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
// ---- чтение результата ----
|
| 765 |
+
fn dec(c: &[u8]) -> i32 {
|
| 766 |
+
let s = std::str::from_utf8(c).unwrap();
|
| 767 |
+
if let Some(r) = s.strip_prefix('-') {
|
| 768 |
+
-r.parse::<i32>().unwrap()
|
| 769 |
+
} else {
|
| 770 |
+
s.parse().unwrap()
|
| 771 |
+
}
|
| 772 |
+
}
|
| 773 |
+
fn positions(buf: &[u8]) -> Vec<Pos> {
|
| 774 |
+
assert_eq!(buf.len() % encoder::CELL_LEN, 0);
|
| 775 |
+
buf.chunks_exact(encoder::CELL_LEN)
|
| 776 |
+
.map(|c| (dec(&c[5..9]), dec(&c[14..18]), dec(&c[23..27])))
|
| 777 |
+
.collect()
|
| 778 |
+
}
|
| 779 |
+
fn key(name: &str) -> (String, String) {
|
| 780 |
+
(name.to_string(), String::new())
|
| 781 |
+
}
|
| 782 |
+
fn parse(data: &[u8], max: usize) -> Result<Groups, NbtError> {
|
| 783 |
+
parse_litematic(data, max, [0, 0, 0], &AtomicBool::new(false))
|
| 784 |
+
}
|
| 785 |
+
fn parse_off(data: &[u8], offset: Offset) -> Result<Groups, NbtError> {
|
| 786 |
+
parse_litematic(data, 1000, offset, &AtomicBool::new(false))
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
#[test]
|
| 790 |
+
fn simple_region() {
|
| 791 |
+
let data = litematic(|o| region(o, "main", [0, 0, 0], [2, 1, 2], &air_stone(), &pack(&[0, 1, 1, 0], 2)));
|
| 792 |
+
let g = parse(&data, 1000).unwrap();
|
| 793 |
+
assert_eq!(g.len(), 1);
|
| 794 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(1, 0, 0), (0, 0, 1)]);
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
#[test]
|
| 798 |
+
fn cells_have_expected_text() {
|
| 799 |
+
let data = litematic(|o| region(o, "r", [-5, 10, -1], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 800 |
+
let g = parse(&data, 10).unwrap();
|
| 801 |
+
let cell = String::from_utf8(g[&key("stone")].clone()).unwrap();
|
| 802 |
+
assert_eq!(cell, r#"{"x":-005,"y":0010,"z":-001}"#);
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
#[test]
|
| 806 |
+
fn empty_regions_tag() {
|
| 807 |
+
let data = litematic(|_| {});
|
| 808 |
+
assert!(parse(&data, 10).unwrap().is_empty());
|
| 809 |
+
}
|
| 810 |
+
|
| 811 |
+
#[test]
|
| 812 |
+
fn empty_region_zero_size() {
|
| 813 |
+
let data = litematic(|o| region(o, "r", [3, 3, 3], [0, 0, 0], &air_stone(), &[]));
|
| 814 |
+
assert!(parse(&data, 10).unwrap().is_empty());
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
#[test]
|
| 818 |
+
fn region_with_only_air() {
|
| 819 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [2, 2, 2], &air_stone(), &pack(&[0; 8], 2)));
|
| 820 |
+
assert!(parse(&data, 10).unwrap().is_empty());
|
| 821 |
+
}
|
| 822 |
+
|
| 823 |
+
#[test]
|
| 824 |
+
fn negative_position() {
|
| 825 |
+
let data = litematic(|o| region(o, "r", [-5, 10, -1], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 826 |
+
let g = parse(&data, 10).unwrap();
|
| 827 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(-5, 10, -1)]);
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
#[test]
|
| 831 |
+
fn negative_size_extends_backwards() {
|
| 832 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [-2, 1, 1], &air_stone(), &pack(&[1, 1], 2)));
|
| 833 |
+
let g = parse(&data, 10).unwrap();
|
| 834 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(-1, 0, 0), (0, 0, 0)]);
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
#[test]
|
| 838 |
+
fn coordinate_out_of_cell_range() {
|
| 839 |
+
let data = litematic(|o| region(o, "r", [10_000, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 840 |
+
assert!(matches!(parse(&data, 10), Err(NbtError::Coord(_))));
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
#[test]
|
| 844 |
+
fn values_spanning_long_boundary() {
|
| 845 |
+
let names = ["minecraft:air", "minecraft:a", "minecraft:b", "minecraft:c", "minecraft:d"];
|
| 846 |
+
let palette: Palette = names.iter().map(|n| (*n, Vec::new())).collect();
|
| 847 |
+
let values: Vec<u64> = (0..30u64).map(|i| i % 5).collect();
|
| 848 |
+
let states = pack(&values, 3);
|
| 849 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [30, 1, 1], &palette, &states));
|
| 850 |
+
let g = parse(&data, 1000).unwrap();
|
| 851 |
+
assert_eq!(g.len(), 4);
|
| 852 |
+
let expected: Vec<Pos> = (0..30).filter(|i| i % 5 == 2).map(|i| (i, 0, 0)).collect();
|
| 853 |
+
assert_eq!(positions(&g[&key("b")]), expected);
|
| 854 |
+
}
|
| 855 |
+
|
| 856 |
+
#[test]
|
| 857 |
+
fn properties_are_sorted_in_name() {
|
| 858 |
+
let palette: Palette = vec![
|
| 859 |
+
("minecraft:air", vec![]),
|
| 860 |
+
("minecraft:oak_stairs", vec![("half", "bottom"), ("facing", "north")]),
|
| 861 |
+
];
|
| 862 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [1, 1, 1], &palette, &pack(&[1], 2)));
|
| 863 |
+
let g = parse(&data, 10).unwrap();
|
| 864 |
+
assert!(g.contains_key(&key("oak_stairs[facing=north,half=bottom]")));
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
#[test]
|
| 868 |
+
fn multiple_regions_merge_sorted_by_region_name() {
|
| 869 |
+
let data = litematic(|o| {
|
| 870 |
+
region(o, "b", [10, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2));
|
| 871 |
+
region(o, "a", [0, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2));
|
| 872 |
+
});
|
| 873 |
+
let g = parse(&data, 10).unwrap();
|
| 874 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(0, 0, 0), (10, 0, 0)]);
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
#[test]
|
| 878 |
+
fn deterministic() {
|
| 879 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [3, 3, 3], &air_stone(), &pack(&[1; 27], 2)));
|
| 880 |
+
assert_eq!(parse(&data, 100).unwrap(), parse(&data, 100).unwrap());
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
|
| 884 |
+
// ---- имена без minecraft: ----
|
| 885 |
+
#[test]
|
| 886 |
+
fn block_names_lose_minecraft_prefix_only() {
|
| 887 |
+
let palette: Palette = vec![
|
| 888 |
+
("minecraft:air", vec![]),
|
| 889 |
+
("create:cogwheel", vec![]),
|
| 890 |
+
("minecraft:stone", vec![]),
|
| 891 |
+
];
|
| 892 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [2, 1, 1], &palette, &pack(&[1, 2], 2)));
|
| 893 |
+
let g = parse(&data, 10).unwrap();
|
| 894 |
+
let mut names: Vec<&str> = g.keys().map(|k| k.0.as_str()).collect();
|
| 895 |
+
names.sort();
|
| 896 |
+
assert_eq!(names, vec!["create:cogwheel", "stone"]);
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
#[test]
|
| 900 |
+
fn stripped_name_keeps_properties() {
|
| 901 |
+
let palette: Palette = vec![
|
| 902 |
+
("minecraft:air", vec![]),
|
| 903 |
+
("minecraft:oak_stairs", vec![("facing", "north")]),
|
| 904 |
+
];
|
| 905 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [1, 1, 1], &palette, &pack(&[1], 2)));
|
| 906 |
+
let g = parse(&data, 10).unwrap();
|
| 907 |
+
assert!(g.contains_key(&key("oak_stairs[facing=north]")));
|
| 908 |
+
}
|
| 909 |
+
|
| 910 |
+
// ---- сдвиг ----
|
| 911 |
+
#[test]
|
| 912 |
+
fn offset_shifts_positions() {
|
| 913 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [2, 1, 1], &air_stone(), &pack(&[1, 1], 2)));
|
| 914 |
+
let g = parse_off(&data, [10, -20, 5]).unwrap();
|
| 915 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(10, -20, 5), (11, -20, 5)]);
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
#[test]
|
| 919 |
+
fn offset_adds_to_region_position() {
|
| 920 |
+
let data = litematic(|o| region(o, "r", [-5, 10, -1], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 921 |
+
let g = parse_off(&data, [100, 1, 1]).unwrap();
|
| 922 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(95, 11, 0)]);
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
#[test]
|
| 926 |
+
fn offset_with_negative_size() {
|
| 927 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [-2, 1, 1], &air_stone(), &pack(&[1, 1], 2)));
|
| 928 |
+
let g = parse_off(&data, [5, 0, 0]).unwrap();
|
| 929 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(4, 0, 0), (5, 0, 0)]);
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
#[test]
|
| 933 |
+
fn offset_applies_to_every_region() {
|
| 934 |
+
let data = litematic(|o| {
|
| 935 |
+
region(o, "a", [0, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2));
|
| 936 |
+
region(o, "b", [10, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2));
|
| 937 |
+
});
|
| 938 |
+
let g = parse_off(&data, [0, 0, 7]).unwrap();
|
| 939 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(0, 0, 7), (10, 0, 7)]);
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
#[test]
|
| 943 |
+
fn offset_applies_to_tile_entities() {
|
| 944 |
+
let data = litematic(|o| {
|
| 945 |
+
region_te(
|
| 946 |
+
o,
|
| 947 |
+
"r",
|
| 948 |
+
[0, 0, 0],
|
| 949 |
+
[2, 1, 1],
|
| 950 |
+
&air_stone(),
|
| 951 |
+
&pack(&[1, 1], 2),
|
| 952 |
+
&[(1, 0, 0, "minecraft:chest")],
|
| 953 |
+
)
|
| 954 |
+
});
|
| 955 |
+
let g = parse_off(&data, [100, 0, 0]).unwrap();
|
| 956 |
+
let k = ("stone".to_string(), r#"{id:"minecraft:chest"}"#.to_string());
|
| 957 |
+
assert_eq!(positions(&g[&k]), vec![(101, 0, 0)]);
|
| 958 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(100, 0, 0)]);
|
| 959 |
+
}
|
| 960 |
+
|
| 961 |
+
#[test]
|
| 962 |
+
fn offset_pushing_out_of_cell_range_is_error() {
|
| 963 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 964 |
+
assert!(matches!(parse_off(&data, [10_000, 0, 0]), Err(NbtError::Coord(_))));
|
| 965 |
+
assert!(matches!(parse_off(&data, [0, -1000, 0]), Err(NbtError::Coord(_))));
|
| 966 |
+
assert!(parse_off(&data, [9_999, -999, 0]).is_ok());
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
+
#[test]
|
| 970 |
+
fn offset_overflowing_i32_is_error() {
|
| 971 |
+
let data = litematic(|o| region(o, "r", [1, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 972 |
+
assert!(matches!(parse_off(&data, [i32::MAX, 0, 0]), Err(NbtError::Malformed(_))));
|
| 973 |
+
}
|
| 974 |
+
|
| 975 |
+
// ---- tile entities ----
|
| 976 |
+
#[test]
|
| 977 |
+
fn tile_entity_splits_group_and_gets_snbt() {
|
| 978 |
+
let data = litematic(|o| {
|
| 979 |
+
region_te(
|
| 980 |
+
o,
|
| 981 |
+
"r",
|
| 982 |
+
[0, 0, 0],
|
| 983 |
+
[3, 1, 1],
|
| 984 |
+
&air_stone(),
|
| 985 |
+
&pack(&[1, 1, 1], 2),
|
| 986 |
+
&[(1, 0, 0, "minecraft:chest")],
|
| 987 |
+
)
|
| 988 |
+
});
|
| 989 |
+
let g = parse(&data, 10).unwrap();
|
| 990 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(0, 0, 0), (2, 0, 0)]);
|
| 991 |
+
let with_nbt = ("stone".to_string(), r#"{id:"minecraft:chest"}"#.to_string());
|
| 992 |
+
assert_eq!(positions(&g[&with_nbt]), vec![(1, 0, 0)]);
|
| 993 |
+
}
|
| 994 |
+
|
| 995 |
+
#[test]
|
| 996 |
+
fn tile_entity_on_air_or_outside_is_ignored() {
|
| 997 |
+
let data = litematic(|o| {
|
| 998 |
+
region_te(
|
| 999 |
+
o,
|
| 1000 |
+
"r",
|
| 1001 |
+
[0, 0, 0],
|
| 1002 |
+
[2, 1, 1],
|
| 1003 |
+
&air_stone(),
|
| 1004 |
+
&pack(&[0, 1], 2),
|
| 1005 |
+
&[(0, 0, 0, "minecraft:chest"), (5, 0, 0, "minecraft:chest"), (-1, 0, 0, "x")],
|
| 1006 |
+
)
|
| 1007 |
+
});
|
| 1008 |
+
let g = parse(&data, 10).unwrap();
|
| 1009 |
+
assert_eq!(g.len(), 1);
|
| 1010 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(1, 0, 0)]);
|
| 1011 |
+
}
|
| 1012 |
+
|
| 1013 |
+
#[test]
|
| 1014 |
+
fn tile_entities_same_nbt_share_group() {
|
| 1015 |
+
let data = litematic(|o| {
|
| 1016 |
+
region_te(
|
| 1017 |
+
o,
|
| 1018 |
+
"r",
|
| 1019 |
+
[0, 0, 0],
|
| 1020 |
+
[2, 1, 1],
|
| 1021 |
+
&air_stone(),
|
| 1022 |
+
&pack(&[1, 1], 2),
|
| 1023 |
+
&[(0, 0, 0, "minecraft:chest"), (1, 0, 0, "minecraft:chest")],
|
| 1024 |
+
)
|
| 1025 |
+
});
|
| 1026 |
+
let g = parse(&data, 10).unwrap();
|
| 1027 |
+
assert_eq!(g.len(), 1);
|
| 1028 |
+
let k = ("stone".to_string(), r#"{id:"minecraft:chest"}"#.to_string());
|
| 1029 |
+
assert_eq!(positions(&g[&k]), vec![(0, 0, 0), (1, 0, 0)]);
|
| 1030 |
+
}
|
| 1031 |
+
|
| 1032 |
+
// ---- SNBT ----
|
| 1033 |
+
#[test]
|
| 1034 |
+
fn snbt_scalars_and_quoting() {
|
| 1035 |
+
let mut m: BTreeMap<String, Tag> = BTreeMap::new();
|
| 1036 |
+
m.insert("id".into(), Tag::String("a\"b\\c".into()));
|
| 1037 |
+
m.insert("Count".into(), Tag::Byte(3));
|
| 1038 |
+
m.insert("a b".into(), Tag::Short(7));
|
| 1039 |
+
m.insert("l".into(), Tag::Long(5));
|
| 1040 |
+
m.insert("d".into(), Tag::Double(1.5));
|
| 1041 |
+
m.insert("f".into(), Tag::Float(2.0));
|
| 1042 |
+
assert_eq!(
|
| 1043 |
+
compound_snbt(&m, &[]),
|
| 1044 |
+
r#"{Count:3b,"a b":7s,d:1.5d,f:2f,id:"a\"b\\c",l:5L}"#
|
| 1045 |
+
);
|
| 1046 |
+
assert_eq!(compound_snbt(&m, &["id", "Count", "a b", "d", "f"]), "{l:5L}");
|
| 1047 |
+
}
|
| 1048 |
+
|
| 1049 |
+
#[test]
|
| 1050 |
+
fn snbt_lists_and_arrays() {
|
| 1051 |
+
let mut m: BTreeMap<String, Tag> = BTreeMap::new();
|
| 1052 |
+
m.insert("list".into(), Tag::List(vec![Tag::Int(1), Tag::Int(2)]));
|
| 1053 |
+
m.insert("ints".into(), Tag::IntArray(&[0, 0, 0, 1, 0, 0, 0, 2]));
|
| 1054 |
+
m.insert("bytes".into(), Tag::ByteArray(&[1, 255]));
|
| 1055 |
+
m.insert("longs".into(), Tag::LongArray(&[0, 0, 0, 0, 0, 0, 0, 9]));
|
| 1056 |
+
let mut inner: BTreeMap<String, Tag> = BTreeMap::new();
|
| 1057 |
+
inner.insert("k".into(), Tag::Int(1));
|
| 1058 |
+
m.insert("c".into(), Tag::List(vec![Tag::Compound(inner)]));
|
| 1059 |
+
assert_eq!(
|
| 1060 |
+
compound_snbt(&m, &[]),
|
| 1061 |
+
"{bytes:[B;1b,-1b],c:[{k:1}],ints:[I;1,2],list:[1,2],longs:[L;9L]}"
|
| 1062 |
+
);
|
| 1063 |
+
}
|
| 1064 |
+
|
| 1065 |
+
// ---- ошибки и лимиты ----
|
| 1066 |
+
#[test]
|
| 1067 |
+
fn not_litematic_without_regions() {
|
| 1068 |
+
let mut data = Vec::new();
|
| 1069 |
+
named(&mut data, 10, "");
|
| 1070 |
+
int_named(&mut data, "Version", 6);
|
| 1071 |
+
data.push(0);
|
| 1072 |
+
assert!(matches!(parse(&data, 10), Err(NbtError::NotLitematic(_))));
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
#[test]
|
| 1076 |
+
fn garbage_is_malformed() {
|
| 1077 |
+
assert!(matches!(parse(&[1, 2, 3], 10), Err(NbtError::Malformed(_))));
|
| 1078 |
+
assert!(matches!(parse(&[], 10), Err(NbtError::Malformed(_))));
|
| 1079 |
+
}
|
| 1080 |
+
|
| 1081 |
+
#[test]
|
| 1082 |
+
fn truncated_is_malformed() {
|
| 1083 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [2, 1, 2], &air_stone(), &pack(&[0, 1, 1, 0], 2)));
|
| 1084 |
+
let cut = &data[..data.len() - 5];
|
| 1085 |
+
assert!(matches!(parse(cut, 10), Err(NbtError::Malformed(_))));
|
| 1086 |
+
}
|
| 1087 |
+
|
| 1088 |
+
#[test]
|
| 1089 |
+
fn index_outside_palette() {
|
| 1090 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [1, 1, 1], &air_stone(), &pack(&[3], 2)));
|
| 1091 |
+
assert!(matches!(parse(&data, 10), Err(NbtError::Malformed(_))));
|
| 1092 |
+
}
|
| 1093 |
+
|
| 1094 |
+
#[test]
|
| 1095 |
+
fn states_too_short() {
|
| 1096 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [4, 4, 4], &air_stone(), &pack(&[1], 2)));
|
| 1097 |
+
assert!(matches!(parse(&data, 100), Err(NbtError::Malformed(_))));
|
| 1098 |
+
}
|
| 1099 |
+
|
| 1100 |
+
#[test]
|
| 1101 |
+
fn block_limit() {
|
| 1102 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [2, 1, 1], &air_stone(), &pack(&[1, 1], 2)));
|
| 1103 |
+
assert!(matches!(parse(&data, 1), Err(NbtError::TooManyBlocks(1))));
|
| 1104 |
+
assert!(parse(&data, 2).is_ok());
|
| 1105 |
+
}
|
| 1106 |
+
|
| 1107 |
+
#[test]
|
| 1108 |
+
fn cancel_flag_stops_parsing() {
|
| 1109 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [2, 1, 1], &air_stone(), &pack(&[1, 1], 2)));
|
| 1110 |
+
let cancel = AtomicBool::new(true);
|
| 1111 |
+
assert_eq!(parse_litematic(&data, 10, [0, 0, 0], &cancel), Err(NbtError::Cancelled));
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
#[test]
|
| 1115 |
+
fn gz_roundtrip() {
|
| 1116 |
+
let data = litematic(|o| region(o, "r", [0, 0, 0], [1, 1, 1], &air_stone(), &pack(&[1], 2)));
|
| 1117 |
+
let g = parse_litematic_gz(&gzip(&data), &Limits::default(), [0, 0, 0], &AtomicBool::new(false)).unwrap();
|
| 1118 |
+
assert_eq!(positions(&g[&key("stone")]), vec![(0, 0, 0)]);
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
#[test]
|
| 1122 |
+
fn gunzip_limit_and_errors() {
|
| 1123 |
+
let gz = gzip(&vec![7u8; 1000]);
|
| 1124 |
+
assert_eq!(gunzip(&gz, 1000).unwrap().len(), 1000);
|
| 1125 |
+
assert!(matches!(gunzip(&gz, 999), Err(NbtError::TooLarge(999))));
|
| 1126 |
+
assert!(matches!(gunzip(b"<html>", 10), Err(NbtError::NotLitematic(_))));
|
| 1127 |
+
assert!(matches!(gunzip(&[], 10), Err(NbtError::NotLitematic(_))));
|
| 1128 |
+
let mut broken = gz.clone();
|
| 1129 |
+
broken.truncate(broken.len() / 2);
|
| 1130 |
+
assert!(gunzip(&broken, 1000).is_err());
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
#[test]
|
| 1134 |
+
fn bits_for_palette_sizes() {
|
| 1135 |
+
// 2 бита минимум; 5 записей → 3 бита; 17 записей → 5 бит
|
| 1136 |
+
let bits = |n: usize| u64::from((usize::BITS - (n - 1).leading_zeros()).max(2));
|
| 1137 |
+
assert_eq!(bits(1), 2);
|
| 1138 |
+
assert_eq!(bits(4), 2);
|
| 1139 |
+
assert_eq!(bits(5), 3);
|
| 1140 |
+
assert_eq!(bits(16), 4);
|
| 1141 |
+
assert_eq!(bits(17), 5);
|
| 1142 |
+
}
|
| 1143 |
+
}
|
src/src/store.rs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! Хранилище спарсенных схематик (в памяти процесса).
|
| 2 |
+
|
| 3 |
+
use std::collections::HashMap;
|
| 4 |
+
use std::sync::{Arc, RwLock};
|
| 5 |
+
|
| 6 |
+
use uuid::Uuid;
|
| 7 |
+
|
| 8 |
+
use crate::encoder::{self, DictEntry, EncodeError, Groups};
|
| 9 |
+
|
| 10 |
+
#[derive(Debug)]
|
| 11 |
+
pub struct Schematic {
|
| 12 |
+
/// Число уникальных блоков.
|
| 13 |
+
pub unique_blocks: usize,
|
| 14 |
+
/// Число уникальных NBT-записей (без «нет NBT»).
|
| 15 |
+
pub unique_nbt: usize,
|
| 16 |
+
/// Словарь блоков, нарезанный так, что JSON каждой части ≤ 24 000 символов.
|
| 17 |
+
pub block_parts: Vec<Vec<DictEntry>>,
|
| 18 |
+
/// Словарь NBT, нарезанный так же.
|
| 19 |
+
pub nbt_parts: Vec<Vec<DictEntry>>,
|
| 20 |
+
/// Весь текст схематики (ячейки по 28 символов).
|
| 21 |
+
pub text: String,
|
| 22 |
+
/// Конец каждой части текста (смещение в байтах).
|
| 23 |
+
pub part_ends: Vec<usize>,
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
impl Schematic {
|
| 27 |
+
pub fn build(groups: &Groups) -> Result<Self, EncodeError> {
|
| 28 |
+
let e = encoder::encode(groups)?;
|
| 29 |
+
let block_parts = encoder::split_dict(&e.blocks, encoder::DICT_PART_JSON_MAX)?;
|
| 30 |
+
let nbt_parts = encoder::split_dict(&e.nbt, encoder::DICT_PART_JSON_MAX)?;
|
| 31 |
+
Ok(Schematic {
|
| 32 |
+
unique_blocks: e.blocks.len(),
|
| 33 |
+
unique_nbt: e.nbt.len(),
|
| 34 |
+
block_parts,
|
| 35 |
+
nbt_parts,
|
| 36 |
+
text: e.text,
|
| 37 |
+
part_ends: e.part_ends,
|
| 38 |
+
})
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
#[derive(Clone, Default)]
|
| 43 |
+
pub struct Store {
|
| 44 |
+
inner: Arc<RwLock<HashMap<Uuid, Arc<Schematic>>>>,
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
impl Store {
|
| 48 |
+
pub fn insert(&self, schematic: Schematic) -> Uuid {
|
| 49 |
+
let id = Uuid::new_v4();
|
| 50 |
+
self.inner
|
| 51 |
+
.write()
|
| 52 |
+
.unwrap_or_else(|e| e.into_inner())
|
| 53 |
+
.insert(id, Arc::new(schematic));
|
| 54 |
+
id
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
pub fn get(&self, id: &Uuid) -> Option<Arc<Schematic>> {
|
| 58 |
+
self.inner
|
| 59 |
+
.read()
|
| 60 |
+
.unwrap_or_else(|e| e.into_inner())
|
| 61 |
+
.get(id)
|
| 62 |
+
.cloned()
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
#[cfg(test)]
|
| 67 |
+
mod tests {
|
| 68 |
+
use super::*;
|
| 69 |
+
|
| 70 |
+
fn sample() -> Schematic {
|
| 71 |
+
let mut cells = Vec::new();
|
| 72 |
+
encoder::push_position(&mut cells, 0, 0, 0).unwrap();
|
| 73 |
+
let mut groups = Groups::new();
|
| 74 |
+
groups.insert(("minecraft:stone".to_string(), String::new()), cells);
|
| 75 |
+
Schematic::build(&groups).unwrap()
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
#[test]
|
| 79 |
+
fn insert_and_get() {
|
| 80 |
+
let store = Store::default();
|
| 81 |
+
let id = store.insert(sample());
|
| 82 |
+
let got = store.get(&id).expect("должна найтись");
|
| 83 |
+
assert_eq!(got.unique_blocks, 1);
|
| 84 |
+
assert_eq!(got.unique_nbt, 0);
|
| 85 |
+
assert_eq!(got.part_ends.len(), 1);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
#[test]
|
| 89 |
+
fn missing_uuid() {
|
| 90 |
+
let store = Store::default();
|
| 91 |
+
assert!(store.get(&Uuid::new_v4()).is_none());
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#[test]
|
| 95 |
+
fn ids_are_unique() {
|
| 96 |
+
let store = Store::default();
|
| 97 |
+
assert_ne!(store.insert(sample()), store.insert(sample()));
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
#[test]
|
| 101 |
+
fn build_empty() {
|
| 102 |
+
let s = Schematic::build(&Groups::new()).unwrap();
|
| 103 |
+
assert_eq!(s.unique_blocks, 0);
|
| 104 |
+
assert!(s.block_parts.is_empty());
|
| 105 |
+
assert!(s.nbt_parts.is_empty());
|
| 106 |
+
assert!(s.text.is_empty());
|
| 107 |
+
assert!(s.part_ends.is_empty());
|
| 108 |
+
}
|
| 109 |
+
}
|