This commit is contained in:
@@ -35,12 +35,8 @@ public class BsonByteBufferWriter extends BsonWriter {
|
|||||||
this.supplier = supplier;
|
this.supplier = supplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer[] toBuffers() {
|
|
||||||
return toBuffers(supplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] toBuffers(Supplier<ByteBuffer> supplier) {
|
public ByteBuffer[] toBuffers() {
|
||||||
if (buffers == null) return new ByteBuffer[0];
|
if (buffers == null) return new ByteBuffer[0];
|
||||||
for (int i = index; i < this.buffers.length; i++) {
|
for (int i = index; i < this.buffers.length; i++) {
|
||||||
ByteBuffer buf = this.buffers[i];
|
ByteBuffer buf = this.buffers[i];
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
package org.redkale.convert.bson;
|
package org.redkale.convert.bson;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
@@ -38,9 +37,8 @@ public class BsonWriter extends Writer {
|
|||||||
return newdata;
|
return newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer[] toBuffers(final Supplier<ByteBuffer> supplier) {
|
public ByteBuffer[] toBuffers() {
|
||||||
if (supplier == null) return new ByteBuffer[]{ByteBuffer.wrap(content, 0, count)};
|
return new ByteBuffer[]{ByteBuffer.wrap(content, 0, count)};
|
||||||
return ByteBufferWriter.create(supplier).put(content, 0, count).toBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BsonWriter(byte[] bs) {
|
protected BsonWriter(byte[] bs) {
|
||||||
|
|||||||
@@ -55,12 +55,8 @@ public class JsonByteBufferWriter extends JsonWriter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer[] toBuffers() {
|
|
||||||
return toBuffers(supplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] toBuffers(Supplier<ByteBuffer> supplier) {
|
public ByteBuffer[] toBuffers() {
|
||||||
if (buffers == null) return new ByteBuffer[0];
|
if (buffers == null) return new ByteBuffer[0];
|
||||||
for (int i = index; i < this.buffers.length; i++) {
|
for (int i = index; i < this.buffers.length; i++) {
|
||||||
ByteBuffer buf = this.buffers[i];
|
ByteBuffer buf = this.buffers[i];
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
package org.redkale.convert.json;
|
package org.redkale.convert.json;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
@@ -107,9 +106,8 @@ public class JsonWriter extends Writer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer[] toBuffers(Supplier<ByteBuffer> supplier) {
|
public ByteBuffer[] toBuffers() {
|
||||||
if (supplier == null) return new ByteBuffer[]{ByteBuffer.wrap(Utility.encodeUTF8(content, 0, count))};
|
return new ByteBuffer[]{ByteBuffer.wrap(Utility.encodeUTF8(content, 0, count))};
|
||||||
return ByteBufferWriter.create(supplier).put(Utility.encodeUTF8(content, 0, count)).toBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] toBytes() {
|
public byte[] toBytes() {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.channels.CompletionHandler;
|
import java.nio.channels.CompletionHandler;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.redkale.util.ByteBufferWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议响应对象
|
* 协议响应对象
|
||||||
@@ -275,7 +274,7 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
|||||||
buffer.flip();
|
buffer.flip();
|
||||||
this.finish(buffer);
|
this.finish(buffer);
|
||||||
} else {
|
} else {
|
||||||
this.finish(ByteBufferWriter.toBuffers(this.context.getBufferSupplier(), bs));
|
this.finish(ByteBuffer.wrap(bs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -636,7 +636,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
super.finish(false, headbuf);
|
super.finish(false, headbuf);
|
||||||
} else {
|
} else {
|
||||||
headbuf.flip();
|
headbuf.flip();
|
||||||
super.finish(false, Utility.append(new ByteBuffer[]{headbuf}, ByteBufferWriter.toBuffers(context.getBufferSupplier(), content)));
|
super.finish(false, new ByteBuffer[]{headbuf, ByteBuffer.wrap(content)});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.context.getBufferCapacity() >= content.length) {
|
if (this.context.getBufferCapacity() >= content.length) {
|
||||||
@@ -645,7 +645,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
buffer.flip();
|
buffer.flip();
|
||||||
this.finish(false, buffer);
|
this.finish(false, buffer);
|
||||||
} else {
|
} else {
|
||||||
this.finish(false, ByteBufferWriter.toBuffers(context.getBufferSupplier(), content));
|
this.finish(false, ByteBuffer.wrap(content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ public final class SncpClient {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
final AsyncConnection conn = conn0;
|
final AsyncConnection conn = conn0;
|
||||||
final ByteBuffer[] sendBuffers = writer.toBuffers(transport.getBufferSupplier());
|
final ByteBuffer[] sendBuffers = writer.toBuffers();
|
||||||
fillHeader(sendBuffers[0], seqid, actionid, reqBodyLength);
|
fillHeader(sendBuffers[0], seqid, actionid, reqBodyLength);
|
||||||
|
|
||||||
final ByteBuffer buffer = transport.pollBuffer();
|
final ByteBuffer buffer = transport.pollBuffer();
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public final class SncpResponse extends Response<SncpContext, SncpRequest> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int respBodyLength = out.count(); //body总长度
|
final int respBodyLength = out.count(); //body总长度
|
||||||
final ByteBuffer[] buffers = out.toBuffers(context.getBufferSupplier());
|
final ByteBuffer[] buffers = out.toBuffers();
|
||||||
fillHeader(buffers[0], respBodyLength - HEADER_SIZE, retcode);
|
fillHeader(buffers[0], respBodyLength - HEADER_SIZE, retcode);
|
||||||
finish(buffers);
|
finish(buffers);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user