This commit is contained in:
redkale
2024-09-30 08:59:17 +08:00
parent c847b349a2
commit 8cf8a2c037
5 changed files with 31 additions and 51 deletions

View File

@@ -450,7 +450,7 @@ public class RestConvertService extends AbstractService {
    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);
@@ -458,9 +458,9 @@ public class RestConvertService extends AbstractService {
    5). Object:
      1. realclass (SmallString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
      1. realclass (StandardString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
      2. 空字符串(SmallString)
      2. 空字符串(StandardString)
      3. SIGN_OBJECTB 标记位值固定为0xBB (short)
@@ -468,9 +468,9 @@ public class RestConvertService extends AbstractService {
        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

View File

@@ -43,6 +43,10 @@ public class StreamDecoder<R extends Reader, T> implements Decodeable<R, Stream<
this.componentType = pt.getActualTypeArguments()[0];
factory.register(type, this);
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 {
throw new ConvertException("StreamDecoder not support the type (" + type + ")");
}

View File

@@ -22,17 +22,17 @@ import org.redkale.util.*;
* <pre>
* BSON协议格式:
* 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);
* 4) 数组: length(4 bytes) + byte[]...
* 5) Object:
* 1、 realclass (SmallString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
* 2、 空字符串(SmallString)
* 1、 realclass (StandardString) (如果指定格式化的class与实体对象的class不一致才会有该值, 该值可以使用@ConvertEntity给其取个别名)
* 2、 空字符串(StandardString)
* 3、 SIGN_OBJECTB 标记位值固定为0xBB (short)
* 4、 循环字段值:
* 4.1 SIGN_HASNEXT 标记位值固定为1 (byte)
* 4.2 字段类型; 1-9为基本类型和字符串; 101-109为基本类型和字符串的数组; 127为Object
* 4.3 字段名 (SmallString)
* 4.2 字段类型; 11-19为基本类型和字符串; 21-29为基本类型和字符串的数组; 127为Object
* 4.3 字段名 (StandardString)
* 4.4 字段的值Object
* 5、 SIGN_NONEXT 标记位值固定为0 (byte)
* 6、 SIGN_OBJECTE 标记位值固定为0xEE (short)

View File

@@ -36,15 +36,13 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
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 =
new BsonCollectionDecoder(instance, new TypeToken<Collection<Object>>() {}.getType());
static final Decodeable collectionDecoder = new BsonCollectionDecoder(instance, Collection.class);
static final Decodeable skipStreamDecoder =
new BsonStreamDecoder(instance, new TypeToken<Stream<Object>>() {}.getType());
static final Decodeable streamDecoder = new BsonStreamDecoder(instance, Stream.class);
static final Decodeable skipMapDecoder = new BsonMapDecoder(instance, Map.class);
static final Decodeable mapDecoder = new BsonMapDecoder(instance, Map.class);
static {
instance.register(Serializable.class, objectDecoder);
@@ -249,13 +247,13 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
case 29:
return StringArraySimpledCoder.instance;
case 81:
return skipArrayDecoder;
return arrayDecoder;
case 82:
return skipCollectionDecoder;
return collectionDecoder;
case 83:
return skipStreamDecoder;
return streamDecoder;
case 84:
return skipMapDecoder;
return mapDecoder;
case 127:
return BsonFactory.objectDecoder;
default:

View File

@@ -9,7 +9,6 @@ import java.nio.charset.StandardCharsets;
import org.redkale.annotation.Nullable;
import org.redkale.convert.*;
import static org.redkale.convert.Reader.SIGN_NULL;
import org.redkale.convert.ext.ByteSimpledCoder;
import org.redkale.util.*;
/**
@@ -211,11 +210,7 @@ public class BsonReader extends Reader {
return bt;
}
short lt = readShort();
if (componentDecoder != null && componentDecoder != ByteSimpledCoder.instance) {
this.arrayItemTypeEnum = readByte();
} else {
this.arrayItemTypeEnum = 0;
}
this.arrayItemTypeEnum = readByte();
return (bt & 0xffff) << 16 | (lt & 0xffff);
}
@@ -273,34 +268,17 @@ public class BsonReader extends Reader {
@Override
public final byte[] readByteArray() {
int len = readArrayB(null);
this.arrayItemTypeEnum = 0;
if (len == Reader.SIGN_NULL) {
short bt = readShort();
if (bt == Reader.SIGN_NULL) {
return null;
}
if (len == Reader.SIGN_VARIABLE) {
int size = 0;
byte[] data = new byte[8];
while (hasNext()) {
if (size >= data.length) {
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;
short lt = readShort();
int len = (bt & 0xffff) << 16 | (lt & 0xffff);
byte[] values = new byte[len];
for (int i = 0; i < values.length; i++) {
values[i] = readByte();
}
return values;
}
@Override