From 37cc5dd0802bed021ecc336a1ffa29a21bc175d3 Mon Sep 17 00:00:00 2001 From: redkale Date: Fri, 4 Oct 2024 19:37:02 +0800 Subject: [PATCH] pb --- .../convert/pb/ProtobufByteBufferWriter.java | 4 +-- .../convert/pb/ProtobufBytesWriter.java | 31 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/redkale/convert/pb/ProtobufByteBufferWriter.java b/src/main/java/org/redkale/convert/pb/ProtobufByteBufferWriter.java index 2005ed064..9cd3ba724 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufByteBufferWriter.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufByteBufferWriter.java @@ -50,10 +50,10 @@ public class ProtobufByteBufferWriter extends ProtobufWriter { total += next.length(); } writeLength(total); - writeTo(bw.content(), 0, bw.length()); + writeTo(bw.content, 0, bw.length()); next = bw; while ((next = next.child) != null) { - writeTo(next.content(), 0, next.length()); + writeTo(next.content, 0, next.length()); } } diff --git a/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java b/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java index 7ec6f314b..fb5dc4b5b 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufBytesWriter.java @@ -16,9 +16,9 @@ import org.redkale.util.ByteTuple; * * @author zhangjx */ -public class ProtobufBytesWriter extends ProtobufWriter implements ByteTuple { +public class ProtobufBytesWriter extends ProtobufWriter { - private byte[] content; + byte[] content; // 链表结构 private ProtobufBytesWriter delegate; @@ -127,14 +127,23 @@ public class ProtobufBytesWriter extends ProtobufWriter implements ByteTuple { * @param array ByteArray */ public void directTo(ByteArray array) { - array.directFrom(content, count); + if (delegate == null) { + array.directFrom(content, count); + } else { + byte[] data = toArray(); + array.directFrom(data, data.length); + } } public void completed(ConvertBytesHandler handler, Consumer callback) { - handler.completed(content, 0, count, callback, this); + if (delegate == null) { + handler.completed(content, 0, count, callback, this); + } else { + byte[] data = toArray(); + handler.completed(data, 0, data.length, callback, this); + } } - @Override public byte[] toArray() { if (delegate == null) { byte[] copy = new byte[count]; @@ -151,7 +160,7 @@ public class ProtobufBytesWriter extends ProtobufWriter implements ByteTuple { next = this; int pos = count; while ((next = next.child) != null) { - System.arraycopy(next.content(), 0, data, pos, next.length()); + System.arraycopy(next.content, 0, data, pos, next.length()); pos += next.length(); } return data; @@ -245,14 +254,4 @@ public class ProtobufBytesWriter extends ProtobufWriter implements ByteTuple { delegate.writeUInt64(value); } } - - @Override - public byte[] content() { - return content; - } - - @Override - public int offset() { - return 0; - } }