移除ConvertMask功能
This commit is contained in:
@@ -46,7 +46,7 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
||||
return writer;
|
||||
}
|
||||
|
||||
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc,
|
||||
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc,
|
||||
BiFunction<Object, Object, Object> mapFieldFunc, Function<Object, ConvertField[]> objExtFunc) {
|
||||
writer.mapFieldFunc = mapFieldFunc;
|
||||
writer.objFieldFunc = objFieldFunc;
|
||||
@@ -66,7 +66,7 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
||||
return newConvert(objFieldFunc, null, objExtFunc);
|
||||
}
|
||||
|
||||
public abstract Convert<R, W> newConvert(BiFunction<Attribute, Object, Object> objFieldFunc,
|
||||
public abstract Convert<R, W> newConvert(BiFunction<Attribute, Object, Object> objFieldFunc,
|
||||
BiFunction<Object, Object, Object> mapFieldFunc, Function<Object, ConvertField[]> objExtFunc);
|
||||
|
||||
public abstract boolean isBinary();
|
||||
@@ -89,8 +89,6 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
||||
|
||||
public abstract <T> T convertFrom(final Type type, final ByteBuffer... buffers);
|
||||
|
||||
public abstract <T> T convertFrom(final Type type, final ConvertMask mask, final ByteBuffer... buffers);
|
||||
|
||||
public final void convertTo(final W writer, final Object value) {
|
||||
convertTo(writer, (Type) null, value);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.convert;
|
||||
|
||||
/**
|
||||
* Mask接口
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public interface ConvertMask {
|
||||
|
||||
default byte mask(byte value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
default byte unmask(byte value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,7 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
|
||||
private ByteBuffer currentBuffer;
|
||||
|
||||
protected ConvertMask mask;
|
||||
|
||||
protected BsonByteBufferReader(ConvertMask mask, ByteBuffer... buffers) {
|
||||
this.mask = mask;
|
||||
protected BsonByteBufferReader(ByteBuffer... buffers) {
|
||||
this.buffers = buffers;
|
||||
if (buffers != null && buffers.length > 0) {
|
||||
this.currentBuffer = buffers[currentIndex];
|
||||
@@ -42,13 +39,12 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
this.currentIndex = 0;
|
||||
this.currentBuffer = null;
|
||||
this.buffers = null;
|
||||
this.mask = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte currentByte() {
|
||||
return mask == null ? currentBuffer.get(currentBuffer.position()) : mask.unmask(currentBuffer.get(currentBuffer.position()));
|
||||
return currentBuffer.get(currentBuffer.position());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,13 +98,13 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
public byte readByte() {
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get());
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
for (;;) {
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get());
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,11 +115,7 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
int remain = this.currentBuffer.remaining();
|
||||
if (remain >= 2) {
|
||||
this.position += 2;
|
||||
if (mask == null) {
|
||||
return this.currentBuffer.getChar();
|
||||
} else {
|
||||
return (char) ((0xff00 & (mask.unmask(this.currentBuffer.get()) << 8)) | (0xff & mask.unmask(this.currentBuffer.get())));
|
||||
}
|
||||
return this.currentBuffer.getChar();
|
||||
}
|
||||
}
|
||||
return (char) ((0xff00 & (readByte() << 8)) | (0xff & readByte()));
|
||||
@@ -135,11 +127,7 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
int remain = this.currentBuffer.remaining();
|
||||
if (remain >= 2) {
|
||||
this.position += 2;
|
||||
if (mask == null) {
|
||||
return this.currentBuffer.getShort();
|
||||
} else {
|
||||
return (short) ((0xff00 & (mask.unmask(this.currentBuffer.get()) << 8)) | (0xff & mask.unmask(this.currentBuffer.get())));
|
||||
}
|
||||
return this.currentBuffer.getShort();
|
||||
}
|
||||
}
|
||||
return (short) ((0xff00 & (readByte() << 8)) | (0xff & readByte()));
|
||||
@@ -151,14 +139,7 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
int remain = this.currentBuffer.remaining();
|
||||
if (remain >= 4) {
|
||||
this.position += 4;
|
||||
if (mask == null) {
|
||||
return this.currentBuffer.getInt();
|
||||
} else {
|
||||
return ((mask.unmask(this.currentBuffer.get()) & 0xff) << 24)
|
||||
| ((mask.unmask(this.currentBuffer.get()) & 0xff) << 16)
|
||||
| ((mask.unmask(this.currentBuffer.get()) & 0xff) << 8)
|
||||
| (mask.unmask(this.currentBuffer.get()) & 0xff);
|
||||
}
|
||||
return this.currentBuffer.getInt();
|
||||
}
|
||||
}
|
||||
return ((readByte() & 0xff) << 24) | ((readByte() & 0xff) << 16) | ((readByte() & 0xff) << 8) | (readByte() & 0xff);
|
||||
@@ -170,18 +151,7 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
int remain = this.currentBuffer.remaining();
|
||||
if (remain >= 8) {
|
||||
this.position += 8;
|
||||
if (mask == null) {
|
||||
return this.currentBuffer.getLong();
|
||||
} else {
|
||||
return ((((long) mask.unmask(this.currentBuffer.get()) & 0xff) << 56)
|
||||
| (((long) mask.unmask(this.currentBuffer.get()) & 0xff) << 48)
|
||||
| (((long) mask.unmask(this.currentBuffer.get()) & 0xff) << 40)
|
||||
| (((long) mask.unmask(this.currentBuffer.get()) & 0xff) << 32)
|
||||
| (((long) mask.unmask(this.currentBuffer.get()) & 0xff) << 24)
|
||||
| (((long) mask.unmask(this.currentBuffer.get()) & 0xff) << 16)
|
||||
| (((long) mask.unmask(this.currentBuffer.get()) & 0xff) << 8)
|
||||
| (((long) mask.unmask(this.currentBuffer.get()) & 0xff)));
|
||||
}
|
||||
return this.currentBuffer.getLong();
|
||||
}
|
||||
}
|
||||
return ((((long) readByte() & 0xff) << 56)
|
||||
@@ -211,19 +181,9 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
if (remain >= len) {
|
||||
this.position += len;
|
||||
this.currentBuffer.get(bs, pos, len);
|
||||
if (mask != null) {
|
||||
for (int i = pos, end = pos + len; i < end; i++) {
|
||||
bs[i] = mask.unmask(bs[i]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.currentBuffer.get(bs, pos, remain);
|
||||
if (mask != null) {
|
||||
for (int i = pos, end = pos + remain; i < end; i++) {
|
||||
bs[i] = mask.unmask(bs[i]);
|
||||
}
|
||||
}
|
||||
this.position += remain;
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
read(bs, pos + remain);
|
||||
|
||||
@@ -86,7 +86,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
||||
|
||||
//------------------------------ reader -----------------------------------------------------------
|
||||
public BsonReader pollReader(final ByteBuffer... buffers) {
|
||||
return new BsonByteBufferReader((ConvertMask) null, buffers);
|
||||
return new BsonByteBufferReader(buffers);
|
||||
}
|
||||
|
||||
public BsonReader pollReader(final InputStream in) {
|
||||
@@ -175,16 +175,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
|
||||
if (type == null || buffers.length < 1) {
|
||||
return null;
|
||||
}
|
||||
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader((ConvertMask) null, buffers));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T convertFrom(final Type type, final ConvertMask mask, final ByteBuffer... buffers) {
|
||||
if (type == null || buffers.length < 1) {
|
||||
return null;
|
||||
}
|
||||
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader(mask, buffers));
|
||||
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader(buffers));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,7 @@ class BsonStreamReader extends BsonByteBufferReader {
|
||||
private byte currByte;
|
||||
|
||||
protected BsonStreamReader(InputStream in) {
|
||||
super((ConvertMask) null);
|
||||
super();
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
|
||||
private ByteBuffer currentBuffer;
|
||||
|
||||
protected ConvertMask mask;
|
||||
|
||||
protected JsonByteBufferReader(ConvertMask mask, ByteBuffer... buffers) {
|
||||
this.mask = mask;
|
||||
protected JsonByteBufferReader(ByteBuffer... buffers) {
|
||||
this.buffers = buffers;
|
||||
if (buffers != null && buffers.length > 0) {
|
||||
this.currentBuffer = buffers[currentIndex];
|
||||
@@ -46,20 +43,19 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
this.buffers = null;
|
||||
this.currentIndex = 0;
|
||||
this.currentBuffer = null;
|
||||
this.mask = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected byte nextByte() {
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get());
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
for (;;) {
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get());
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,20 +207,7 @@ public class JsonConvert extends TextConvert<JsonReader, JsonWriter> {
|
||||
decoder = factory.loadDecoder(type);
|
||||
this.lastConvertDecodeable = decoder;
|
||||
}
|
||||
return (T) decoder.convertFrom(new JsonByteBufferReader((ConvertMask) null, buffers));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convertFrom(final Type type, final ConvertMask mask, final ByteBuffer... buffers) {
|
||||
if (type == null || buffers == null || buffers.length == 0) {
|
||||
return null;
|
||||
}
|
||||
Decodeable decoder = this.lastConvertDecodeable;
|
||||
if (decoder == null || decoder.getType() != type) {
|
||||
decoder = factory.loadDecoder(type);
|
||||
this.lastConvertDecodeable = decoder;
|
||||
}
|
||||
return (T) decoder.convertFrom(new JsonByteBufferReader(mask, buffers));
|
||||
return (T) decoder.convertFrom(new JsonByteBufferReader(buffers));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -279,15 +266,7 @@ public class JsonConvert extends TextConvert<JsonReader, JsonWriter> {
|
||||
if (buffers == null || buffers.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return (V) new AnyDecoder(factory).convertFrom(new JsonByteBufferReader((ConvertMask) null, buffers));
|
||||
}
|
||||
|
||||
//返回非null的值是由String、ArrayList、HashMap任意组合的对象
|
||||
public <V> V convertFrom(final ConvertMask mask, final ByteBuffer... buffers) {
|
||||
if (buffers == null || buffers.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return (V) new AnyDecoder(factory).convertFrom(new JsonByteBufferReader(mask, buffers));
|
||||
return (V) new AnyDecoder(factory).convertFrom(new JsonByteBufferReader(buffers));
|
||||
}
|
||||
|
||||
//返回非null的值是由String、ArrayList、HashMap任意组合的对象
|
||||
|
||||
@@ -19,7 +19,7 @@ class JsonStreamReader extends JsonByteBufferReader {
|
||||
private InputStream in;
|
||||
|
||||
protected JsonStreamReader(InputStream in) {
|
||||
super((ConvertMask) null);
|
||||
super();
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.redkale.convert.protobuf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.redkale.convert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -20,10 +19,7 @@ public class ProtobufByteBufferReader extends ProtobufReader {
|
||||
|
||||
private ByteBuffer currentBuffer;
|
||||
|
||||
protected ConvertMask mask;
|
||||
|
||||
protected ProtobufByteBufferReader(ConvertMask mask, ByteBuffer... buffers) {
|
||||
this.mask = mask;
|
||||
protected ProtobufByteBufferReader(ByteBuffer... buffers) {
|
||||
this.buffers = buffers;
|
||||
if (buffers != null && buffers.length > 0) this.currentBuffer = buffers[currentIndex];
|
||||
}
|
||||
@@ -34,25 +30,24 @@ public class ProtobufByteBufferReader extends ProtobufReader {
|
||||
this.currentIndex = 0;
|
||||
this.currentBuffer = null;
|
||||
this.buffers = null;
|
||||
this.mask = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte currentByte() {
|
||||
return mask == null ? currentBuffer.get(currentBuffer.position()) : mask.unmask(currentBuffer.get(currentBuffer.position()));
|
||||
return currentBuffer.get(currentBuffer.position());
|
||||
}
|
||||
|
||||
protected byte nextByte() {
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get());
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
for (;;) {
|
||||
this.currentBuffer = this.buffers[++this.currentIndex];
|
||||
if (this.currentBuffer.hasRemaining()) {
|
||||
this.position++;
|
||||
return mask == null ? this.currentBuffer.get() : mask.unmask(this.currentBuffer.get());
|
||||
return this.currentBuffer.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,27 +534,7 @@ public class ProtobufConvert extends BinaryConvert<ProtobufReader, ProtobufWrite
|
||||
if (!(decoder instanceof ObjectDecoder)) {
|
||||
throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")");
|
||||
}
|
||||
return (T) decoder.convertFrom(new ProtobufByteBufferReader((ConvertMask) null, buffers));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T convertFrom(final Type type, final ConvertMask mask, final ByteBuffer... buffers) {
|
||||
if (true) {
|
||||
throw new ConvertException(this.getClass().getSimpleName() + " not supported convertFrom ByteBuffer");
|
||||
}
|
||||
if (type == null || buffers.length < 1) {
|
||||
return null;
|
||||
}
|
||||
Decodeable decoder = this.lastConvertDecodeable;
|
||||
if (decoder == null || decoder.getType() != type) {
|
||||
decoder = factory.loadDecoder(type);
|
||||
this.lastConvertDecodeable = decoder;
|
||||
}
|
||||
if (!(decoder instanceof ObjectDecoder)) {
|
||||
throw new ConvertException(this.getClass().getSimpleName() + " not supported type(" + type + ")");
|
||||
}
|
||||
return (T) decoder.convertFrom(new ProtobufByteBufferReader(mask, buffers));
|
||||
return (T) decoder.convertFrom(new ProtobufByteBufferReader(buffers));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,7 @@ class ProtobufStreamReader extends ProtobufByteBufferReader {
|
||||
private byte currByte;
|
||||
|
||||
protected ProtobufStreamReader(InputStream in) {
|
||||
super((ConvertMask) null);
|
||||
super();
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user