# HG changeset patch
# User yabiku
# Date 1161503925 -32400
# Node ID 55632138c7a5d5249f6778c0325eeb1fd76a69ce
# Parent 3ac650d064d50b45ad5f204d8d3bb05cb873d5f0
add
diff -r 3ac650d064d5 -r 55632138c7a5 .classpath
--- a/.classpath Sun Oct 22 15:32:23 2006 +0900
+++ b/.classpath Sun Oct 22 16:58:45 2006 +0900
@@ -3,5 +3,6 @@
+
diff -r 3ac650d064d5 -r 55632138c7a5 src/sample/merge/Merge.java
--- 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();
+ }
}
diff -r 3ac650d064d5 -r 55632138c7a5 src/sample/pack/PackTest.java
--- 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[]) {
diff -r 3ac650d064d5 -r 55632138c7a5 src/sample/pack/PackTest3.java
--- /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();
+ }
+}