This commit is contained in:
redkale
2024-10-17 20:24:19 +08:00
parent 173a5c8a24
commit 264cc3995b
8 changed files with 28 additions and 18 deletions

View File

@@ -126,14 +126,14 @@ public class MapDecoder<R extends Reader, K, V> implements Decodeable<R, Map<K,
if (len == Reader.SIGN_VARIABLE) { if (len == Reader.SIGN_VARIABLE) {
while (in.hasNext()) { while (in.hasNext()) {
K key = kdecoder.convertFrom(in); K key = kdecoder.convertFrom(in);
in.readBlank(); in.readColon();
V value = vdecoder.convertFrom(in); V value = vdecoder.convertFrom(in);
result.put(key, value); result.put(key, value);
} }
} else { // 固定长度 } else { // 固定长度
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
K key = kdecoder.convertFrom(in); K key = kdecoder.convertFrom(in);
in.readBlank(); in.readColon();
V value = vdecoder.convertFrom(in); V value = vdecoder.convertFrom(in);
result.put(key, value); result.put(key, value);
} }

View File

@@ -294,8 +294,9 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
if (member.index > 0) { if (member.index > 0) {
member.position = member.index; member.position = member.index;
} else { } else {
while (pos.contains(++pidx)) while (pos.contains(++pidx)) {
; // do nothing
}
member.position = pidx; member.position = pidx;
} }
initForEachDeMember(factory, member); initForEachDeMember(factory, member);
@@ -375,7 +376,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
final T result = this.creator == null ? null : this.creator.create(); final T result = this.creator == null ? null : this.creator.create();
while (in.hasNext()) { while (in.hasNext()) {
DeMember member = in.readField(info); DeMember member = in.readField(info);
in.readBlank(); in.readColon();
if (member == null) { if (member == null) {
in.skipValue(); // 跳过不存在的属性的值 in.skipValue(); // 跳过不存在的属性的值
} else { } else {
@@ -392,7 +393,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
int oc = 0; int oc = 0;
while (in.hasNext()) { while (in.hasNext()) {
DeMember member = in.readField(info); DeMember member = in.readField(info);
in.readBlank(); in.readColon();
if (member == null) { if (member == null) {
in.skipValue(); // 跳过不存在的属性的值 in.skipValue(); // 跳过不存在的属性的值
} else { } else {

View File

@@ -57,11 +57,15 @@ public abstract class Reader {
*/ */
public abstract int position(); public abstract int position();
/** 跳过值(不包含值前面的字段) */ /**
* 跳过值(不包含值前面的字段)
*/
public abstract void skipValue(); public abstract void skipValue();
/** /跳过字段与值之间的多余内容, json就是跳过:符, map跳过: */ /**
public abstract void readBlank(); * 跳过字段与值之间的多余内容, json就是跳过:符, map跳过:
*/
public abstract void readColon();
/** /**
* 读取下个值的类型 * 读取下个值的类型
@@ -74,6 +78,7 @@ public abstract class Reader {
* 读取对象的类名, 返回 null 表示对象为null 返回空字符串表示当前class与返回的class一致返回非空字符串表示class是当前class的子类。 * 读取对象的类名, 返回 null 表示对象为null 返回空字符串表示当前class与返回的class一致返回非空字符串表示class是当前class的子类。
* *
* @param clazz 类名 * @param clazz 类名
*
* @return 返回字段数 * @return 返回字段数
*/ */
public String readObjectB(final Class clazz) { public String readObjectB(final Class clazz) {
@@ -97,7 +102,9 @@ public abstract class Reader {
*/ */
public abstract int readArrayB(@Nullable Decodeable componentDecoder); public abstract int readArrayB(@Nullable Decodeable componentDecoder);
/** 读取数组的尾端 */ /**
* 读取数组的尾端
*/
public abstract void readArrayE(); public abstract void readArrayE();
/** /**
@@ -109,7 +116,9 @@ public abstract class Reader {
*/ */
public abstract int readMapB(Decodeable keyDecoder, Decodeable valueDecoder); public abstract int readMapB(Decodeable keyDecoder, Decodeable valueDecoder);
/** 读取数组的尾端 */ /**
* 读取Map的尾端
*/
public abstract void readMapE(); public abstract void readMapE();
/** /**

View File

@@ -203,7 +203,7 @@ public class JsonByteBufferReader extends JsonReader {
/** 判断下一个非空白字符是否: */ /** 判断下一个非空白字符是否: */
@Override @Override
public final void readBlank() { public final void readColon() {
char ch = nextGoodChar(true); char ch = nextGoodChar(true);
if (ch == ':') { if (ch == ':') {
return; return;

View File

@@ -143,7 +143,7 @@ public class JsonMultiImplDecoder<T> implements Decodeable<JsonReader, T> {
} }
} }
} }
in.readBlank(); in.readColon();
if (member == null) { if (member == null) {
in.skipValue(); // 跳过不存在的属性的值 in.skipValue(); // 跳过不存在的属性的值
} else { } else {

View File

@@ -109,7 +109,7 @@ public class JsonReader extends Reader {
for (String key1 : keys) { for (String key1 : keys) {
while (this.hasNext()) { while (this.hasNext()) {
String field = this.readStandardString(); String field = this.readStandardString();
readBlank(); readColon();
if (key1.equals(field)) { if (key1.equals(field)) {
break; break;
} }
@@ -131,7 +131,7 @@ public class JsonReader extends Reader {
case '{': case '{':
while (hasNext()) { while (hasNext()) {
this.readStandardString(); // 读掉field this.readStandardString(); // 读掉field
this.readBlank(); this.readColon();
this.skipValue(); this.skipValue();
} }
break; break;
@@ -347,7 +347,7 @@ public class JsonReader extends Reader {
/** 判断下一个非空白字符是否: */ /** 判断下一个非空白字符是否: */
@Override @Override
public void readBlank() { public void readColon() {
char ch = nextGoodChar(true); char ch = nextGoodChar(true);
if (ch == ':') { if (ch == ':') {
return; return;

View File

@@ -147,7 +147,7 @@ public class ProtobufReader extends Reader {
/** 判断下一个非空白字节是否: */ /** 判断下一个非空白字节是否: */
@Override @Override
public final void readBlank() { public final void readColon() {
// do nothing // do nothing
} }

View File

@@ -111,7 +111,7 @@ public class InnerCoderEntityTest {
final Object[] params = new Object[deMembers.length]; final Object[] params = new Object[deMembers.length];
while (in.hasNext()) { while (in.hasNext()) {
DeMember member = in.readField(memberInfo); // 读取字段名 DeMember member = in.readField(memberInfo); // 读取字段名
in.readBlank(); // 读取字段名与字段值之间的间隔符JSON则是跳过冒号: in.readColon(); // 读取字段名与字段值之间的间隔符JSON则是跳过冒号:
if (member == null) { if (member == null) {
in.skipValue(); // 跳过不存在的字段的值, 一般不会发生 in.skipValue(); // 跳过不存在的字段的值, 一般不会发生
} else { } else {