mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-05-20 16:15:47 +08:00
@@ -45,10 +45,16 @@ class ByteBuf {
|
||||
void clear() {
|
||||
readerIndex = 0;
|
||||
writerIndex = 0;
|
||||
_buffer = Uint8List(0);
|
||||
}
|
||||
|
||||
///释放已读的空间
|
||||
void clearRead() {
|
||||
if (readerIndex == writerIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (readerIndex > 0) {
|
||||
_buffer = Uint8List.sublistView(_buffer, readerIndex, writerIndex);
|
||||
writerIndex -= readerIndex;
|
||||
|
||||
53
lib/network/util/byte_utils.dart
Normal file
53
lib/network/util/byte_utils.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
List<int> viewOrSublist(List<int> data, int offset, int length) {
|
||||
if (data is Uint8List) {
|
||||
return Uint8List.view(data.buffer, data.offsetInBytes + offset, length);
|
||||
} else {
|
||||
return data.sublist(offset, offset + length);
|
||||
}
|
||||
}
|
||||
|
||||
int readInt64(List<int> bytes, int offset) {
|
||||
var high = readInt32(bytes, offset);
|
||||
var low = readInt32(bytes, offset + 4);
|
||||
return high << 32 | low;
|
||||
}
|
||||
|
||||
int readInt32(List<int> bytes, int offset) {
|
||||
return (bytes[offset] << 24) |
|
||||
(bytes[offset + 1] << 16) |
|
||||
(bytes[offset + 2] << 8) |
|
||||
bytes[offset + 3];
|
||||
}
|
||||
|
||||
int readInt24(List<int> bytes, int offset) {
|
||||
return (bytes[offset] << 16) | (bytes[offset + 1] << 8) | bytes[offset + 2];
|
||||
}
|
||||
|
||||
int readInt16(List<int> bytes, int offset) {
|
||||
return (bytes[offset] << 8) | bytes[offset + 1];
|
||||
}
|
||||
|
||||
void setInt64(List<int> bytes, int offset, int value) {
|
||||
setInt32(bytes, offset, value >> 32);
|
||||
setInt32(bytes, offset + 4, value & 0xffffffff);
|
||||
}
|
||||
|
||||
void setInt32(List<int> bytes, int offset, int value) {
|
||||
bytes[offset] = (value >> 24) & 0xff;
|
||||
bytes[offset + 1] = (value >> 16) & 0xff;
|
||||
bytes[offset + 2] = (value >> 8) & 0xff;
|
||||
bytes[offset + 3] = value & 0xff;
|
||||
}
|
||||
|
||||
void setInt24(List<int> bytes, int offset, int value) {
|
||||
bytes[offset] = (value >> 16) & 0xff;
|
||||
bytes[offset + 1] = (value >> 8) & 0xff;
|
||||
bytes[offset + 2] = value & 0xff;
|
||||
}
|
||||
|
||||
void setInt16(List<int> bytes, int offset, int value) {
|
||||
bytes[offset] = (value >> 8) & 0xff;
|
||||
bytes[offset + 1] = value & 0xff;
|
||||
}
|
||||
@@ -113,10 +113,13 @@ class ProxyHelper {
|
||||
request.uri = hostAndPort.domain;
|
||||
}
|
||||
|
||||
request.response = HttpResponse(status)
|
||||
..headers.contentType = 'text/plain'
|
||||
..headers.contentLength = message.codeUnits.length
|
||||
..body = message.codeUnits;
|
||||
if (request.response == null || request.method == HttpMethod.connect) {
|
||||
request.response = HttpResponse(status)
|
||||
..headers.contentType = 'text/plain'
|
||||
..headers.contentLength = message.codeUnits.length
|
||||
..body = message.codeUnits;
|
||||
}
|
||||
|
||||
request.response?.request = request;
|
||||
|
||||
channelContext.host = hostAndPort;
|
||||
|
||||
Reference in New Issue
Block a user