diff options
| author | ruki <[email protected]> | 2022-05-08 23:04:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-08 23:04:26 +0800 |
| commit | bd81aa4cd750f668f325ca1269236981f5cdd4c5 (patch) | |
| tree | d03368562503197e172b4605be4c75636d2676b4 | |
| parent | 56c6720361323fcbed71c76542cd42a995800218 (diff) | |
compress stream data
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/service/stream.lua | 13 |
2 files changed, 11 insertions, 6 deletions
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index f5672d2a4..2874ac154 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -215,7 +215,7 @@ function remote_build_client:sync() -- do sync cprint("Uploading files with ${bright}%d${clear} bytes ..", os.filesize(archive_diff_file)) local send_ok = false - if stream:send_msg(message.new_sync(session_id, diff_files, {token = self:token()})) and stream:flush() then + if stream:send_msg(message.new_sync(session_id, diff_files, {token = self:token()}), {compress = true}) and stream:flush() then if stream:send_file(archive_diff_file) and stream:flush() then send_ok = true end @@ -396,7 +396,7 @@ function remote_build_client:_diff_files(stream) local count = 0 local result, errors cprint("Comparing ${bright}%d${clear} files ..", filecount) - if stream:send_msg(message.new_diff(session_id, manifest, {token = self:token()})) and stream:flush() then + if stream:send_msg(message.new_diff(session_id, manifest, {token = self:token()}), {compress = true}) and stream:flush() then local msg = stream:recv_msg() if msg and msg:success() then result = msg:body().manifest diff --git a/xmake/modules/private/service/stream.lua b/xmake/modules/private/service/stream.lua index 37436bc25..e6f7a5e99 100644 --- a/xmake/modules/private/service/stream.lua +++ b/xmake/modules/private/service/stream.lua @@ -23,6 +23,7 @@ import("core.base.bit") import("core.base.object") import("core.base.socket") import("core.base.bytes") +import("core.compress.lz4") import("private.service.message") -- define module @@ -103,18 +104,18 @@ function stream:send(data, start, last) end -- send message -function stream:send_msg(msg) - return self:send_object(msg:body()) +function stream:send_msg(msg, opt) + return self:send_object(msg:body(), opt) end -- send object -function stream:send_object(obj) +function stream:send_object(obj, opt) local str, errors = string.serialize(obj, {strip = true, indent = false}) if errors then raise(errors) end if str then - return self:send_string(str) + return self:send_string(str, opt) end end @@ -132,6 +133,7 @@ function stream:send_data(data, opt) local flags = 0 if opt.compress then flags = bit.bor(flags, HEADER_FLAG_COMPRESS_LZ4) + data = lz4.compress(data) end local size = data:size() assert(size < STREAM_DATA_MAXN, "too large data size(%d)", size) @@ -297,6 +299,9 @@ function stream:recv_data() end end if recv == size then + if bit.band(flags, HEADER_FLAG_COMPRESS_LZ4) == HEADER_FLAG_COMPRESS_LZ4 then + buff = lz4.decompress(buff) + end return buff end end |
