This commit is contained in:
redkale
2024-10-04 19:37:02 +08:00
parent a3cbc19de9
commit 37cc5dd080
2 changed files with 17 additions and 18 deletions

View File

@@ -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());
}
}

View File

@@ -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<ProtobufWriter> 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;
}
}