Util Simple and Powerful serializing system,SaveableSerializing

Discussion in 'Resources' started by SkyWolf46, Jun 4, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    SkyWolf46

    SaveableSerializing is...


    Text based serializing system focused on speed and readability.
    SaveableWriter executes serialization with like next format .

    start subset
    items
    end subset



    SaveableReader basically allows 250 deep of inner class.
    This can change about create saveable object,
    but we don't recommanded that because of over 250 section waste many memory.

    Basic package of project is milkyway.SaveableSerializing.Parser
    You can read Saveable Serialization after copy that package "to" your project.
    ItemStack is Example Package, and contains ItemStack Serialization of lower 1.5.2 Minecraft ItemStack.
    We will support higher 1.5.2 ItemStack Serialization, and we are in progress.
    If you use lower 1.5.2 Serialization,ItemFlag can be ignored.
    If you want to use ItemStack Serialization,Copy milkyway.SaveableSerializing.ItemStacks on your package with Default Saveable project.

    If you need custom serializing class on this system.you have to implements SaveableData and register Instance to StaticSaveableRegistry.

    This system follows MIT Lisence.
    You are free at distribute and edit,and commercial use,
    but you must make the copyright notice and permission mark on all copies or important parts of the software.
    In addition, milkyway0308, the creator of this system, is not responsible for any problems with the use of the software without project bugs.


    Simple Example here.

    Data Saving Code
    Code:
    HashMap<String,Integer> exampleHashMap = new HashMap<>();
    
    SaveableDataWriter writer = new SaveableDataWriter(new File("Example.data");
    try{
       writer.add(new SaveableHashMap( exampleHashMap));
    catch(Exception ignored){}
    writer.flush();
    Data Loading Code
    Code:
    HashMap<String,Integer> exampleHashMap = new HashMap<>();
    // Current version(0.6.2) not contains FileNotFoundException ignore
    File file = new File("Example.dat");
    if(file.exists()){
      SaveableDataReader reader = new SaveableDataReader(file);
      List<SaveableData> data = reader.read();
      exampleHashMap = (HashMap<String,Integer>)data.get(0).getOriginal();
    
    }
    Example Custom Serializing
    Code:
      // You must implements SaveableData to Serialize class.
    public class Test implements SaveableData{
    
    // I will serialize this to variable at this time.
    List<String> toSave = new ArrayList<>();
    String data;
       // You must need empty constructor to register instance.
       public Test(){}
    // Serializing start method.
    // On data Serialize,this method will be invoke.
    @Override
        public void writeBy(StringBuilder builder) {
           // When you write default java data,you have to seperate data with escape charactor like this.
            builder.append(data).append("\n");
            try {
               // SaveableData#appendSubSet(StringBuilder builder) method call SaveableData#writeBy(StringBuilder builder)
               // with regular format.
                new SaveableArrayList(toSave).appendSubSet(builder);
            } catch (CollectionsNullException e) {
                e.printStackTrace();
            } catch (TypeNotSupportedException e) {
                e.printStackTrace();
            }
        }
      
       // This method will invoke at read Object after called SaveableData#appendObject(SaveableData data).
        @Override
        public void appendTo(List<String> builded) {
            try{
               // String data will be return by writing ordered.
                data = builded.get(0);
            }catch (Exception ex){}
        }
    
    
        // SaveableData instance seperator.
        // System will seperate Object with this name.
        @Override
        public String getName() {
            return "Test";
        }
    
        // This method will be invoke while reading SaveableData.
        @Override
        public void appendObject(String str, SaveableData data) {
            toSave = (List<String>) data.getOriginal();
        }
    
    
        // This method use to return data without class casting.
        @Override
        public Object getOriginal() {
            return null;
        }
    
        // Important : You have to return empty instance at this method.
        @Override
        public SaveableData getNewInstance() {
            return new Test();
        }
    
    
    }
    public class Main {
    
        public static void main(String[] args){
          // You have to register instance before use SaveableDataReader.
            StaticDataRegistry.getHandle().registerSaveable(new Test());
            File file = new File("test.example");
            SaveableDataWriter writer  = new SaveableDataWriter(file);
            writer.add(new Test());
            // Write and Clear Writer.
            writer.flush();
           // Current version not contains FileNotFoundException ignore.
            if(file.exists()){
               SaveableDataReader reader = new SaveableDataReader(file);
                // Congratulation! You has been successed for serializing custom class.
               Test test = (Test)reader.read().get(0);
        }
    }
    
    You can download this project at here :
    https://github.com/DevCrafters/SaveableSerializing
     
    Last edited: Jun 4, 2017
  2. Offline

    timtower Administrator Administrator Moderator

    @SkyWolf46 Are you the original developer? What did you change? What advantage does it have over the regular config for low amount storage?
     
  3. Offline

    SkyWolf46

    I am original developer of this system,using nickname "milkyway0308".
    This serializing system have advantige for complicated datas,like this.
    In my opinion,Configuration is not good at multi object saving like this:

    Code:
    
    class TestData{
    HashMap<String,Integer> item1 = new HashMap<>();
    HashMap<String,Integer> item2 = new HashMap<>();
    HashMap<String,Integer> item3 = new HashMap<>();
    HashMap<String,Integer> item4 = new HashMap<>();
    HashMap<String,Integer> item5 = new HashMap<>();
    }
    
    And this system is not suitable for user setting.
    This project have some readability,but this is only for developer's bug check.
    I maked this system for stable data save.
    If you need user setting like configuration,I can't recommend this for you.
     
    Last edited: Jun 4, 2017
  4. Offline

    timtower Administrator Administrator Moderator

    @SkyWolf46 Let it implement Serializable and add the required methods. Then you are done.
     
  5. Offline

    SkyWolf46

    Completed.Thanks for advice.
     
Thread Status:
Not open for further replies.

Share This Page