protobuf
This commit is contained in:
@@ -67,7 +67,6 @@ public class BsonByteBufferReader extends BsonReader {
|
|||||||
/**
|
/**
|
||||||
* 判断下一个非空白字节是否为[
|
* 判断下一个非空白字节是否为[
|
||||||
*
|
*
|
||||||
* @param member DeMember
|
|
||||||
* @param typevals byte[]
|
* @param typevals byte[]
|
||||||
* @param componentDecoder Decodeable
|
* @param componentDecoder Decodeable
|
||||||
* @return 数组长度或 SIGN_NULL
|
* @return 数组长度或 SIGN_NULL
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class BsonByteBufferWriter extends BsonWriter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final byte[] toArray() {
|
public final byte[] toArray() {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
return toByteArray().getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class JsonByteBufferReader extends JsonReader {
|
|||||||
private ByteBuffer[] buffers;
|
private ByteBuffer[] buffers;
|
||||||
|
|
||||||
private ByteBuffer currentBuffer;
|
private ByteBuffer currentBuffer;
|
||||||
|
|
||||||
private int currBufIndex = 0;
|
private int currBufIndex = 0;
|
||||||
|
|
||||||
protected JsonByteBufferReader(ByteBuffer... buffers) {
|
protected JsonByteBufferReader(ByteBuffer... buffers) {
|
||||||
|
|||||||
@@ -65,6 +65,17 @@ public class JsonByteBufferWriter extends JsonWriter {
|
|||||||
return this.buffers;
|
return this.buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ByteArray toByteArray() {
|
||||||
|
ByteArray array = new ByteArray();
|
||||||
|
if (buffers != null) {
|
||||||
|
for (ByteBuffer buf : toBuffers()) {
|
||||||
|
array.put(buf);
|
||||||
|
buf.flip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
public int count() {
|
public int count() {
|
||||||
if (this.buffers == null) {
|
if (this.buffers == null) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package org.redkale.convert.pb;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import org.redkale.util.ByteArray;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
/** @author zhangjx */
|
/** @author zhangjx */
|
||||||
@@ -48,6 +49,17 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
|||||||
return this.buffers;
|
return this.buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ByteArray toByteArray() {
|
||||||
|
ByteArray array = new ByteArray();
|
||||||
|
if (buffers != null) {
|
||||||
|
for (ByteBuffer buf : toBuffers()) {
|
||||||
|
array.put(buf);
|
||||||
|
buf.flip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int expand(final int byteLength) {
|
protected int expand(final int byteLength) {
|
||||||
if (this.buffers == null) {
|
if (this.buffers == null) {
|
||||||
@@ -154,7 +166,7 @@ public class ProtobufByteBufferWriter extends ProtobufWriter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final byte[] toArray() {
|
public final byte[] toArray() {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // 无需实现
|
return toByteArray().getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class ProtobufMapEncoder<K, V> extends MapEncoder<ProtobufWriter, K, V> {
|
|||||||
kencoder.convertTo(tmp, key);
|
kencoder.convertTo(tmp, key);
|
||||||
tmp.writeTag(valTag);
|
tmp.writeTag(valTag);
|
||||||
vencoder.convertTo(tmp, v);
|
vencoder.convertTo(tmp, v);
|
||||||
|
|
||||||
out.writeTuple(tmp);
|
out.writeTuple(tmp);
|
||||||
out.offerChild(tmp);
|
out.offerChild(tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ public class ProtobufReader extends Reader {
|
|||||||
/**
|
/**
|
||||||
* 判断下一个非空白字符是否为[
|
* 判断下一个非空白字符是否为[
|
||||||
*
|
*
|
||||||
* @param member DeMember
|
|
||||||
* @param componentDecoder Decodeable
|
* @param componentDecoder Decodeable
|
||||||
* @return SIGN_VARIABLE 或 SIGN_NULL
|
* @return SIGN_VARIABLE 或 SIGN_NULL
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.test.convert.bson;
|
package org.redkale.test.convert.bson;
|
||||||
|
|
||||||
import org.redkale.test.convert.SimpleEntity;
|
|
||||||
import org.redkale.test.convert.SimpleChildEntity;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -15,6 +13,8 @@ import org.redkale.annotation.ConstructorParameters;
|
|||||||
import org.redkale.convert.bson.*;
|
import org.redkale.convert.bson.*;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.persistence.*;
|
import org.redkale.persistence.*;
|
||||||
|
import org.redkale.test.convert.SimpleChildEntity;
|
||||||
|
import org.redkale.test.convert.SimpleEntity;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/** @author zhangjx */
|
/** @author zhangjx */
|
||||||
@@ -88,7 +88,7 @@ public class BsonMainTest {
|
|||||||
final int len = bytes2.length;
|
final int len = bytes2.length;
|
||||||
BsonByteBufferWriter writer = convert.pollWriter(() -> ByteBuffer.allocate(len / 2));
|
BsonByteBufferWriter writer = convert.pollWriter(() -> ByteBuffer.allocate(len / 2));
|
||||||
convert.convertTo(writer, bean);
|
convert.convertTo(writer, bean);
|
||||||
bytes2 = writer.toArray();
|
bytes2 = writer.toByteArray().getBytes();
|
||||||
System.out.println(convert.convertFrom(ComplextEntity.class, bytes2).toString());
|
System.out.println(convert.convertFrom(ComplextEntity.class, bytes2).toString());
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
"{\"chname\":\"\",\"flag\":true,\"userid\":0}",
|
"{\"chname\":\"\",\"flag\":true,\"userid\":0}",
|
||||||
|
|||||||
Reference in New Issue
Block a user