Omnimaga

General Discussion => Technology and Development => Computer Projects and Ideas => Topic started by: cooliojazz on March 12, 2012, 01:11:38 am

Title: GDF - Global Data Format
Post by: cooliojazz on March 12, 2012, 01:11:38 am
A few projects ago, I was thinking how I really didn't have any good ways to save data, and I was too lazy to do all this fancy data storage stuff, especially between languages.  So I made GDF, which is just a really basic file format, that I am making libs for in various languages.  Yes, there's probably lots of things like this out there, but oh well, I like this! So there.

Quick description:
There are 5 data types, integers (32 bits), longs (64 bits), floats (32 bits), double (64 bits), boolean (8 bits), strings (X bits)
It is stack based, working on an array (stack) of entries, each entry consisting of a data type and a value.  There's really not much more to it.  I have the java and php versions done (done != bugless) and am working on a version in AXE just for fun, though I don't know if I'll finish that as GDF isn't really meant for that structureless of a language, plus the whole really big numbers that the calc doesn't like thing, so we'll see...

Examples!
Code: [Select]
/* PHP code */
$gdf = new GDF();
$gdf->readGDF(fopen("test.gdf", "rb"));
echo $gdf->getSize() . " total entries.<br><br>";
while ($gdf->getSize() > 0) {
    $cur = $gdf->rpopEntry();
    echo "<br><i>" . DATATYPE::toString($cur->datatype) . "</i>: " . $cur->value;
}
Reads and prints all entries in a gdf file called "test.gdf" (html formatting)

Code: [Select]
/* Java code */
try {
    InputStream mr = new FileInputStream(new File("test.gdf"));
    GDF gdf = new GDF();
    gdf.readGDF(mr);
    System.out.println(gdf.getSize() + " total entries.\n")
    while (gdf.getSize() > 0) {
        GDF.Entry entry = gdf.rpopEntry();
        System.out.println(entry.datatype.toString() + ": " + entry.value);
    }
} catch (Exception ex) {
    ex.printStackTrace();
}
Same thing as before but in java to the standard output stream.

There's a bit more to actually saving etc, but I have almost everything pretty well documented, so it should be pretty easy to figure out.  Maybe I'll add more sample later.
The zip includes GDF.java, the java source file, and GDF.inc, the php source file.
Title: Re: GDF - Global Data Format
Post by: Juju on March 12, 2012, 01:13:14 am
Looks pretty nice.