1#![doc = include_str!("../README.md")]
2
3pub mod borrow;
4pub mod endian;
5pub mod mutf8;
6pub mod num;
7pub mod owned;
8mod swap_endian;
9
10use std::io;
11
12use thiserror::Error;
13
14pub const TAG_END: u8 = 0;
15pub const TAG_BYTE: u8 = 1;
16pub const TAG_SHORT: u8 = 2;
17pub const TAG_INT: u8 = 3;
18pub const TAG_LONG: u8 = 4;
19pub const TAG_FLOAT: u8 = 5;
20pub const TAG_DOUBLE: u8 = 6;
21pub const TAG_BYTE_ARRAY: u8 = 7;
22pub const TAG_STRING: u8 = 8;
23pub const TAG_LIST: u8 = 9;
24pub const TAG_COMPOUND: u8 = 10;
25pub const TAG_INT_ARRAY: u8 = 11;
26pub const TAG_LONG_ARRAY: u8 = 12;
27
28#[non_exhaustive]
30#[derive(Debug, Error)]
31pub enum NbtReadError {
32 #[error(transparent)]
33 Io(#[from] io::Error),
34
35 #[error("Root tag not a compound: {0}")]
36 InvalidRootTag(u8),
37
38 #[error("Invalid tag: {0}")]
39 InvalidTag(u8),
40
41 #[error("Depth limit exceeded")]
42 DepthLimitExceeded,
43}
44
45pub struct ReadOpts {
49 pub depth_limit: u16,
52
53 pub name: bool,
56}
57
58pub struct WriteOpts {
60 pub name: bool,
63}
64
65impl Default for ReadOpts {
66 #[inline]
67 fn default() -> Self {
68 Self {
69 depth_limit: 128,
70 name: true,
71 }
72 }
73}
74
75impl ReadOpts {
76 #[inline]
77 pub fn new() -> Self {
78 Self::default()
79 }
80
81 #[inline]
82 pub fn with_depth_limit(mut self, depth_limit: u16) -> Self {
83 self.depth_limit = depth_limit;
84 self
85 }
86
87 #[inline]
88 pub fn with_name(mut self, name: bool) -> Self {
89 self.name = name;
90 self
91 }
92}
93
94impl Default for WriteOpts {
95 #[inline]
96 fn default() -> Self {
97 Self { name: true }
98 }
99}
100
101impl WriteOpts {
102 #[inline]
103 pub fn new() -> Self {
104 Self::default()
105 }
106
107 #[inline]
108 pub fn with_name(mut self, name: bool) -> Self {
109 self.name = name;
110 self
111 }
112}