pb
This commit is contained in:
@@ -42,6 +42,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Boolean value) {
|
||||||
|
return (value == null || !value) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Boolean value) {
|
public int computeSize(Boolean value) {
|
||||||
return value == null ? 0 : 1;
|
return value == null ? 0 : 1;
|
||||||
@@ -68,6 +74,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Byte value) {
|
||||||
|
return (value == null || value.byteValue() == 0) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Byte value) {
|
public int computeSize(Byte value) {
|
||||||
return value == null ? 0 : 1;
|
return value == null ? 0 : 1;
|
||||||
@@ -94,6 +106,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Character value) {
|
||||||
|
return (value == null || value.charValue() == 0) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Character value) {
|
public int computeSize(Character value) {
|
||||||
return value == null ? 0 : ProtobufFactory.computeSInt32SizeNoTag(value);
|
return value == null ? 0 : ProtobufFactory.computeSInt32SizeNoTag(value);
|
||||||
@@ -120,6 +138,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Short value) {
|
||||||
|
return (value == null || value.shortValue() == 0) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Short value) {
|
public int computeSize(Short value) {
|
||||||
return value == null ? 0 : ProtobufFactory.computeSInt32SizeNoTag(value);
|
return value == null ? 0 : ProtobufFactory.computeSInt32SizeNoTag(value);
|
||||||
@@ -146,6 +170,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Integer value) {
|
||||||
|
return (value == null || value.intValue() == 0) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Integer value) {
|
public int computeSize(Integer value) {
|
||||||
return value == null ? 0 : ProtobufFactory.computeSInt32SizeNoTag(value);
|
return value == null ? 0 : ProtobufFactory.computeSInt32SizeNoTag(value);
|
||||||
@@ -172,6 +202,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Float value) {
|
||||||
|
return (value == null || value.floatValue() == 0) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Float value) {
|
public int computeSize(Float value) {
|
||||||
return value == null ? 0 : 4;
|
return value == null ? 0 : 4;
|
||||||
@@ -198,6 +234,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Long value) {
|
||||||
|
return (value == null || value.longValue() == 0) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Long value) {
|
public int computeSize(Long value) {
|
||||||
return value == null ? 0 : ProtobufFactory.computeSInt64SizeNoTag(value);
|
return value == null ? 0 : ProtobufFactory.computeSInt64SizeNoTag(value);
|
||||||
@@ -224,6 +266,12 @@ public abstract class ProtobufCoders {
|
|||||||
return computeSize(value);
|
return computeSize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, Double value) {
|
||||||
|
return (value == null || value.doubleValue() == 0) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(Double value) {
|
public int computeSize(Double value) {
|
||||||
return value == null ? 0 : 8;
|
return value == null ? 0 : 8;
|
||||||
@@ -245,6 +293,12 @@ public abstract class ProtobufCoders {
|
|||||||
|
|
||||||
public static final ProtobufStringSimpledCoder instance = new ProtobufStringSimpledCoder();
|
public static final ProtobufStringSimpledCoder instance = new ProtobufStringSimpledCoder();
|
||||||
|
|
||||||
|
// 对象是否为空
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty(ProtobufWriter out, String value) {
|
||||||
|
return (value == null || value.isEmpty()) && out.tiny();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeSize(ProtobufWriter out, int tagSize, String value) {
|
public int computeSize(ProtobufWriter out, int tagSize, String value) {
|
||||||
if (value == null || value.isEmpty()) {
|
if (value == null || value.isEmpty()) {
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ public abstract class AnyValue {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{'" + name + "': " + value + "}";
|
||||||
|
}
|
||||||
|
|
||||||
static Entry<AnyValue>[] getEntryAnyValueArray(
|
static Entry<AnyValue>[] getEntryAnyValueArray(
|
||||||
BiPredicate<String, String> comparison, Entry<AnyValue>[] entitys, String name) {
|
BiPredicate<String, String> comparison, Entry<AnyValue>[] entitys, String name) {
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ 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;
|
||||||
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -59,15 +60,18 @@ public class UserTest {
|
|||||||
AnyValueWriter writer = AnyValueWriter.create();
|
AnyValueWriter writer = AnyValueWriter.create();
|
||||||
writer.addValue("name", "aaa");
|
writer.addValue("name", "aaa");
|
||||||
writer.addValue("name", "bbb");
|
writer.addValue("name", "bbb");
|
||||||
writer.addValue("node", AnyValueWriter.create("id", "123"));
|
writer.addValue("node", AnyValueWriter.create("id", "111"));
|
||||||
writer.addValue("node", AnyValueWriter.create("id", "456"));
|
writer.addValue("node", AnyValueWriter.create("id", "222"));
|
||||||
|
writer.addValue("node", AnyValueWriter.create("id", "333"));
|
||||||
System.out.println(writer);
|
System.out.println(writer);
|
||||||
ProtobufObjectEncoder encoder = (ProtobufObjectEncoder) factory.loadEncoder(AnyValueWriter.class);
|
ProtobufObjectEncoder encoder = (ProtobufObjectEncoder) factory.loadEncoder(AnyValueWriter.class);
|
||||||
System.out.println(encoder);
|
System.out.println(encoder);
|
||||||
ProtobufArrayEncoder stringEntrys = (ProtobufArrayEncoder) encoder.getMembers()[2].getEncoder();
|
ProtobufArrayEncoder stringEntrys = (ProtobufArrayEncoder) encoder.getMembers()[2].getEncoder();
|
||||||
System.out.println(stringEntrys);
|
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("长度: " + bs.length);
|
System.out.println(excepted);
|
||||||
|
Utility.println("pbconvert ", bs);
|
||||||
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