protobuf
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
package org.redkale.convert.bson;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
import org.redkale.util.ByteArray;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
@@ -49,24 +51,20 @@ public class BsonByteBufferWriter extends BsonWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toArray() {
|
||||
if (buffers == null) {
|
||||
return new byte[0];
|
||||
public ByteArray toByteArray() {
|
||||
ByteArray array = new ByteArray();
|
||||
if (buffers != null) {
|
||||
for (ByteBuffer buf : toBuffers()) {
|
||||
array.put(buf);
|
||||
buf.flip();
|
||||
}
|
||||
}
|
||||
int pos = 0;
|
||||
byte[] bytes = new byte[this.count];
|
||||
for (ByteBuffer buf : toBuffers()) {
|
||||
int r = buf.remaining();
|
||||
buf.get(bytes, pos, r);
|
||||
buf.flip();
|
||||
pos += r;
|
||||
}
|
||||
return bytes;
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "[count=" + this.count + "]";
|
||||
return Objects.toString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,17 +136,22 @@ public class BsonByteBufferWriter extends BsonWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] content() {
|
||||
public final byte[] toArray() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public int offset() {
|
||||
public final byte[] content() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
public final int offset() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int length() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
||||
@Override
|
||||
public void convertToBytes(final Type type, final Object value, final ConvertBytesHandler handler) {
|
||||
final BsonWriter writer = pollWriter();
|
||||
if (type == null && type == null) {
|
||||
if (type == null && value == null) {
|
||||
writer.writeNull();
|
||||
} else {
|
||||
factory.loadEncoder(type).convertTo(writer, value);
|
||||
|
||||
@@ -94,8 +94,10 @@ public class BsonWriter extends Writer implements ByteTuple {
|
||||
this.count = array.length();
|
||||
}
|
||||
|
||||
public BsonWriter withFeatures(int features) {
|
||||
return (BsonWriter) super.withFeatures(features);
|
||||
@Override
|
||||
public final BsonWriter withFeatures(int features) {
|
||||
super.withFeatures(features);
|
||||
return this;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@@ -24,14 +24,14 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
|
||||
private ByteBuffer[] buffers;
|
||||
|
||||
private int currentIndex = 0;
|
||||
|
||||
private ByteBuffer currentBuffer;
|
||||
|
||||
private int currBufIndex = 0;
|
||||
|
||||
protected JsonByteBufferReader(ByteBuffer... buffers) {
|
||||
this.buffers = buffers;
|
||||
if (buffers != null && buffers.length > 0) {
|
||||
this.currentBuffer = buffers[currentIndex];
|
||||
this.currentBuffer = buffers[currBufIndex];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
super.recycle(); // this.position 初始化值为-1
|
||||
this.currentChar = 0;
|
||||
this.buffers = null;
|
||||
this.currentIndex = 0;
|
||||
this.currBufIndex = 0;
|
||||
this.currentBuffer = null;
|
||||
return false;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
for (; ; ) {
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
this.currentBuffer = this.buffers[++this.currBufIndex];
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return this.currentBuffer.get();
|
||||
@@ -77,7 +77,7 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
}
|
||||
if (this.currentBuffer != null) {
|
||||
int remain = this.currentBuffer.remaining();
|
||||
if (remain == 0 && this.currentIndex + 1 >= this.buffers.length) {
|
||||
if (remain == 0 && this.currBufIndex + 1 >= this.buffers.length) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
|
||||
private ByteBuffer[] buffers;
|
||||
|
||||
private int index;
|
||||
private int currBufIndex;
|
||||
|
||||
public JsonByteBufferWriter(int features, Supplier<ByteBuffer> supplier) {
|
||||
this(features, null, supplier);
|
||||
@@ -48,7 +48,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
super.recycle();
|
||||
this.charset = null;
|
||||
this.buffers = null;
|
||||
this.index = 0;
|
||||
this.currBufIndex = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
if (buffers == null) {
|
||||
return new ByteBuffer[0];
|
||||
}
|
||||
for (int i = index; i < this.buffers.length; i++) {
|
||||
for (int i = currBufIndex; i < this.buffers.length; i++) {
|
||||
ByteBuffer buf = this.buffers[i];
|
||||
if (buf.position() != 0) {
|
||||
buf.flip();
|
||||
@@ -78,15 +78,15 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
|
||||
private int expand(final int byteLength) {
|
||||
if (this.buffers == null) {
|
||||
this.index = 0;
|
||||
this.currBufIndex = 0;
|
||||
this.buffers = new ByteBuffer[] {supplier.get()};
|
||||
}
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer.flip();
|
||||
buffer = supplier.get();
|
||||
this.buffers = Utility.append(this.buffers, buffer);
|
||||
this.index++;
|
||||
this.currBufIndex++;
|
||||
}
|
||||
int len = buffer.remaining();
|
||||
int size = 0;
|
||||
@@ -105,7 +105,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
throw new ConvertException("writeTo char(int.value = " + (int) ch + ") must be less 127");
|
||||
}
|
||||
expand(1);
|
||||
this.buffers[index].put((byte) ch);
|
||||
this.buffers[currBufIndex].put((byte) ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,16 +116,16 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
@Override
|
||||
public void writeTo(final byte ch) { // 只能是 0 - 127 的字符
|
||||
expand(1);
|
||||
this.buffers[index].put(ch);
|
||||
this.buffers[currBufIndex].put(ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final byte[] chs, final int start, final int len) { // 只能是 0 - 127 的字符
|
||||
int expandsize = expand(len);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
this.buffers[index].put(chs, start, len);
|
||||
this.buffers[currBufIndex].put(chs, start, len);
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
int remain = len;
|
||||
int offset = start;
|
||||
while (remain > 0) {
|
||||
@@ -154,7 +154,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
expandsize = expand(byteLength);
|
||||
}
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
if (quote) {
|
||||
buffer.put((byte) '"');
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
}
|
||||
return;
|
||||
}
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
if (quote) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -266,8 +266,8 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
}
|
||||
|
||||
private ByteBuffer nextByteBuffer() {
|
||||
this.buffers[this.index].flip();
|
||||
return this.buffers[++this.index];
|
||||
this.buffers[this.currBufIndex].flip();
|
||||
return this.buffers[++this.currBufIndex];
|
||||
}
|
||||
|
||||
protected static int encodeEscapeUTF8Length(final char[] text, final int start, final int len) {
|
||||
@@ -316,7 +316,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs = Utility.latin1ByteArray(value);
|
||||
int expandsize = expand(bs.length + (quote ? 2 : 0));
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
if (quote) {
|
||||
buffer.put((byte) '"');
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
buffer.put((byte) '"');
|
||||
}
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
if (quote) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -353,11 +353,11 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(String.valueOf(value));
|
||||
int expandsize = expand(bs1.length + bs2.length);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put(bs2);
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -379,11 +379,11 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(String.valueOf(value));
|
||||
int expandsize = expand(bs1.length + bs2.length);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put(bs2);
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -405,11 +405,11 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(String.valueOf(value));
|
||||
int expandsize = expand(bs1.length + bs2.length);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put(bs2);
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -431,13 +431,13 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(value);
|
||||
int expandsize = expand(bs1.length + bs2.length + 2);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put((byte) '"');
|
||||
buffer.put(bs2);
|
||||
buffer.put((byte) '"');
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -471,12 +471,12 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(String.valueOf(value));
|
||||
int expandsize = expand(bs1.length + bs2.length + 1);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put(bs2);
|
||||
buffer.put((byte) '}');
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -504,12 +504,12 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(String.valueOf(value));
|
||||
int expandsize = expand(bs1.length + bs2.length + 1);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put(bs2);
|
||||
buffer.put((byte) '}');
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -537,12 +537,12 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(String.valueOf(value));
|
||||
int expandsize = expand(bs1.length + bs2.length + 1);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put(bs2);
|
||||
buffer.put((byte) '}');
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -574,20 +574,20 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
}
|
||||
if (value == null || (tiny() && value.isEmpty())) {
|
||||
expand(1);
|
||||
this.buffers[index].put((byte) '}');
|
||||
this.buffers[currBufIndex].put((byte) '}');
|
||||
} else {
|
||||
byte[] bs1 = fieldBytes;
|
||||
byte[] bs2 = Utility.latin1ByteArray(value);
|
||||
int expandsize = expand(bs1.length + bs2.length + 3);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put((byte) '"');
|
||||
buffer.put(bs2);
|
||||
buffer.put((byte) '"');
|
||||
buffer.put((byte) '}');
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -635,11 +635,11 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
if (value == null || (tiny() && value.isEmpty())) {
|
||||
int expandsize = expand(2);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
ByteBuffer bb = this.buffers[index];
|
||||
ByteBuffer bb = this.buffers[currBufIndex];
|
||||
bb.put((byte) '{');
|
||||
bb.put((byte) '}');
|
||||
} else {
|
||||
ByteBuffer bb = this.buffers[index];
|
||||
ByteBuffer bb = this.buffers[currBufIndex];
|
||||
bb.put((byte) '{');
|
||||
bb = nextByteBuffer();
|
||||
bb.put((byte) '}');
|
||||
@@ -649,14 +649,14 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs2 = Utility.latin1ByteArray(value);
|
||||
int expandsize = expand(bs1.length + bs2.length + 3);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put((byte) '"');
|
||||
buffer.put(bs2);
|
||||
buffer.put((byte) '"');
|
||||
buffer.put((byte) '}');
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -705,14 +705,14 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
byte[] bs4 = Utility.latin1ByteArray(String.valueOf(value2));
|
||||
int expandsize = expand(bs1.length + bs2.length + bs3.length + bs4.length + 1);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
buffer.put(bs1);
|
||||
buffer.put(bs2);
|
||||
buffer.put(bs3);
|
||||
buffer.put(bs4);
|
||||
buffer.put((byte) '}');
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
for (byte b : bs1) {
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer = nextByteBuffer();
|
||||
@@ -805,7 +805,7 @@ public class JsonByteBufferWriter extends JsonWriter {
|
||||
final int byteLength = 2 + encodeEscapeUTF8Length(chs, 0, chs.length);
|
||||
expandsize = expand(byteLength);
|
||||
if (expandsize == 0) { // 只需要一个buffer
|
||||
final ByteBuffer buffer = this.buffers[index];
|
||||
final ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
if (quote) {
|
||||
buffer.put((byte) '"');
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ProtobufArrayEncoder<T> extends ArrayEncoder<ProtobufWriter, T> {
|
||||
|
||||
public ProtobufArrayEncoder(ProtobufFactory factory, Type type) {
|
||||
super(factory, type);
|
||||
this.componentSimpled = getComponentEncoder()instanceof SimpledCoder;
|
||||
this.componentSimpled = getComponentEncoder() instanceof SimpledCoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,8 +40,7 @@ public class ProtobufArrayEncoder<T> extends ArrayEncoder<ProtobufWriter, T> {
|
||||
} else {
|
||||
ProtobufWriter tmp = out.pollChild();
|
||||
itemEncoder.convertTo(tmp, item);
|
||||
out.writeLength(tmp.count());
|
||||
out.writeTo(tmp.toArray());
|
||||
out.writeTuple(tmp);
|
||||
out.offerChild(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,21 @@ public class ProtobufByteBufferReader extends ProtobufReader {
|
||||
|
||||
private ByteBuffer currentBuffer;
|
||||
|
||||
private int currentIndex = 0;
|
||||
private int currBufIndex = 0;
|
||||
|
||||
protected ProtobufByteBufferReader() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
protected ProtobufByteBufferReader(ByteBuffer... buffers) {
|
||||
this.buffers = buffers;
|
||||
this.currentBuffer = buffers[currentIndex];
|
||||
this.currentBuffer = buffers[currBufIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean recycle() {
|
||||
super.recycle();
|
||||
this.currentIndex = 0;
|
||||
this.currBufIndex = 0;
|
||||
this.currentBuffer = null;
|
||||
this.buffers = null;
|
||||
return false;
|
||||
@@ -39,7 +43,7 @@ public class ProtobufByteBufferReader extends ProtobufReader {
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
for (; ; ) {
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
this.currentBuffer = this.buffers[++this.currBufIndex];
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return this.currentBuffer.get();
|
||||
@@ -67,8 +71,8 @@ public class ProtobufByteBufferReader extends ProtobufReader {
|
||||
array.put(currentBuffer);
|
||||
}
|
||||
int end = buffers.length - 1;
|
||||
while (this.currentIndex < end) {
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
while (this.currBufIndex < end) {
|
||||
this.currentBuffer = this.buffers[++this.currBufIndex];
|
||||
array.put(currentBuffer);
|
||||
}
|
||||
return array.getBytes();
|
||||
@@ -83,8 +87,8 @@ public class ProtobufByteBufferReader extends ProtobufReader {
|
||||
return true;
|
||||
}
|
||||
int end = buffers.length - 1;
|
||||
while (this.currentIndex < end) {
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
while (this.currBufIndex < end) {
|
||||
this.currentBuffer = this.buffers[++this.currBufIndex];
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.redkale.convert.pb;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
@@ -16,7 +17,7 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
||||
|
||||
private ByteBuffer[] buffers;
|
||||
|
||||
private int index;
|
||||
private int currBufIndex;
|
||||
|
||||
public ProtobufByteBufferWriter(int features, boolean enumtostring, Supplier<ByteBuffer> supplier) {
|
||||
super((byte[]) null);
|
||||
@@ -29,7 +30,7 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
||||
protected boolean recycle() {
|
||||
super.recycle();
|
||||
this.buffers = null;
|
||||
this.index = 0;
|
||||
this.currBufIndex = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
||||
if (buffers == null) {
|
||||
return new ByteBuffer[0];
|
||||
}
|
||||
for (int i = index; i < this.buffers.length; i++) {
|
||||
for (int i = currBufIndex; i < this.buffers.length; i++) {
|
||||
ByteBuffer buf = this.buffers[i];
|
||||
if (buf.position() != 0) {
|
||||
buf.flip();
|
||||
@@ -47,39 +48,18 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
||||
return this.buffers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toArray() {
|
||||
if (buffers == null) {
|
||||
return new byte[0];
|
||||
}
|
||||
int pos = 0;
|
||||
byte[] bytes = new byte[this.count];
|
||||
for (ByteBuffer buf : toBuffers()) {
|
||||
int r = buf.remaining();
|
||||
buf.get(bytes, pos, r);
|
||||
buf.flip();
|
||||
pos += r;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "[count=" + this.count + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int expand(final int byteLength) {
|
||||
if (this.buffers == null) {
|
||||
this.index = 0;
|
||||
this.currBufIndex = 0;
|
||||
this.buffers = new ByteBuffer[] {supplier.get()};
|
||||
}
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
if (!buffer.hasRemaining()) {
|
||||
buffer.flip();
|
||||
buffer = supplier.get();
|
||||
this.buffers = Utility.append(this.buffers, buffer);
|
||||
this.index++;
|
||||
this.currBufIndex++;
|
||||
}
|
||||
int len = buffer.remaining();
|
||||
int size = 0;
|
||||
@@ -92,19 +72,26 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final byte ch) {
|
||||
expand(1);
|
||||
this.buffers[currBufIndex].put(ch);
|
||||
count++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final byte[] chs, final int start, final int len) {
|
||||
if (expand(len) == 0) {
|
||||
this.buffers[index].put(chs, start, len);
|
||||
this.buffers[currBufIndex].put(chs, start, len);
|
||||
} else {
|
||||
ByteBuffer buffer = this.buffers[index];
|
||||
ByteBuffer buffer = this.buffers[currBufIndex];
|
||||
final int end = start + len;
|
||||
int remain = len; // 还剩多少没有写
|
||||
while (remain > 0) {
|
||||
final int br = buffer.remaining();
|
||||
if (remain > br) { // 一个buffer写不完
|
||||
buffer.put(chs, end - remain, br);
|
||||
buffer = nextByteBuffer();
|
||||
buffer.put(chs, end - remain, br).flip();
|
||||
buffer = this.buffers[++this.currBufIndex];
|
||||
remain -= br;
|
||||
} else {
|
||||
buffer.put(chs, end - remain, remain);
|
||||
@@ -115,30 +102,63 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
||||
this.count += len;
|
||||
}
|
||||
|
||||
private ByteBuffer nextByteBuffer() {
|
||||
this.buffers[this.index].flip();
|
||||
return this.buffers[++this.index];
|
||||
@Override
|
||||
protected final void writeUInt32(int value) {
|
||||
if (value >= 0 && value < TENTHOUSAND_MAX) {
|
||||
writeTo(TENTHOUSAND_UINT_BYTES[value]);
|
||||
return;
|
||||
} else if (value < 0 && value > TENTHOUSAND_MAX) {
|
||||
writeTo(TENTHOUSAND_UINT_BYTES2[-value]);
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
if ((value & ~0x7F) == 0) {
|
||||
writeTo((byte) value);
|
||||
return;
|
||||
} else {
|
||||
writeTo((byte) ((value & 0x7F) | 0x80));
|
||||
value >>>= 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final byte ch) {
|
||||
expand(1);
|
||||
this.buffers[index].put(ch);
|
||||
count++;
|
||||
protected final void writeUInt64(long value) {
|
||||
if (value >= 0 && value < TENTHOUSAND_MAX) {
|
||||
writeTo(TENTHOUSAND_UINT_BYTES[(int) value]);
|
||||
return;
|
||||
} else if (value < 0 && value > TENTHOUSAND_MAX) {
|
||||
writeTo(TENTHOUSAND_UINT_BYTES2[(int) -value]);
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
if ((value & ~0x7FL) == 0) {
|
||||
writeTo((byte) value);
|
||||
return;
|
||||
} else {
|
||||
writeTo((byte) ((value & 0x7F) | 0x80));
|
||||
value >>>= 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] content() {
|
||||
public String toString() {
|
||||
return Objects.toString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ProtobufWriter clear() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public int offset() {
|
||||
public final byte[] toArray() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
public final byte[] content() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.redkale.util.*;
|
||||
*/
|
||||
public abstract class ProtobufCoders {
|
||||
|
||||
private static final Creator<List> LIST_CREATOR = Creator.load(List.class);
|
||||
static final Creator<List> LIST_CREATOR = Creator.load(List.class);
|
||||
|
||||
private ProtobufCoders() {
|
||||
// do nothing
|
||||
|
||||
@@ -39,8 +39,7 @@ public class ProtobufCollectionEncoder<T> extends CollectionEncoder<ProtobufWrit
|
||||
} else {
|
||||
ProtobufWriter tmp = out.pollChild();
|
||||
itemEncoder.convertTo(tmp, item);
|
||||
out.writeLength(tmp.count());
|
||||
out.writeTo(tmp.toArray());
|
||||
out.writeTuple(tmp);
|
||||
out.offerChild(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,8 +105,7 @@ public class ProtobufConvert extends BinaryConvert<ProtobufReader, ProtobufWrite
|
||||
// ------------------------------ writer -----------------------------------------------------------
|
||||
@Override
|
||||
protected <S extends ProtobufWriter> S configWrite(S writer) {
|
||||
writer.initOffset = writer.count;
|
||||
return writer;
|
||||
return (S) writer.configWrite();
|
||||
}
|
||||
|
||||
public ProtobufByteBufferWriter pollProtobufWriter(final Supplier<ByteBuffer> supplier) {
|
||||
@@ -826,7 +825,7 @@ public class ProtobufConvert extends BinaryConvert<ProtobufReader, ProtobufWrite
|
||||
writer.writeNull();
|
||||
return;
|
||||
}
|
||||
writer.initOffset = writer.count;
|
||||
writer.configWrite();
|
||||
final Type t = type == null ? value.getClass() : type;
|
||||
Encodeable encoder = this.lastEncodeable;
|
||||
if (encoder == null || encoder.getType() != t) {
|
||||
|
||||
@@ -227,6 +227,32 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
||||
|
||||
@Override
|
||||
protected <E> Encodeable<ProtobufWriter, E> createCollectionEncoder(Type type) {
|
||||
if (type instanceof ParameterizedType) {
|
||||
ParameterizedType pt = (ParameterizedType) type;
|
||||
Type componentType = pt.getActualTypeArguments()[0];
|
||||
Creator<? extends Collection> creator = ProtobufCoders.LIST_CREATOR;
|
||||
if (componentType == Boolean.class) {
|
||||
return (Encodeable) new ProtobufBoolCollectionSimpledCoder(creator);
|
||||
} else if (componentType == Byte.class) {
|
||||
return (Encodeable) new ProtobufByteCollectionSimpledCoder(creator);
|
||||
} else if (componentType == Character.class) {
|
||||
return (Encodeable) new ProtobufCharCollectionSimpledCoder(creator);
|
||||
} else if (componentType == Short.class) {
|
||||
return (Encodeable) new ProtobufShortCollectionSimpledCoder(creator);
|
||||
} else if (componentType == Integer.class) {
|
||||
return (Encodeable) new ProtobufIntCollectionSimpledCoder(creator);
|
||||
} else if (componentType == Float.class) {
|
||||
return (Encodeable) new ProtobufFloatCollectionSimpledCoder(creator);
|
||||
} else if (componentType == Long.class) {
|
||||
return (Encodeable) new ProtobufLongCollectionSimpledCoder(creator);
|
||||
} else if (componentType == Double.class) {
|
||||
return (Encodeable) new ProtobufDoubleCollectionSimpledCoder(creator);
|
||||
} else if (componentType == AtomicInteger.class) {
|
||||
return (Encodeable) new ProtobufAtomicIntegerCollectionSimpledCoder(creator);
|
||||
} else if (componentType == AtomicLong.class) {
|
||||
return (Encodeable) new ProtobufAtomicLongCollectionSimpledCoder(creator);
|
||||
}
|
||||
}
|
||||
return new ProtobufCollectionEncoder(this, type);
|
||||
}
|
||||
|
||||
@@ -262,6 +288,31 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
||||
|
||||
@Override
|
||||
protected <E> Encodeable<ProtobufWriter, E> createStreamEncoder(Type type) {
|
||||
if (type instanceof ParameterizedType) {
|
||||
ParameterizedType pt = (ParameterizedType) type;
|
||||
Type componentType = pt.getActualTypeArguments()[0];
|
||||
if (componentType == Boolean.class) {
|
||||
return (Encodeable) ProtobufBoolStreamSimpledCoder.instance;
|
||||
} else if (componentType == Byte.class) {
|
||||
return (Encodeable) ProtobufByteStreamSimpledCoder.instance;
|
||||
} else if (componentType == Character.class) {
|
||||
return (Encodeable) ProtobufCharStreamSimpledCoder.instance;
|
||||
} else if (componentType == Short.class) {
|
||||
return (Encodeable) ProtobufShortStreamSimpledCoder.instance;
|
||||
} else if (componentType == Integer.class) {
|
||||
return (Encodeable) ProtobufIntStreamSimpledCoder.instance;
|
||||
} else if (componentType == Float.class) {
|
||||
return (Encodeable) ProtobufFloatStreamSimpledCoder.instance;
|
||||
} else if (componentType == Long.class) {
|
||||
return (Encodeable) ProtobufLongStreamSimpledCoder.instance;
|
||||
} else if (componentType == Double.class) {
|
||||
return (Encodeable) ProtobufDoubleStreamSimpledCoder.instance;
|
||||
} else if (componentType == AtomicInteger.class) {
|
||||
return (Encodeable) ProtobufAtomicIntegerStreamSimpledCoder.instance;
|
||||
} else if (componentType == AtomicLong.class) {
|
||||
return (Encodeable) ProtobufAtomicLongStreamSimpledCoder.instance;
|
||||
}
|
||||
}
|
||||
return new ProtobufStreamEncoder(this, type);
|
||||
}
|
||||
|
||||
@@ -366,7 +417,7 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
||||
|| componentType == AtomicLong.class
|
||||
|| componentType == String.class;
|
||||
}
|
||||
|
||||
|
||||
// see io.protostuff.ProtobufOutput
|
||||
protected static int computeRawVarint32Size(final int value) {
|
||||
if (value == 0) return 1;
|
||||
@@ -390,7 +441,7 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
||||
if ((value & (0xffffffffffffffffL << 63)) == 0) return 9;
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
// see com.google.protobuf.CodedOutputStream
|
||||
protected static int computeInt32SizeNoTag(final int value) {
|
||||
if (value == 0) {
|
||||
|
||||
@@ -52,9 +52,8 @@ public class ProtobufMapEncoder<K, V> extends MapEncoder<ProtobufWriter, K, V> {
|
||||
kencoder.convertTo(tmp, key);
|
||||
tmp.writeTag(valTag);
|
||||
vencoder.convertTo(tmp, v);
|
||||
|
||||
out.writeLength(tmp.count());
|
||||
out.writeTo(tmp.toArray());
|
||||
|
||||
out.writeTuple(tmp);
|
||||
out.offerChild(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ProtobufObjectEncoder<T> extends ObjectEncoder<ProtobufWriter, T> {
|
||||
|
||||
@Override
|
||||
protected ProtobufWriter objectWriter(ProtobufWriter out, T value) {
|
||||
if (out.count() > out.initOffset) {
|
||||
if (out.length() > out.initOffset) {
|
||||
return out.pollChild().configParentFunc(out);
|
||||
}
|
||||
return out;
|
||||
|
||||
@@ -284,7 +284,6 @@ public class ProtobufReader extends Reader {
|
||||
|
||||
public final int[] readInts() {
|
||||
int len = readRawVarint32();
|
||||
System.out.println("等到长度: " + len);
|
||||
List<Integer> list = new ArrayList<>(len);
|
||||
while (len > 0) {
|
||||
int val = readInt();
|
||||
|
||||
@@ -40,8 +40,7 @@ public class ProtobufStreamEncoder<T> extends StreamEncoder<ProtobufWriter, T> {
|
||||
} else {
|
||||
ProtobufWriter tmp = out.pollChild();
|
||||
itemEncoder.convertTo(tmp, item);
|
||||
out.writeLength(tmp.count());
|
||||
out.writeTo(tmp.toArray());
|
||||
out.writeTuple(tmp);
|
||||
out.offerChild(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class ProtobufStreamReader extends ProtobufByteBufferReader {
|
||||
if (backByte != null) {
|
||||
byte b = backByte;
|
||||
backByte = null;
|
||||
this.position++;
|
||||
return b;
|
||||
}
|
||||
try {
|
||||
@@ -67,6 +68,7 @@ class ProtobufStreamReader extends ProtobufByteBufferReader {
|
||||
try {
|
||||
int v;
|
||||
while ((v = in.read()) != -1) {
|
||||
this.position++;
|
||||
array.putByte(v);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -77,6 +79,12 @@ class ProtobufStreamReader extends ProtobufByteBufferReader {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (backByte != null) {
|
||||
return true;
|
||||
}
|
||||
if (this.limit > 0 && (this.position + 1) >= this.limit) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
int v = in.read();
|
||||
if (v == -1) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.redkale.convert.pb;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.redkale.convert.ConvertException;
|
||||
|
||||
/**
|
||||
@@ -36,6 +37,7 @@ class ProtobufStreamWriter extends ProtobufByteBufferWriter {
|
||||
} catch (IOException e) {
|
||||
throw new ConvertException(e);
|
||||
}
|
||||
this.count += len;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,5 +47,11 @@ class ProtobufStreamWriter extends ProtobufByteBufferWriter {
|
||||
} catch (IOException e) {
|
||||
throw new ConvertException(e);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer[] toBuffers() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,7 +47,7 @@ public class GenericEntityTest {
|
||||
System.out.println("-------------------- runJson1 ---------------------------------");
|
||||
JsonConvert convert = JsonConvert.root();
|
||||
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
||||
String json = convert.convertTo(bean);
|
||||
String json = convert.convertTo(ENTITY_TYPE, bean);
|
||||
System.out.println(json);
|
||||
System.out.println(convert.convertFrom(ENTITY_TYPE, json).toString());
|
||||
Assertions.assertEquals(JSON, json);
|
||||
@@ -55,7 +55,6 @@ public class GenericEntityTest {
|
||||
|
||||
@Test
|
||||
public void runJson2() throws Exception {
|
||||
System.out.println("-------------------- runJson2 ---------------------------------");
|
||||
JsonConvert convert = JsonConvert.root();
|
||||
ByteBuffer in = ConvertHelper.createByteBuffer(createBytes());
|
||||
GenericEntity<Long, String, SimpleEntity> bean = convert.convertFrom(ENTITY_TYPE, in);
|
||||
@@ -67,7 +66,6 @@ public class GenericEntityTest {
|
||||
|
||||
@Test
|
||||
public void runJson3() throws Exception {
|
||||
System.out.println("-------------------- runJson3 ---------------------------------");
|
||||
JsonConvert convert = JsonConvert.root();
|
||||
InputStream in = ConvertHelper.createInputStream(createBytes());
|
||||
GenericEntity<Long, String, SimpleEntity> bean = convert.convertFrom(ENTITY_TYPE, in);
|
||||
@@ -82,10 +80,9 @@ public class GenericEntityTest {
|
||||
System.out.println("-------------------- runPb1 ---------------------------------");
|
||||
ProtobufConvert convert = ProtobufConvert.root();
|
||||
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
||||
byte[] bs = convert.convertTo(bean);
|
||||
Utility.println("proto", bs);
|
||||
byte[] bs = convert.convertTo(ENTITY_TYPE, bean);
|
||||
Utility.println("proto0 ", bs);
|
||||
String rs = convert.convertFrom(ENTITY_TYPE, bs).toString();
|
||||
System.out.println();
|
||||
Assertions.assertEquals(JSON, rs);
|
||||
}
|
||||
|
||||
@@ -94,13 +91,16 @@ public class GenericEntityTest {
|
||||
System.out.println("-------------------- runPb2 ---------------------------------");
|
||||
ProtobufConvert convert = ProtobufConvert.root();
|
||||
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
||||
byte[] bs = convert.convertTo(bean);
|
||||
byte[] bs = convert.convertTo(ENTITY_TYPE, bean);
|
||||
ByteBuffer in = ConvertHelper.createByteBuffer(bs);
|
||||
GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
||||
Assertions.assertEquals(JSON, rs.toString());
|
||||
Supplier<ByteBuffer> out = ConvertHelper.createSupplier();
|
||||
ByteBuffer[] buffers = convert.convertTo(out, ENTITY_TYPE, rs);
|
||||
Assertions.assertArrayEquals(bs, ConvertHelper.toBytes(buffers));
|
||||
byte[] bs2 = ConvertHelper.toBytes(buffers);
|
||||
Utility.println("proto1 ", bs);
|
||||
Utility.println("proto2 ", bs2);
|
||||
Assertions.assertArrayEquals(bs, bs2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,13 +108,16 @@ public class GenericEntityTest {
|
||||
System.out.println("-------------------- runPb3 ---------------------------------");
|
||||
ProtobufConvert convert = ProtobufConvert.root();
|
||||
GenericEntity<Long, String, SimpleEntity> bean = createBean();
|
||||
byte[] bs = convert.convertTo(bean);
|
||||
byte[] bs = convert.convertTo(ENTITY_TYPE, bean);
|
||||
Utility.println("proto1 ", bs);
|
||||
InputStream in = ConvertHelper.createInputStream(bs);
|
||||
// GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
||||
// Assertions.assertEquals(JSON, rs.toString());
|
||||
// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// convert.convertTo(out, ENTITY_TYPE, rs);
|
||||
// Assertions.assertArrayEquals(bs, out.toByteArray());
|
||||
GenericEntity<Long, String, SimpleEntity> rs = convert.convertFrom(ENTITY_TYPE, in);
|
||||
Assertions.assertEquals(JSON, rs.toString());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
convert.convertTo(out, ENTITY_TYPE, rs);
|
||||
byte[] bs2 = out.toByteArray();
|
||||
Utility.println("proto2 ", bs2);
|
||||
Assertions.assertArrayEquals(bs, bs2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,26 +176,26 @@ public class GenericEntityTest {
|
||||
|
||||
public static class GenericEntity<T, K, V> {
|
||||
|
||||
@ConvertColumn(index = 3)
|
||||
private K oneName;
|
||||
@ConvertColumn(index = 1)
|
||||
private Entry<K, V> oneEntry;
|
||||
|
||||
@ConvertColumn(index = 2)
|
||||
private List<? extends T> oneList;
|
||||
|
||||
@ConvertColumn(index = 1)
|
||||
private Entry<K, V> oneEntry;
|
||||
@ConvertColumn(index = 3)
|
||||
private K oneName;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
public K getOneName() {
|
||||
return oneName;
|
||||
public Entry<K, V> getOneEntry() {
|
||||
return oneEntry;
|
||||
}
|
||||
|
||||
public void setOneName(K oneName) {
|
||||
this.oneName = oneName;
|
||||
public void setOneEntry(Entry<K, V> oneEntry) {
|
||||
this.oneEntry = oneEntry;
|
||||
}
|
||||
|
||||
public List<? extends T> getOneList() {
|
||||
@@ -203,12 +206,12 @@ public class GenericEntityTest {
|
||||
this.oneList = oneList;
|
||||
}
|
||||
|
||||
public Entry<K, V> getOneEntry() {
|
||||
return oneEntry;
|
||||
public K getOneName() {
|
||||
return oneName;
|
||||
}
|
||||
|
||||
public void setOneEntry(Entry<K, V> oneEntry) {
|
||||
this.oneEntry = oneEntry;
|
||||
public void setOneName(K oneName) {
|
||||
this.oneName = oneName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user