CENTER>
 
HyperView2.959 bannerDocumentation
 
 
Externalizer.class
This class is used to generate class specific serialization packets.
You define the class name, add fields & their names  with optional array lengths.
The Externalizer will generate almost the absolutley tightest and more efficient
serialization code possible.   I do not have exact benchmarks yet, but the resultant
code represents the base minumum number of instructions necessary.
.   You have the the option to store the Serialization Object into  the ObjectRegistry
which is a class that will be implemented by the
HyperChannel.class to determine which Objects are allowed to actually run.
It generates the read/write code and in future expansion will also generate 'C' code. 


Step 1:
Enter the class name. If it is in the ObjectRegistry  it will  be loaded
with all its fields.   Here I have already defined and saved into the ObjectRegistry
a  class  called "Test.class."

Externalizer image

As you can see the Test.class serialization list was loaded from the
ObjectRegistry.class and I have seleced "char[]" which means
single dimensional char array.

Externalizer image
 
Now a text popup asks me for the field's name
I enter "testCharArray"

Externalizer.class image

Now because this is an array it asks me for its length.
I entered 1024

Externalizer.class
 
Now the Externalizer adds char [1024] testCharArray
into the class serialization list.

This is Test.class
public class Test
{
byte testByte;
byte testByte2;
byte testShort;
byte testByteArray[256][256];
char testCharAray[1024];

Test() /
{
  // Assume we initialized our class
  // variables here.
}


}

My packet info is entered now generate the source

Externalizer image

Now I clicked "Generate" and the generation popup is displayed.
'C' source is surrently unimplemented but will be added.
global / stack is for Java & 'C' args & pointer exclusivley for 'C'.
If global is selected then the resultan code will be generated as
global class references. ie: Test.someVariable
Otherwise code will be generated as stack references
Eventually I will add standard Object serialization.
However Optimal Binary is a quantum leap more efficient.

Next I select "Save"

Externalizer image

Once I select save the ObjectRegistry popup gives you the
option to save the Serialization List into the Object Registry.
The Serialization code will still be generated.

Externalizer image

Finally the directory where the code is saved is displayed.

Externalizer image


Finally Here is the generated Serialization code for Test.class.
NOTE:  The resultant Serialization class name will be a concatenation of the class name
prepended by the String "Serialize."  hence the Serialization class for Test.class will be
called "SerializeTest.class" which has 2 methods. pack() and unpack()
/* The code generated by Externalizer.class */

public class SerializeTest implements Serialization

{
final int byteSize=67588;

SerializeTest()
{

}

public int pack(byte[] outBuffer,Object tObject)
{
Test tTest = (Test)tObject;
    int currentOffset = 0;
    int floatBits;
    long doubleBits;
                  /* byte */
   outBuffer[currentOffset++] = (byte)tTest.testByte;
                  /* byte */
   outBuffer[currentOffset++] = (byte)tTest.testByte2;
                  /* short */
   outBuffer[currentOffset++] = (byte)(tTest.testShort >>> 8);
   outBuffer[currentOffset++] = (byte)(tTest.testShort & 0xff);
                 /* byte 2D array */
   for(y=0;y<256;y++)
   {
      for(z=0;z<256;z++)
      {
         outBuffer[currentOffset++] = (byte)tTest.testByteArray[y][z];
      }
   }
                 /* char array */
   for(z=0;z<1024;z++)
   {
      outBuffer[currentOffset++] = (byte)(tTest.testCharArray[z] >>> 8);
      outBuffer[currentOffset++] = (byte)(tTest.testCharArray[z] & 0xff);
   }
    byteSize = currentOffset;return currentOffset;
}

 public int unpack(byte[] outBuffer,Object tObject)

 {
 int currentOffset = 0;
Test tTest = (Test)tObject;
                  /* byte */
   tTest.testByte = (byte)outBuffer[currentOffset++];
                  /* byte */
   tTest.testByte2 = (byte)outBuffer[currentOffset++];
                  /* short */
   tTest.testShort  = (short)(outBuffer[currentOffset++] << 8);
   tTest.testShort |= (short)(outBuffer[currentOffset++]);
                  /* byte 2D array*/
   for(y=0;y<256;y++)
   {
      for(z=0;z<256;z++)
      {        
         tTest.testByteArray[y][z] = (byte)outBuffer[currentOffset++];
      }
   }
                  /* char array*/
   for(z=0;z<1024;z++)
   {
      tTest.testCharArray = (short)((short)outBuffer[currentOffset++] << 8);

      tTest.testCharArray |= (short)(outBuffer[currentOffset++] & 0xff);
   }
   byteSize = currentOffset;
   return currentOffset;
}
}


How to implement  this.
Here is our predefined Test.class

public class Test
{
byte testByte;
byte testByte2;
short testShort;
byte testByteArray[256][256];
char testCharArray[1024];
}



public class myClass   // The Serialization implementing class
{
public void someMethod()
{
int x,y;
class test = new Test();     // Make a Test class 
int len1,len2;                                
        // this next bit is to just to put some aribtrary values into Test.class.


   test.testByte   = (byte) 100;  
   test.testByte2 = (byte) 200;
   test.testShort = (short)2000;
         // Now loop through the array and set random values.
   for(y=0;y<256;y++)
   {
      for(z=0;z<256;z++)
      {
         test.testByteArray[ y ][ z ] = (byte) (Math.Random() * (double)255.0);
      }
   }
   for(z=0;z<1024;z++)
   {
      testCharArray[z] = (short)(Math.random() * (double)0xffff);
   }
                      
   // Now the Test.class variables have real values loaded.
   // time to serialize/deserialize.


            //
            // Make the SerializeTest.class  which was generated by the Externalizer
           //
SerializeTest serializeTest = new SerializeTest();   // Make its Serialization class      
           //
           // The SerializeTest.class stores the exact bytesize.
          //
int testSize = serializeTest.byteSize;                          // Get the size in bytes
         // Instantiate the byte block
byte[] testDerivedByteData = new byte[testSize];          // exactly the right size.                                                                     
                                       // Destination byteBlock / Object to serialize.
                                          
   serializeTest.pack(testDerivedByteData ,test);

        // Now
testDerivedByteData contains the Serialized Test.
        // Lets unpack it into another Test.class Object.
 
  Test test2 = new Test();   // Make another Test.class Object.
   serializeTest.unpack(testDerivedByteData ,test2);

       // Test2.class, a Test.class now contains the test.class deserialized data.
}

}