diff --git a/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java b/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java index c99b57b..8bc54ae 100644 --- a/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java +++ b/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java @@ -37,7 +37,11 @@ public class CollectionSchema implements Schema> { @Override public List readFrom(ByteBuf input, int length) { - return this.readFrom(input.readSlice(length)); + int writerIndex = input.writerIndex(); + input.writerIndex(input.readerIndex() + length); + List result = this.readFrom(input); + input.writerIndex(writerIndex); + return result; } @Override diff --git a/src/main/java/io/github/yezhihao/protostar/schema/ConvertSchema.java b/src/main/java/io/github/yezhihao/protostar/schema/ConvertSchema.java index 9ae56c1..051c079 100644 --- a/src/main/java/io/github/yezhihao/protostar/schema/ConvertSchema.java +++ b/src/main/java/io/github/yezhihao/protostar/schema/ConvertSchema.java @@ -35,8 +35,13 @@ public class ConvertSchema implements Schema { @Override public T readFrom(ByteBuf input, int length) { - if (length > 0) - input = input.readSlice(length); + if (length > 0) { + int writerIndex = input.writerIndex(); + input.writerIndex(input.readerIndex() + length); + T result = converter.convert(input); + input.writerIndex(writerIndex); + return result; + } return converter.convert(input); } diff --git a/src/main/java/io/github/yezhihao/protostar/schema/ObjectSchema.java b/src/main/java/io/github/yezhihao/protostar/schema/ObjectSchema.java index d29e820..9b6c6fb 100644 --- a/src/main/java/io/github/yezhihao/protostar/schema/ObjectSchema.java +++ b/src/main/java/io/github/yezhihao/protostar/schema/ObjectSchema.java @@ -25,8 +25,13 @@ public class ObjectSchema implements Schema { @Override public T readFrom(ByteBuf input, int length) { - if (length > 0) - input = input.readSlice(length); + if (length > 0) { + int writerIndex = input.writerIndex(); + input.writerIndex(input.readerIndex() + length); + T result = schema.readFrom(input); + input.writerIndex(writerIndex); + return result; + } return schema.readFrom(input); }