pb
This commit is contained in:
@@ -84,11 +84,11 @@ public abstract class Writer {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean tiny() {
|
public final boolean tiny() {
|
||||||
return features > 0 && ConvertFactory.checkTinyFeature(features);
|
return features > 0 && ConvertFactory.checkTinyFeature(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean nullable() {
|
public final boolean nullable() {
|
||||||
return features > 0 && ConvertFactory.checkNullableFeature(features);
|
return features > 0 && ConvertFactory.checkNullableFeature(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,14 +53,14 @@ public class ProtobufBytesWriter extends ProtobufWriter { // 存在child情况
|
|||||||
@Override
|
@Override
|
||||||
protected boolean recycle() {
|
protected boolean recycle() {
|
||||||
super.recycle();
|
super.recycle();
|
||||||
if (this.delegate != null && this.pool != null) {
|
if (this.delegate != null && this.pool != null && this.parent == null) {
|
||||||
ProtobufWriter s;
|
ProtobufWriter s;
|
||||||
ProtobufWriter p = this.delegate;
|
ProtobufWriter p = this.delegate;
|
||||||
do {
|
do {
|
||||||
s = p;
|
s = p;
|
||||||
p = p.parent;
|
p = p.parent;
|
||||||
offerPool(s);
|
offerPool(s);
|
||||||
} while (p != this);
|
} while (p != this && p != null);
|
||||||
}
|
}
|
||||||
this.delegate = null;
|
this.delegate = null;
|
||||||
if (this.content.length > RESET_MAX_SIZE) {
|
if (this.content.length > RESET_MAX_SIZE) {
|
||||||
@@ -92,6 +92,11 @@ public class ProtobufBytesWriter extends ProtobufWriter { // 存在child情况
|
|||||||
this.child = result;
|
this.child = result;
|
||||||
delegate = result;
|
delegate = result;
|
||||||
} else {
|
} else {
|
||||||
|
if (delegate.child != null) {
|
||||||
|
while (delegate.child != null) {
|
||||||
|
delegate = delegate.child;
|
||||||
|
}
|
||||||
|
}
|
||||||
result.parent = delegate;
|
result.parent = delegate;
|
||||||
delegate.child = result;
|
delegate.child = result;
|
||||||
delegate = result;
|
delegate = result;
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ import org.junit.jupiter.api.Assertions;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.redkale.convert.ConvertColumn;
|
import org.redkale.convert.ConvertColumn;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.convert.pb.ProtobufArrayEncoder;
|
|
||||||
import org.redkale.convert.pb.ProtobufConvert;
|
import org.redkale.convert.pb.ProtobufConvert;
|
||||||
import org.redkale.convert.pb.ProtobufFactory;
|
import org.redkale.convert.pb.ProtobufFactory;
|
||||||
import org.redkale.convert.pb.ProtobufObjectEncoder;
|
|
||||||
import org.redkale.test.convert.User;
|
import org.redkale.test.convert.User;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.AnyValueWriter;
|
import org.redkale.util.AnyValueWriter;
|
||||||
@@ -54,7 +52,7 @@ public class UserTest {
|
|||||||
Assertions.assertEquals(bean.toString(), bean2.toString());
|
Assertions.assertEquals(bean.toString(), bean2.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void run3() throws Exception {
|
public void run3() throws Exception {
|
||||||
ProtobufFactory factory = ProtobufFactory.root();
|
ProtobufFactory factory = ProtobufFactory.root();
|
||||||
AnyValueWriter writer = AnyValueWriter.create();
|
AnyValueWriter writer = AnyValueWriter.create();
|
||||||
@@ -63,15 +61,13 @@ public class UserTest {
|
|||||||
writer.addValue("node", AnyValueWriter.create("id", "111"));
|
writer.addValue("node", AnyValueWriter.create("id", "111"));
|
||||||
writer.addValue("node", AnyValueWriter.create("id", "222"));
|
writer.addValue("node", AnyValueWriter.create("id", "222"));
|
||||||
writer.addValue("node", AnyValueWriter.create("id", "333"));
|
writer.addValue("node", AnyValueWriter.create("id", "333"));
|
||||||
System.out.println(writer);
|
String excepted =
|
||||||
ProtobufObjectEncoder encoder = (ProtobufObjectEncoder) factory.loadEncoder(AnyValueWriter.class);
|
"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]";
|
||||||
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]";
|
|
||||||
byte[] bs = factory.getConvert().convertTo(AnyValue.class, writer);
|
byte[] bs = factory.getConvert().convertTo(AnyValue.class, writer);
|
||||||
System.out.println(excepted);
|
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);
|
AnyValue other = factory.getConvert().convertFrom(AnyValue.class, bs);
|
||||||
System.out.println(other);
|
System.out.println(other);
|
||||||
Assertions.assertEquals(writer.toString(), other.toString());
|
Assertions.assertEquals(writer.toString(), other.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user