Commits

Anonymous committed 1ef5afb

added support for unsigned lists

Comments (0)

Files changed (4)

core/dependency-reduced-pom.xml

   <parent>
     <artifactId>styx-root</artifactId>
     <groupId>com.cubeia.styx</groupId>
-    <version>1.15</version>
+    <version>1.16-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>styx-core</artifactId>

core/src/main/java/com/cubeia/firebase/io/PacketInputStream.java

 		}
 	}
 	
-    public void loadLongArray(long[] data) throws IOException {
+	public void loadUint32Array(long[] data) throws IOException {
+		for (int i = 0; i < data.length; i++) {
+			data[i] = loadUnsignedInt();
+		}
+	}
+	
+	public void loadUint16Array(int[] data) throws IOException {
+		for (int i = 0; i < data.length; i++) {
+			data[i] = loadUnsignedShort();
+		}
+	}
+	
+	public void loadUint8Array(short[] data) throws IOException {
+		for (int i = 0; i < data.length; i++) {
+			data[i] = (short) (inBuffer.get() & 0xff);
+		}
+	}
+    
+	public void loadLongArray(long[] data) throws IOException {
         for (int i = 0; i < data.length; i++) {
             data[i] = inBuffer.getLong();
         }

core/src/main/java/com/cubeia/firebase/io/PacketOutputStream.java

 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.nio.ByteBuffer;
 
 /**
  * Handles the serialization of the Styx wire format.
     }
     
     public void saveUnsignedInt(long val) throws IOException {
-        os.write((byte) (0xff & val >>> 24));
-        os.write((byte) (0xff & val >>> 16));
-        os.write((byte) (0xff & val >>> 8));
-        os.write((byte) (0xff & val));
+    	int b1,b2,b3,b4;
+    	ByteBuffer bb = ByteBuffer.allocate(4);
+    	b1 = (int) ((val & 0xff000000) >>> 24);
+    	b2 = (int) ((val & 0x00ff0000) >>> 16);
+    	b3 = (int) ((val & 0x0000ff00) >>> 8);
+    	b4 = (int) ((val & 0x000000ff));
+    	
+    	bb.put((byte) (b1 & 0xff));
+    	bb.put((byte) (b2 & 0xff));
+    	bb.put((byte) (b3 & 0xff));
+    	bb.put((byte) (b4 & 0xff));
+        
+    	os.write(bb.array());
+        
     }
     
     public void saveLong(long val) throws IOException {
 		}
 	}
 	
+	public void saveUint32Array(long[] data) throws IOException {
+		for (long val : data) {
+			saveUnsignedInt(val);
+		}
+	}
+	
+	public void saveUint16Array(int[] data) throws IOException {
+		for (int val : data) {
+			saveUnsignedShort(val);
+		}
+	}
+
+	public void saveUint8Array(short[] data) throws IOException {
+		for (short val : data) {
+			saveUnsignedByte(val);
+		}
+	}
+	
     public void saveArray(long[] data) throws IOException {
         for (long val : data) {
             os.writeLong(val);

maven/protocol-generator-plugin/src/main/scripts/java_generator.rb

     type = jtype(list.obj_type)
     # uint8 array *is* a byte-array
     if(list.obj_type == "uint8")
-      wi("public byte[] #{camelcase(list.name)} = new byte[0];")
-      result = "byte[]"   
+      wi("public short[] #{camelcase(list.name)} = new short[0];")
+      result = "short[]"   
     elsif(builtin?(list.obj_type))
       # If complex type, then use List 
       if (UNSIGNED_TYPES.has_key?(type))
       wi("}")
       @indent_level -= 1
       wi("}")
-      
+
+    elsif list.obj_type == "uint8"
+      wi("ps.saveInt(#{name}.length);")
+      wi("ps.saveUint8Array(#{name});")
+   
+    elsif list.obj_type == "uint16"
+      wi("ps.saveInt(#{name}.length);")
+      wi("ps.saveUint16Array(#{name});")
+   
+    elsif list.obj_type == "uint32"
+      wi("ps.saveInt(#{name}.length);")
+      wi("ps.saveUint32Array(#{name});")
+       
     elsif(builtin?(list.obj_type))
       # Save as array
       wi("ps.saveInt(#{name}.length);")
     if(list.obj_type == "uint8")
       # Array of uint8 *is* byte
       wi("int #{name}Count = ps.loadInt();")
-      wi("#{name} = new byte[#{name}Count];")
-      wi("ps.loadByteArray(#{name});")
+      wi("#{name} = new short[#{name}Count];")
+      wi("ps.loadUint8Array(#{name});")
+   
+    elsif(list.obj_type == "uint16")
+        wi("int #{name}Count = ps.loadInt();")
+        wi("#{name} = new #{ltype}[#{name}Count];")
+        wi("ps.loadUint16Array(#{name});")
+    
+    elsif(list.obj_type == "uint32")
+        wi("int #{name}Count = ps.loadInt();")
+        wi("#{name} = new #{ltype}[#{name}Count];")
+        wi("ps.loadUint32Array(#{name});")
       
     elsif(builtin?(list.obj_type))
       wi("int #{name}Count = ps.loadInt();")