diff --git a/.gitignore b/.gitignore
index 677190f..f65cb8b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ bin/
.project
.class
.jar
+*.swp
diff --git a/pom.xml b/pom.xml
index 22b91b7..db9dc62 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.zvidia
pomelo
- 1.0-SNAPSHOT
+ 1.0-websocket
junit
@@ -55,4 +55,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/java/com/zvidia/pomelo/protobuf/Codec.java b/src/main/java/com/zvidia/pomelo/protobuf/Codec.java
index ff072a9..fa7e4cf 100644
--- a/src/main/java/com/zvidia/pomelo/protobuf/Codec.java
+++ b/src/main/java/com/zvidia/pomelo/protobuf/Codec.java
@@ -16,7 +16,18 @@ public static byte[] encodeUInt32(int num) {
}
public static int decodeUInt32(byte[] bytes) {
- return ByteUtils.bytesToInt(bytes);
+ int result = 0;
+ for(int i=0; i 0)
+ {
+ return result;
+ }
+ }
+
+ return result;
}
public static byte[] encodeSInt32(int num) {
@@ -24,7 +35,10 @@ public static byte[] encodeSInt32(int num) {
}
public static int decodeSInt32(byte[] bytes) {
- return ByteUtils.bytesToInt(bytes);
+ int uResult = Codec.decodeUInt32(bytes);
+ int flag = ((uResult % 2) == 1 ) ? -1 : 1;
+
+ return ((uResult % 2 + uResult)/2) * flag;
}
public static byte[] encodeUInt64(long num) {
diff --git a/src/main/java/com/zvidia/pomelo/protobuf/Decoder.java b/src/main/java/com/zvidia/pomelo/protobuf/Decoder.java
index d732328..8e408a3 100644
--- a/src/main/java/com/zvidia/pomelo/protobuf/Decoder.java
+++ b/src/main/java/com/zvidia/pomelo/protobuf/Decoder.java
@@ -124,15 +124,15 @@ private Object decodeProp(String type, JSONObject proto) throws JSONException {
}
case _int32:
case _sInt32: {
- return getByte() & 0xff;
+ return Codec.decodeSInt32(getBytes(false));// & 0xff;
}
case _float: {
- float aFloat = buffer.getFloat(offset);
+ float aFloat = buffer.getFloat();
offset += 4;
return aFloat;
}
case _double: {
- double aDouble = buffer.getDouble(offset);
+ double aDouble = buffer.getDouble();
offset += 8;
return aDouble;
}
@@ -184,12 +184,16 @@ private byte getByte() {
}
private byte[] getBytes(boolean flag) {
- ByteBuffer buf = ByteBuffer.allocate(4);
+ ByteBuffer buf = ByteBuffer.allocate(5);
int pos = offset;
flag = flag || false;
- int b = buffer.getInt(pos);
- buf.putInt(b);
- pos += 4;
+ byte b;
+ do{
+ b = buffer.get();
+ buf.put(b);
+ pos += 1;
+ }while(b<0);
+
if (!flag) {
offset = pos;
buffer.position(pos);