Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 985117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:07:11+00:00 2026-05-16T05:07:11+00:00

I want to write a parser for NBT (Named Binary Tags) structures. The format

  • 0

I want to write a parser for NBT (Named Binary Tags) structures. The format is represented like this:

TAG_Compound("hello world"): 1 entries
{
    TAG_String("name"): Bananrama
}

And in memory (or the file it’s stored in) as hexadecimal view:

0000000: 0a 00 0b 68 65 6c 6c 6f 20 77 6f 72 6c 64 08 00  ...hello world..
0000010: 04 6e 61 6d 65 00 09 42 61 6e 61 6e 72 61 6d 61  .name..Bananrama
0000020: 00                                               .
  • 0x0a = TAG_Compound
    • 0x00 0x0b = name is 11 characters long
    • “hello world”
  • 0x08 = TAG_String
    • 0x00 0x04 = name is 4 characters long
    • “name”
    • 0x00 0x09 = payload is 9 characters
    • “Bananarama”
  • 0x00 = TAG_End

It can get more complicated with more and more nested TAG_Compounds like a tree structure.

Now my question is not exactly about parsing the format, it’s really easy. I would rather like to know how I could efficiently and more importantly convenietly store it for later usage.

I know I can’t obtain a degree of ease like

tags["hello world"]["name"] = "Bananrama"

But what’s the best way to store it while keeping it easy to use? I thought about a nbt_compound structure (because every NBT tree has at least one root compound), have it store how many children it has and contain an array of nbt_value structs that would store the type and content of that value. Is that a good idea?

Edit: The full specification can be seen here

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:07:12+00:00Added an answer on May 16, 2026 at 5:07 am

    I am certain this code is broken, but the idea is what I am trying to convey. I think I would use a Tag object, like

    struct TagHeader
    {
      TagType type;  // Enum of COMPOUND, STRING, etc
      char *name;
    }
    
    struct TagCompound
    {
      TagHeader header;
      int nelems;
      void *children;
    }
    
    struct TagString
    {
      TagHeader hearder;
      char *value;
    }
    

    With a function, like

    void *get_value(void *root, char *name)
    {
      int i;
      if (! root) return NULL;
    
      if (((TagHeader *) root)->type == COMPOUND)
      {
        TagCompound *c = (TagCompound *)root;
        for (i = 0; i < c->nelems; i++)
        {
          if (strcmp(((TagHeader *) c->values[i])->name, name) == 0)
          {
            return c->values[i];
          }
        }
        return NULL;
      } else if ( /* handle other tag Types */ ) {
      }
      return NULL;
    }
    

    Then access it like:

    get_value(get_value(root, "Hello World"), "name");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a parser for Blender's .obj file. The file format seems
I want write a little code analyzer which parses nested structures and translates into
Hello I want write my own desktop sharing application in Java. The application should
I want to write symple (consisting of one preg_replace call) forum parser and I
i want to write a parser which search some city names or other geographic
I want to write a parser that takes an email or other text that
I want to write a Parser that produces some data structure and validates its
I'm using boost::spirit to write a parser, lexer here is what i want to
I'd like to write a parser for hashtags. I have been reading the blog
I want to write a simple parser for a subset of Jade , generating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.