This commit is contained in:
@@ -23,8 +23,7 @@ public final class EnMember<W extends Writer, T, F> implements Comparable<EnMemb
|
||||
|
||||
private final boolean istring;
|
||||
|
||||
private final boolean isnumber;
|
||||
|
||||
//private final boolean isnumber;
|
||||
private final boolean isbool;
|
||||
|
||||
public EnMember(Attribute<T, F> attribute, Encodeable<W, F> encoder) {
|
||||
@@ -33,16 +32,13 @@ public final class EnMember<W extends Writer, T, F> implements Comparable<EnMemb
|
||||
Class t = attribute.type();
|
||||
this.istring = CharSequence.class.isAssignableFrom(t);
|
||||
this.isbool = t == Boolean.class || t == boolean.class;
|
||||
this.isnumber = Number.class.isAssignableFrom(t) || (!this.isbool && t.isPrimitive());
|
||||
//this.isnumber = Number.class.isAssignableFrom(t) || (!this.isbool && t.isPrimitive());
|
||||
}
|
||||
|
||||
public boolean write(final W out, final boolean comma, final T obj) {
|
||||
F value = attribute.get(obj);
|
||||
if (value == null) return comma;
|
||||
if (out.isTiny()) {
|
||||
// if (isnumber) {
|
||||
// if (((Number) value).intValue() == 0) return comma;
|
||||
// }
|
||||
if (istring) {
|
||||
if (((CharSequence) value).length() == 0) return comma;
|
||||
} else if (isbool) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package com.wentch.redkale.convert.bson;
|
||||
|
||||
import com.wentch.redkale.convert.*;
|
||||
import com.wentch.redkale.convert.ext.*;
|
||||
import com.wentch.redkale.util.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
|
||||
@@ -29,6 +30,8 @@ public final class BsonReader implements Reader {
|
||||
|
||||
private int position = -1;
|
||||
|
||||
private byte typeval; //字段的类型值 对应 BsonWriter.writeField
|
||||
|
||||
private byte[] content;
|
||||
|
||||
public BsonReader() {
|
||||
@@ -58,6 +61,7 @@ public final class BsonReader implements Reader {
|
||||
|
||||
protected boolean recycle() {
|
||||
this.position = -1;
|
||||
this.typeval = 0;
|
||||
//this.limit = -1;
|
||||
this.content = null;
|
||||
return true;
|
||||
@@ -72,7 +76,56 @@ public final class BsonReader implements Reader {
|
||||
*/
|
||||
@Override
|
||||
public final void skipValue() {
|
||||
|
||||
if (typeval == 0) return;
|
||||
final byte val = this.typeval;
|
||||
this.typeval = 0;
|
||||
switch (val) {
|
||||
case 1: readBoolean();
|
||||
break;
|
||||
case 2: readByte();
|
||||
break;
|
||||
case 3: readShort();
|
||||
break;
|
||||
case 4: readChar();
|
||||
break;
|
||||
case 5: readInt();
|
||||
break;
|
||||
case 6: readLong();
|
||||
break;
|
||||
case 7: readFloat();
|
||||
break;
|
||||
case 8: readDouble();
|
||||
break;
|
||||
case 9: readString();
|
||||
break;
|
||||
case 101:
|
||||
BoolArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 102:
|
||||
ByteArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 103:
|
||||
ShortArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 104:
|
||||
CharArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 105:
|
||||
IntArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 106:
|
||||
LongArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 107:
|
||||
FloatArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 108:
|
||||
DoubleArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 109:
|
||||
StringArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,6 +198,7 @@ public final class BsonReader implements Reader {
|
||||
@Override
|
||||
public DeMember readField(final AtomicInteger index, final DeMember[] members) {
|
||||
final String exceptedfield = readSmallString();
|
||||
this.typeval = readByte();
|
||||
final int len = members.length;
|
||||
int v = index.get();
|
||||
if (v >= len) {
|
||||
|
||||
@@ -171,6 +171,46 @@ public final class BsonWriter implements Writer {
|
||||
public final void writeField(boolean comma, Attribute attribute) {
|
||||
writeByte(BsonReader.SIGN_HASNEXT);
|
||||
writeSmallString(attribute.field());
|
||||
byte typeval = 127; //字段的类型值
|
||||
final Class type = attribute.type();
|
||||
if (type == boolean.class || type == Boolean.class) {
|
||||
typeval = 1;
|
||||
} else if (type == byte.class || type == Byte.class) {
|
||||
typeval = 2;
|
||||
} else if (type == short.class || type == Short.class) {
|
||||
typeval = 3;
|
||||
} else if (type == char.class || type == Character.class) {
|
||||
typeval = 4;
|
||||
} else if (type == int.class || type == Integer.class) {
|
||||
typeval = 5;
|
||||
} else if (type == long.class || type == Long.class) {
|
||||
typeval = 6;
|
||||
} else if (type == float.class || type == Float.class) {
|
||||
typeval = 7;
|
||||
} else if (type == double.class || type == Double.class) {
|
||||
typeval = 8;
|
||||
} else if (type == String.class) {
|
||||
typeval = 9;
|
||||
} else if (type == boolean[].class || type == Boolean[].class) {
|
||||
typeval = 101;
|
||||
} else if (type == byte[].class || type == Byte[].class) {
|
||||
typeval = 102;
|
||||
} else if (type == short[].class || type == Short[].class) {
|
||||
typeval = 103;
|
||||
} else if (type == char[].class || type == Character[].class) {
|
||||
typeval = 104;
|
||||
} else if (type == int[].class || type == Integer[].class) {
|
||||
typeval = 105;
|
||||
} else if (type == long[].class || type == Long[].class) {
|
||||
typeval = 106;
|
||||
} else if (type == float[].class || type == Float[].class) {
|
||||
typeval = 107;
|
||||
} else if (type == double[].class || type == Double[].class) {
|
||||
typeval = 108;
|
||||
} else if (type == String[].class) {
|
||||
typeval = 109;
|
||||
}
|
||||
writeByte(typeval);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user