This commit is contained in:
redkale
2024-10-20 01:00:41 +08:00
parent a19b083478
commit c2a923619e
3 changed files with 15 additions and 14 deletions

View File

@@ -84,11 +84,11 @@ public abstract class Writer {
return this;
}
protected final boolean tiny() {
public final boolean tiny() {
return features > 0 && ConvertFactory.checkTinyFeature(features);
}
protected final boolean nullable() {
public final boolean nullable() {
return features > 0 && ConvertFactory.checkNullableFeature(features);
}

View File

@@ -53,14 +53,14 @@ public class ProtobufBytesWriter extends ProtobufWriter { // 存在child情况
@Override
protected boolean recycle() {
super.recycle();
if (this.delegate != null && this.pool != null) {
if (this.delegate != null && this.pool != null && this.parent == null) {
ProtobufWriter s;
ProtobufWriter p = this.delegate;
do {
s = p;
p = p.parent;
offerPool(s);
} while (p != this);
} while (p != this && p != null);
}
this.delegate = null;
if (this.content.length > RESET_MAX_SIZE) {
@@ -92,6 +92,11 @@ public class ProtobufBytesWriter extends ProtobufWriter { // 存在child情况
this.child = result;
delegate = result;
} else {
if (delegate.child != null) {
while (delegate.child != null) {
delegate = delegate.child;
}
}
result.parent = delegate;
delegate.child = result;
delegate = result;

View File

@@ -9,10 +9,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redkale.convert.ConvertColumn;
import org.redkale.convert.json.JsonConvert;
import org.redkale.convert.pb.ProtobufArrayEncoder;
import org.redkale.convert.pb.ProtobufConvert;
import org.redkale.convert.pb.ProtobufFactory;
import org.redkale.convert.pb.ProtobufObjectEncoder;
import org.redkale.test.convert.User;
import org.redkale.util.AnyValue;
import org.redkale.util.AnyValueWriter;
@@ -54,7 +52,7 @@ public class UserTest {
Assertions.assertEquals(bean.toString(), bean2.toString());
}
// @Test
@Test
public void run3() throws Exception {
ProtobufFactory factory = ProtobufFactory.root();
AnyValueWriter writer = AnyValueWriter.create();
@@ -63,15 +61,13 @@ public class UserTest {
writer.addValue("node", AnyValueWriter.create("id", "111"));
writer.addValue("node", AnyValueWriter.create("id", "222"));
writer.addValue("node", AnyValueWriter.create("id", "333"));
System.out.println(writer);
ProtobufObjectEncoder encoder = (ProtobufObjectEncoder) factory.loadEncoder(AnyValueWriter.class);
System.out.println(encoder);
ProtobufArrayEncoder stringEntrys = (ProtobufArrayEncoder) encoder.getMembers()[2].getEncoder();
System.out.println(stringEntrys);
String excepted = "proto-buf 89.[0x12,0x0b,0x0a,0x04,0x6e,0x61,0x6d,0x65,0x12,0x03,0x61,0x61,0x61,0x12,0x0b,0x0a,0x04,0x6e,0x61,0x6d,0x65,0x12,0x03,0x62,0x62,0x62,0x1a,0x13,0x0a,0x04,0x6e,0x6f,0x64,0x65,0x12,0x0b,0x12,0x09,0x0a,0x02,0x69,0x64,0x12,0x03,0x31,0x31,0x31,0x1a,0x13,0x0a,0x04,0x6e,0x6f,0x64,0x65,0x12,0x0b,0x12,0x09,0x0a,0x02,0x69,0x64,0x12,0x03,0x32,0x32,0x32,0x1a,0x13,0x0a,0x04,0x6e,0x6f,0x64,0x65,0x12,0x0b,0x12,0x09,0x0a,0x02,0x69,0x64,0x12,0x03,0x33,0x33,0x33]";
String excepted =
"proto-buf 89.[0x12,0x0b,0x0a,0x04,0x6e,0x61,0x6d,0x65,0x12,0x03,0x61,0x61,0x61,0x12,0x0b,0x0a,0x04,0x6e,0x61,0x6d,0x65,0x12,0x03,0x62,0x62,0x62,0x1a,0x13,0x0a,0x04,0x6e,0x6f,0x64,0x65,0x12,0x0b,0x12,0x09,0x0a,0x02,0x69,0x64,0x12,0x03,0x31,0x31,0x31,0x1a,0x13,0x0a,0x04,0x6e,0x6f,0x64,0x65,0x12,0x0b,0x12,0x09,0x0a,0x02,0x69,0x64,0x12,0x03,0x32,0x32,0x32,0x1a,0x13,0x0a,0x04,0x6e,0x6f,0x64,0x65,0x12,0x0b,0x12,0x09,0x0a,0x02,0x69,0x64,0x12,0x03,0x33,0x33,0x33]";
byte[] bs = factory.getConvert().convertTo(AnyValue.class, writer);
System.out.println(excepted);
Utility.println("pbconvert ", bs);
String rs = Utility.println("pbconvert ", bs);
Assertions.assertEquals(excepted.substring(excepted.indexOf('[')), rs.substring(rs.indexOf('[')));
AnyValue other = factory.getConvert().convertFrom(AnyValue.class, bs);
System.out.println(other);
Assertions.assertEquals(writer.toString(), other.toString());