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 932823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:43:50+00:00 2026-05-15T20:43:50+00:00

Let’s say that I want a class that represents a data structure in memory.

  • 0

Let’s say that I want a class that represents a data structure in memory. In this structure, the first two bytes indicate which version of the structure it is. The order and size of the data that follows depends on the version of the structure.

For example:
Version 1 is a 10-byte structure that looks like this:

  • Byte offset 0: Format Version (2
    bytes)
  • Byte offset 2: Data section A
    (4 bytes)
  • Byte offset 6: Data section
    B (4 bytes)

Version 2 is a 20-byte structure that looks like this:

  • Byte offset 0: Format Version (2 bytes)
  • Byte offset 2: Data section A (8 bytes)
  • Byte offset 10: Data section B (6 bytes)
  • Byte offset 16: Data section C (4 bytes)

I want my class to be able to support both versions without the user of the class having to specify which version to use. That is, when the object is constructed, it should be able to use the Format Version field to determine what its structure should be. Then the getters/setters for each field should be created appropriately based on what the structure is. I also will want to be able to add support for additional structure version in the future. Each new version of the structure will most likely contain all the same fields as the older versions, but perhaps with greater allocation lengths for each of these fields, and perhaps some newly added fields.

As far as I can tell, the only constraint that I have is that the format version field always appears at byte offset 0, and is always 2 bytes long.

So, is it possible to accomplish my goal?

  • 1 1 Answer
  • 0 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-15T20:43:50+00:00Added an answer on May 15, 2026 at 8:43 pm

    Typically, you’d be creating and using separate classes for each different version of your structure. You’d give them a common interface so you could address and store them by a common type. Those different structure classes could then contain different fields and methods for dealing with the different variations of your data.

    // The common interface. Every struct knows how to read and write itself.
    public interface MultiStruct {
      public void readData(InputStream in);
      public void writeData(OutputStream out);
    }
    
    // This class knows only about storing a format code
    public abstract class AbstractMultiStruct implements MultiStruct {
      protected static final int FORM1 = 1, FORM2 = 2;
    
      private int format;
    
      public AbstractMultiStruct(int fmt) {
        this.format = fmt;
      }
    
      public int getFormat() {
        return this.format;
      }
    
    }
    
    // This is the first real struct implementation.
    public class Struct1 extends AbstractMultiStruct {
      private char[] dataA;
      private char[] dataB;
    
      public Struct1() {
        super(FORM1);
        this.dataA = new char[22];
        this.dataB = new char[33];
      }
    
      public void readData(InputStream in) {
        ...
      }
    
      public void writeData(OutputStream out) {
        ...
      }
    
      public String toString() {
        ...
      }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have two interfaces and a behavior class: public interface Creable
Let me explain best with an example. Say you have node class that can
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have multiple requirements for a password. The first is that the
Let say I've this URL: http://example.com/image-title/987654/ I want to insert download to the part
Let's say that I have a set of relations that looks like this: relations
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say you have a class, with certain properties, and that you tried your
Let's say i have a Facebook page tab (iframe) app that i want to
Let's say I want to upload unsigned integer and float data to the graphics

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.