Compare commits

...

2 Commits

Author SHA1 Message Date
BodgeMaster 93fdcb7b65 resources: Add a file with examples for possible dumpnbt output
This may be useful for future unit tests.
I did this because I had no fucking idea how to implement drawing
the tree. I still have no fucking idea.

I hope there are no errors in there. If there are any, we’ll
find out when writing the relevant unit tests.
2022-10-16 07:40:55 +02:00
BodgeMaster 8d2f3f2fa5 tools/dumpnbt: Switch from using the validator to using the parser, update some strings 2022-10-16 07:40:00 +02:00
2 changed files with 352 additions and 7 deletions

View File

@ -0,0 +1,346 @@
#############################################################################
# Examples for all types of tags: #
#############################################################################
[0: End]:
'Total: 1 byte
[0: 8 Bit Integer] name:
|Header: 7 bytes
|Payload: 1 byte
|Total: 8 bytes
'Value: 0
[0: 16 Bit Integer] name:
|Header: 7 bytes
|Payload: 2 bytes
|Total: 9 bytes
'Value: 0
[0: 32 Bit Integer] name:
|Header: 7 bytes
|Payload: 4 bytes
|Total: 11 bytes
'Value: 0
[0: 64 Bit Integer] name:
|Header: 7 bytes
|Payload: 8 bytes
|Total: 15 bytes
'Value: 0
[0: Float] name:
|Header: 7 bytes
|Payload: 4 bytes
|Total: 11 bytes
'Value: 0
[0: Double] name:
|Header: 7 bytes
|Payload: 8 bytes
|Total: 15 bytes
'Value: 0
[0: Array of 8 Bit Integers] name:
|Header: 7 bytes
|Payload: 7 bytes
|Total: 14 bytes
|Length: 3
'Values:
|0
|0
'0
[0: String] name:
|Header: 7 bytes
|Payload: 14 bytes
|Total: 21 bytes
'Value: Hello World!
[0: List] name:
|Header: 7 bytes
|Payload: 8 bytes
|Total: 15 bytes
|Contained Type: 8 Bit Integer
|Length: 3
|
|[12: 8 Bit Integer]:
| |Payload: 1 byte
| |Total: 1 byte
| 'Value: 0
|
|[13: 8 Bit Integer]:
| |Payload: 1 byte
| |Total: 1 byte
| 'Value: 0
|
'[14: 8 Bit Integer]:
|Payload: 1 byte
|Total: 1 byte
'Value: 0
[0: Compound] name:
|Header: 7 bytes
|Payload: 25 bytes
|Total: 32 bytes
|Length: 4
|
|[7: 8 Bit Integer] name:
| |Header: 7 bytes
| |Payload: 1 byte
| |Total: 8 bytes
| 'Value: 0
|
|[15: 8 Bit Integer] name:
| |Header: 7 bytes
| |Payload: 1 byte
| |Total: 8 bytes
| 'Value: 0
|
|[23: 8 Bit Integer] name:
| |Header: 7 bytes
| |Payload: 1 byte
| |Total: 8 bytes
| 'Value: 0
|
'[31: End]:
'Total: 1 byte
[0: Array of 32 Bit Integers] name:
|Header: 7 bytes
|Payload: 16 bytes
|Total: 23 bytes
|Length: 3
'Values:
|0
|0
'0
[0: Array of 64 Bit Integers] name:
|Header: 7 bytes
|Payload: 28 bytes
|Total: 35 bytes
|Length: 3
'Values:
|0
|0
'0
#############################################################################
# Output for simple_nbt (what it's supposed to look like) #
#############################################################################
[0: Compound]:
|Header: 3 bytes
|Payload: 475 bytes
|Total: 478 bytes
|Length: 15
|
|[3: String] Spaces and special characters are allowed in tag names, right?:
| |Header: 65 bytes
| |Payload: 24 bytes
| |Total: 89 bytes
| 'Value: Idk. Lets find out.
|
|[92: Compound] compound:
| |Header: 11 bytes
| |Payload: 45 bytes
| |Total: 56 bytes
| |Length: 3
| |
| |[103: 32 Bit Integer] some_number:
| | |Header: 14 bytes
| | |Payload: 4 bytes
| | |Total: 18 bytes
| | 'Value: -754506943
| |
| |[121: String] some_text:
| | |Header: 12 bytes
| | |Payload: 14 bytes
| | |Total: 26 bytes
| | 'Value: eat a cookie
| |
| '[147: End]:
| 'Total: 1 byte
|
|[148: Double] double:
| |Header: 9 bytes
| |Payload: 8 bytes
| |Total: 17 bytes
| 'Value: 623593.6542742235
|
|[165: Float] float:
| |Header: 8 bytes
| |Payload: 4 bytes
| |Total: 12 bytes
| 'Value: 35.2678337097168
|
|[177: 16 Bit Integer] int16:
| |Header: 8 bytes
| |Payload: 2 bytes
| |Total: 10 bytes
| 'Value: 2000
|
|[187: 32 Bit Integer] int32:
| |Header: 8 bytes
| |Payload: 4 bytes
| |Total: 12 bytes
| 'Value: 10101010
|
|[199: Array of 32 Bit Integers] int32_array:
| |Header: 14 bytes
| |Payload: 20 bytes
| |Total: 34 bytes
| |Length: 4
| 'Values:
| |398452796
| |43259
| |2147483647
| '1634890337
|
|[233: 64 Bit Integer] int64:
| |Header: 8 bytes
| |Payload: 8 bytes
| |Total: 16 bytes
| 'Value: 810001800766
|
|[249: Array of 64 Bit Integers] int64_array:
| |Header: 14 bytes
| |Payload: 44 bytes
| |Total: 58 bytes
| |Length: 5
| 'Values:
| |239865
| |23586749
| |9223372036854775807
| |188944201329624
| '3116157694992754
|
|[307: 8 Bit Integer] int8:
| |Header: 7 bytes
| |Payload: 1 byte
| |Total: 8 bytes
| 'Value: 100
|
|[315: Array of 8 Bit Integers] int8_array:
| |Header: 13 bytes
| |Payload: 12 bytes
| |Total: 25 bytes
| |Length: 8
| 'Values:
| |113
| |53
| |119
| |98
| |84
| |100
| |245
| '50
|
|[340: List] list_int8:
| |Header: 12 bytes
| |Payload: 10 bytes
| |Total: 22 bytes
| |Contained Type: 8 Bit Integer
| |Length: 5
| |
| |[357: 8 Bit Integer]:
| | |Payload: 1 byte
| | |Total: 1 byte
| | 'Value: 65
| |
| |[358: 8 Bit Integer]:
| | |Payload: 1 byte
| | |Total: 1 byte
| | 'Value: 96
| |
| |[359: 8 Bit Integer]:
| | |Payload: 1 byte
| | |Total: 1 byte
| | 'Value: 78
| |
| |[360: 8 Bit Integer]:
| | |Payload: 1 byte
| | |Total: 1 byte
| | 'Value: 127
| |
| '[361: 8 Bit Integer]:
| |Payload: 1 byte
| |Total: 1 byte
| 'Value: -6
|
|[362: List] list_strings:
| |Header: 15 bytes
| |Payload: 77 bytes
| |Total: 92 bytes
| |Contained Type: String
| |Length: 12
| |
| |[382: String]:
| | |Payload: 8 bytes
| | |Total: 8 bytes
| | 'Value: Pacman
| |
| |[390: String]:
| | |Payload: 5 bytes
| | |Total: 5 bytes
| | 'Value: ate
| |
| |[395: String]:
| | |Payload: 5 bytes
| | |Total: 5 bytes
| | 'Value: all
| |
| |[400: String]:
| | |Payload: 5 bytes
| | |Total: 5 bytes
| | 'Value: the
| |
| |[405: String]:
| | |Payload: 6 bytes
| | |Total: 6 bytes
| | 'Value: dots
| |
| |[411: String]:
| | |Payload: 4 bytes
| | |Total: 4 bytes
| | 'Value: so
| |
| |[415: String]:
| | |Payload: 5 bytes
| | |Total: 5 bytes
| | 'Value: now
| |
| |[420: String]:
| | |Payload: 8 bytes
| | |Total: 8 bytes
| | 'Value: hes
| |
| |[428: String]:
| | |Payload: 8 bytes
| | |Total: 8 bytes
| | 'Value: coming
| |
| |[436: String]:
| | |Payload: 5 bytes
| | |Total: 5 bytes
| | 'Value: for
| |
| |[441: String]:
| | |Payload: 5 bytes
| | |Total: 5 bytes
| | 'Value: the
| |
| '[446: String]:
| |Payload: 8 bytes
| |Total: 8 bytes
| 'Value: words.
|
|[454: String] string:
| |Header: 9 bytes
| |Payload: 14 bytes
| |Total: 23 bytes
| 'Value: Hello World!
|
'[477: End]:
'Total: 1 byte

View File

@ -25,6 +25,7 @@
#define EXIT_USAGE 2
#define EXIT_UNIMPLEMENTED 3
int main(int argc, char* argv[]) {
std::vector<CLI::Flag> flags;
flags.push_back(CLI::Flag('h', "help", "print help and exit"));
@ -32,9 +33,9 @@ int main(int argc, char* argv[]) {
flags.push_back(CLI::Flag('x', "hexadecimal", "print numbers in hex format"));
std::vector<CLI::Option> options;
std::vector<CLI::Argument> arguments;
arguments.push_back(CLI::Argument("FILE", "path of the file to work on"));
arguments.push_back(CLI::Argument("FILE", "path of the file to dump"));
CLI::ArgumentsParser cliParser = CLI::ArgumentsParser(argc, argv, flags, options, arguments, "Present NBT in human or machine readable formats - preliminary implementation.");
CLI::ArgumentsParser cliParser = CLI::ArgumentsParser(argc, argv, flags, options, arguments, "Present NBT in human or machine readable formats");
if (cliParser.getFlag("help").value){
std::cout << cliParser.getUsage() << std::endl;
@ -70,7 +71,7 @@ int main(int argc, char* argv[]) {
std::ifstream fileStream;
fileStream.open(cliParser.getArgument(0).value, std::ios::in | std::ios::binary | std::ios::ate);
if (!fileStream.is_open()) {
std::cerr << argv[0] << ": File not found: " << cliParser.getArgument(0).value << std::endl;
std::cerr << argv[0] << ": Could not open file: " << cliParser.getArgument(0).value << std::endl;
return EXIT_RUNTIME;
}
@ -86,10 +87,8 @@ int main(int argc, char* argv[]) {
}
fileStream.close();
bool isValidData = NBT::validateRawNBTData(data, fileSize);
if (isValidData) {
std::cerr << "Valid data." << std::endl;
} else {
ErrorOr<std::vector<NBT::Tag::Generic*>> tags = NBT::deserialize(data, fileSize);
if (tags.isError) {
std::cerr << "Invalid data." << std::endl;
return EXIT_RUNTIME;
}