API adjustment

- Change payload length indicator bytes length: 4b -> 8b
This commit is contained in:
Linloir 2022-10-18 15:07:42 +08:00
parent bdfeb07927
commit 522e0712e7
No known key found for this signature in database
GPG Key ID: 58EEB209A0F2C366
2 changed files with 6 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @Date : 2022-10-08 15:10:04
* @LastEditTime : 2022-10-17 22:53:17
* @LastEditTime : 2022-10-18 14:50:17
* @Description :
*/
@ -108,12 +108,12 @@ class TCPController {
while(true) {
if(requestLength == 0 && payloadLength == 0 && _payloadPullStreamController.isClosed) {
//New request
if(buffer.length >= 8) {
if(buffer.length >= 12) {
//Buffered data has more than 8 bytes, enough to read request length and body length
requestLength = Uint8List.fromList(buffer.sublist(0, 4)).buffer.asInt32List()[0];
payloadLength = Uint8List.fromList(buffer.sublist(4, 8)).buffer.asInt32List()[0];
payloadLength = Uint8List.fromList(buffer.sublist(4, 12)).buffer.asInt64List()[0];
//Clear the length indicator bytes
buffer.removeRange(0, 8);
buffer.removeRange(0, 12);
//Initialize payload transmission controller
_payloadPullStreamController = StreamController();
//Create a future that listens to the status of the payload transmission

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @Date : 2022-10-08 22:40:47
* @LastEditTime : 2022-10-12 13:53:06
* @LastEditTime : 2022-10-18 14:44:49
* @Description :
*/
@ -76,7 +76,7 @@ class TCPResponse {
int get payloadLength => payloadFile?.lengthSync() ?? 0;
Stream<List<int>> get stream async* {
yield Uint8List(4)..buffer.asInt32List()[0] = responseLength;
yield Uint8List(4)..buffer.asInt32List()[0] = payloadLength;
yield Uint8List(8)..buffer.asInt64List()[0] = payloadLength;
yield Uint8List.fromList(responseJson.codeUnits);
if(payloadFile != null) {
yield await payloadFile!.readAsBytes();