changeset 6:55632138c7a5

add
author yabiku
date Sun, 22 Oct 2006 16:58:45 +0900
parents 3ac650d064d5
children db9137964f03
files .classpath src/sample/merge/Merge.java src/sample/pack/PackTest.java src/sample/pack/PackTest3.java
diffstat 4 files changed, 129 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/.classpath	Sun Oct 22 15:32:23 2006 +0900
+++ b/.classpath	Sun Oct 22 16:58:45 2006 +0900
@@ -3,5 +3,6 @@
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="lib" path="C:/yabiku/eclipse/plugins/org.junit_3.8.1/junit.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
--- a/src/sample/merge/Merge.java	Sun Oct 22 15:32:23 2006 +0900
+++ b/src/sample/merge/Merge.java	Sun Oct 22 16:58:45 2006 +0900
@@ -1,8 +1,30 @@
 package sample.merge;
 
 public class Merge {
+	
+	private byte[] inUserList;
+	private byte[] inTokenList;
+	
+	private byte[] outUserList;
+	private byte[] outTokenList;
+	
+	protected Merge() {
+	}
+	
+	public Merge(byte[] inUserList, byte[] inTokenList) {
+		this.inUserList = inUserList;
+		this.inTokenList = inTokenList;
+	}
 
+	public byte[] mergeRepCommand() {
+		
+		return null;
+	}
 	public int add(int i, int j) {
 		return i+j;
 	}
+	
+	public static void main(String[] args) {
+		Merge merge = new Merge();
+	}
 }
--- a/src/sample/pack/PackTest.java	Sun Oct 22 15:32:23 2006 +0900
+++ b/src/sample/pack/PackTest.java	Sun Oct 22 16:58:45 2006 +0900
@@ -30,7 +30,7 @@
     	b[1] = (byte)((i >>> 16 ) & 0xFF);
     	b[2] = (byte)((i >>>  8 ) & 0xFF);
     	b[3] = (byte)((i >>>  0 ) & 0xFF);
-        
+    	
     	return b;
     }
 
@@ -69,7 +69,9 @@
 			//System.out.println(readbyte[i]);
 		}
     	text = new String(readbyte, 0, textsiz);
-    	
+
+    	System.out.println("unpack:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ text);
+
     }
     
     public static void main(String args[]) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/sample/pack/PackTest3.java	Sun Oct 22 16:58:45 2006 +0900
@@ -0,0 +1,102 @@
+package sample.pack;
+
+
+import java.nio.*;
+
+public class PackTest3 {
+
+    private int cmd = 47;
+    private int eid = 1;
+    private int lineno = 100;
+    private int sid = 1;
+    private int seqid = 32767;
+    private int textsiz = 5;
+   
+    byte REP_INSERT_CMD = 6;
+    byte REP_INSERT_ACK_CMD = 7;
+    byte REP_JOIN_CMD = 41;
+    byte REP_JOIN_ACK_CMD = 42;
+    byte REP_PUT_CMD = 45;
+    byte REP_PUT_ACK_CMD = 46;
+    byte REP_SELECT_CMD = 47;
+    byte REP_SELECT_ACK_CMD = 48;
+    byte REP_QUIT_CMD = 53;
+    byte REP_QUIT_ACK_CMD = 54;
+
+    public byte[] chgBytes( int i ){
+    	byte[] b = new byte[4] ;
+        
+    	b[0] = (byte)((i >>> 24 ) & 0xFF);
+    	b[1] = (byte)((i >>> 16 ) & 0xFF);
+    	b[2] = (byte)((i >>>  8 ) & 0xFF);
+    	b[3] = (byte)((i >>>  0 ) & 0xFF);
+    	
+    	return b;
+    }
+
+    public ByteBuffer pack(int cmd, int sid, int eid, int seqid, int lineno, String text ) {	
+    	byte[] b_cmd = new byte[3];
+    	byte[] b_sid = new byte[3]; 
+    	byte[] b_eid = new byte[3]; 
+    	byte[] b_seqid = new byte[3]; 
+    	byte[] b_lineno = new byte[3]; 
+    	byte[] b_textsiz = new byte[3];
+    	byte[] textToByte = text.getBytes();
+    	textsiz = text.length();
+    	
+    	System.out.println(cmd);
+
+    	b_cmd = chgBytes(cmd);
+    	
+    	System.out.println(b_cmd);
+    	
+    	b_sid = chgBytes(sid);
+    	b_eid = chgBytes(eid);
+    	b_seqid = chgBytes(seqid);
+    	b_lineno = chgBytes(lineno);
+    	b_textsiz = chgBytes(textsiz);   
+
+    	ByteBuffer buffer = ByteBuffer.allocateDirect(24+textsiz);
+
+    	buffer.put(b_cmd); buffer.put(b_sid); buffer.put(b_eid);
+    	buffer.put(b_seqid); buffer.put(b_lineno); buffer.put(b_textsiz); 
+    	buffer.put(textToByte);
+
+    	return buffer;
+    }
+
+    public void unpack(ByteBuffer buffer, int cmd, int sid, int eid, int seqid, int lineno, String text) {
+    	int textsiz = 0;
+
+    	buffer.flip();
+    	buffer.getInt(cmd); buffer.getInt(sid); buffer.getInt(eid);
+    	buffer.getInt(seqid); buffer.getInt(lineno); buffer.getInt(textsiz);
+    	
+    	byte[] readbyte = new byte[textsiz];
+    	for(int i = 0; i < textsiz; i++){
+			readbyte[i] = buffer.get();
+			//System.out.println(readbyte[i]);
+		}
+    	text = new String(readbyte, 0, textsiz);
+
+    	System.out.println("unpack:" + cmd +", "+ sid +", "+ eid +", "+ seqid +", "+ lineno +", "+ text);
+
+    }
+    
+    public void job() {
+    	ByteBuffer testbuf = ByteBuffer.allocateDirect(1024);
+
+    	System.out.println("pack unpack test.");
+    	testbuf = pack(cmd, sid, eid, seqid, lineno, "test");
+	
+    	int cmd2=0,sid2=0,eid2=0,seqid2=0,lineno2=0;
+    	String string = "";
+    	unpack(testbuf,cmd2,sid2,eid2,seqid2,lineno2,string);
+
+    	System.out.println("unpack:" + cmd2 +", "+ sid2 +", "+ eid2 +", "+ seqid2 +", "+ lineno2 +", "+ string);    	
+    }
+    
+    public static void main(String args[]) {
+    	new PackTest3().job();
+    }
+}