bson
This commit is contained in:
@@ -450,7 +450,7 @@ public class RestConvertService extends AbstractService {
|
|||||||
|
|
||||||
    1). 基本数据类型: 直接转换成byte[]
|
    1). 基本数据类型: 直接转换成byte[]
|
||||||
|
|
||||||
    2). SmallString(无特殊字符且长度小于256的字符串): length(1 byte) + byte[](utf8); 通常用于类名、字段名、枚举。
|
    2). StandardString(无特殊字符且长度小于256的字符串): length(1 byte) + byte[](utf8); 通常用于类名、字段名、枚举。
|
||||||
|
|
||||||
    3). String: length(4 bytes) + byte[](utf8);
|
    3). String: length(4 bytes) + byte[](utf8);
|
||||||
|
|
||||||
@@ -458,9 +458,9 @@ public class RestConvertService extends AbstractService {
|
|||||||
|
|
||||||
    5). Object:
|
    5). Object:
|
||||||
|
|
||||||
      1. realclass (SmallString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
|
      1. realclass (StandardString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
|
||||||
|
|
||||||
      2. 空字符串(SmallString)
|
      2. 空字符串(StandardString)
|
||||||
|
|
||||||
      3. SIGN_OBJECTB 标记位,值固定为0xBB (short)
|
      3. SIGN_OBJECTB 标记位,值固定为0xBB (short)
|
||||||
|
|
||||||
@@ -468,9 +468,9 @@ public class RestConvertService extends AbstractService {
|
|||||||
|
|
||||||
        4.1 SIGN_HASNEXT 标记位,值固定为1 (byte)
|
        4.1 SIGN_HASNEXT 标记位,值固定为1 (byte)
|
||||||
|
|
||||||
        4.2 字段类型; 1-9为基本类型&字符串; 101-109为基本类型&字符串的数组; 127为Object
|
        4.2 字段类型; 11-19为基本类型&字符串; 21-29为基本类型&字符串的数组; 127为Object
|
||||||
|
|
||||||
        4.3 字段名 (SmallString)
|
        4.3 字段名 (StandardString)
|
||||||
|
|
||||||
        4.4 字段的值Object
|
        4.4 字段的值Object
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ public class StreamDecoder<R extends Reader, T> implements Decodeable<R, Stream<
|
|||||||
this.componentType = pt.getActualTypeArguments()[0];
|
this.componentType = pt.getActualTypeArguments()[0];
|
||||||
factory.register(type, this);
|
factory.register(type, this);
|
||||||
this.componentDecoder = factory.loadDecoder(this.componentType);
|
this.componentDecoder = factory.loadDecoder(this.componentType);
|
||||||
|
} else if (factory.isReversible() && type == Stream.class) {
|
||||||
|
this.componentType = Object.class;
|
||||||
|
factory.register(type, this);
|
||||||
|
this.componentDecoder = factory.loadDecoder(this.componentType);
|
||||||
} else {
|
} else {
|
||||||
throw new ConvertException("StreamDecoder not support the type (" + type + ")");
|
throw new ConvertException("StreamDecoder not support the type (" + type + ")");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,17 +22,17 @@ import org.redkale.util.*;
|
|||||||
* <pre>
|
* <pre>
|
||||||
* BSON协议格式:
|
* BSON协议格式:
|
||||||
* 1) 基本数据类型: 直接转换成byte[]
|
* 1) 基本数据类型: 直接转换成byte[]
|
||||||
* 2) SmallString(无特殊字符且长度小于256的字符串): length(1 byte) + byte[](utf8); 通常用于类名、字段名、枚举。
|
* 2) StandardString(无特殊字符且长度小于256的字符串): length(1 byte) + byte[](utf8); 通常用于类名、字段名、枚举。
|
||||||
* 3) String: length(4 bytes) + byte[](utf8);
|
* 3) String: length(4 bytes) + byte[](utf8);
|
||||||
* 4) 数组: length(4 bytes) + byte[]...
|
* 4) 数组: length(4 bytes) + byte[]...
|
||||||
* 5) Object:
|
* 5) Object:
|
||||||
* 1、 realclass (SmallString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
|
* 1、 realclass (StandardString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
|
||||||
* 2、 空字符串(SmallString)
|
* 2、 空字符串(StandardString)
|
||||||
* 3、 SIGN_OBJECTB 标记位,值固定为0xBB (short)
|
* 3、 SIGN_OBJECTB 标记位,值固定为0xBB (short)
|
||||||
* 4、 循环字段值:
|
* 4、 循环字段值:
|
||||||
* 4.1 SIGN_HASNEXT 标记位,值固定为1 (byte)
|
* 4.1 SIGN_HASNEXT 标记位,值固定为1 (byte)
|
||||||
* 4.2 字段类型; 1-9为基本类型和字符串; 101-109为基本类型和字符串的数组; 127为Object
|
* 4.2 字段类型; 11-19为基本类型和字符串; 21-29为基本类型和字符串的数组; 127为Object
|
||||||
* 4.3 字段名 (SmallString)
|
* 4.3 字段名 (StandardString)
|
||||||
* 4.4 字段的值Object
|
* 4.4 字段的值Object
|
||||||
* 5、 SIGN_NONEXT 标记位,值固定为0 (byte)
|
* 5、 SIGN_NONEXT 标记位,值固定为0 (byte)
|
||||||
* 6、 SIGN_OBJECTE 标记位,值固定为0xEE (short)
|
* 6、 SIGN_OBJECTE 标记位,值固定为0xEE (short)
|
||||||
|
|||||||
@@ -36,15 +36,13 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
|||||||
|
|
||||||
static final Encodeable objectEncoder = instance.loadEncoder(Object.class);
|
static final Encodeable objectEncoder = instance.loadEncoder(Object.class);
|
||||||
|
|
||||||
static final Decodeable skipArrayDecoder = new BsonArrayDecoder(instance, Object[].class);
|
static final Decodeable arrayDecoder = new BsonArrayDecoder(instance, Object[].class);
|
||||||
|
|
||||||
static final Decodeable skipCollectionDecoder =
|
static final Decodeable collectionDecoder = new BsonCollectionDecoder(instance, Collection.class);
|
||||||
new BsonCollectionDecoder(instance, new TypeToken<Collection<Object>>() {}.getType());
|
|
||||||
|
|
||||||
static final Decodeable skipStreamDecoder =
|
static final Decodeable streamDecoder = new BsonStreamDecoder(instance, Stream.class);
|
||||||
new BsonStreamDecoder(instance, new TypeToken<Stream<Object>>() {}.getType());
|
|
||||||
|
|
||||||
static final Decodeable skipMapDecoder = new BsonMapDecoder(instance, Map.class);
|
static final Decodeable mapDecoder = new BsonMapDecoder(instance, Map.class);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
instance.register(Serializable.class, objectDecoder);
|
instance.register(Serializable.class, objectDecoder);
|
||||||
@@ -249,13 +247,13 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
|||||||
case 29:
|
case 29:
|
||||||
return StringArraySimpledCoder.instance;
|
return StringArraySimpledCoder.instance;
|
||||||
case 81:
|
case 81:
|
||||||
return skipArrayDecoder;
|
return arrayDecoder;
|
||||||
case 82:
|
case 82:
|
||||||
return skipCollectionDecoder;
|
return collectionDecoder;
|
||||||
case 83:
|
case 83:
|
||||||
return skipStreamDecoder;
|
return streamDecoder;
|
||||||
case 84:
|
case 84:
|
||||||
return skipMapDecoder;
|
return mapDecoder;
|
||||||
case 127:
|
case 127:
|
||||||
return BsonFactory.objectDecoder;
|
return BsonFactory.objectDecoder;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import org.redkale.annotation.Nullable;
|
import org.redkale.annotation.Nullable;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import static org.redkale.convert.Reader.SIGN_NULL;
|
import static org.redkale.convert.Reader.SIGN_NULL;
|
||||||
import org.redkale.convert.ext.ByteSimpledCoder;
|
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,11 +210,7 @@ public class BsonReader extends Reader {
|
|||||||
return bt;
|
return bt;
|
||||||
}
|
}
|
||||||
short lt = readShort();
|
short lt = readShort();
|
||||||
if (componentDecoder != null && componentDecoder != ByteSimpledCoder.instance) {
|
this.arrayItemTypeEnum = readByte();
|
||||||
this.arrayItemTypeEnum = readByte();
|
|
||||||
} else {
|
|
||||||
this.arrayItemTypeEnum = 0;
|
|
||||||
}
|
|
||||||
return (bt & 0xffff) << 16 | (lt & 0xffff);
|
return (bt & 0xffff) << 16 | (lt & 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,34 +268,17 @@ public class BsonReader extends Reader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final byte[] readByteArray() {
|
public final byte[] readByteArray() {
|
||||||
int len = readArrayB(null);
|
short bt = readShort();
|
||||||
this.arrayItemTypeEnum = 0;
|
if (bt == Reader.SIGN_NULL) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
short lt = readShort();
|
||||||
int size = 0;
|
int len = (bt & 0xffff) << 16 | (lt & 0xffff);
|
||||||
byte[] data = new byte[8];
|
byte[] values = new byte[len];
|
||||||
while (hasNext()) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
if (size >= data.length) {
|
values[i] = readByte();
|
||||||
byte[] newdata = new byte[data.length + 4];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = readByte();
|
|
||||||
}
|
|
||||||
readArrayE();
|
|
||||||
byte[] newdata = new byte[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
byte[] values = new byte[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = readByte();
|
|
||||||
}
|
|
||||||
readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user