优化代码,使用writerIndex标记代替Slice
parent
7c1f0bce6c
commit
15943a2e55
|
@ -37,7 +37,11 @@ public class CollectionSchema<T> implements Schema<List<T>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<T> readFrom(ByteBuf input, int length) {
|
public List<T> readFrom(ByteBuf input, int length) {
|
||||||
return this.readFrom(input.readSlice(length));
|
int writerIndex = input.writerIndex();
|
||||||
|
input.writerIndex(input.readerIndex() + length);
|
||||||
|
List<T> result = this.readFrom(input);
|
||||||
|
input.writerIndex(writerIndex);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,8 +35,13 @@ public class ConvertSchema<T> implements Schema<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T readFrom(ByteBuf input, int length) {
|
public T readFrom(ByteBuf input, int length) {
|
||||||
if (length > 0)
|
if (length > 0) {
|
||||||
input = input.readSlice(length);
|
int writerIndex = input.writerIndex();
|
||||||
|
input.writerIndex(input.readerIndex() + length);
|
||||||
|
T result = converter.convert(input);
|
||||||
|
input.writerIndex(writerIndex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return converter.convert(input);
|
return converter.convert(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,13 @@ public class ObjectSchema<T> implements Schema<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T readFrom(ByteBuf input, int length) {
|
public T readFrom(ByteBuf input, int length) {
|
||||||
if (length > 0)
|
if (length > 0) {
|
||||||
input = input.readSlice(length);
|
int writerIndex = input.writerIndex();
|
||||||
|
input.writerIndex(input.readerIndex() + length);
|
||||||
|
T result = schema.readFrom(input);
|
||||||
|
input.writerIndex(writerIndex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return schema.readFrom(input);
|
return schema.readFrom(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue