Coverage for /home/antoine/projects/xpra-git/dist/python3/lib64/python/xpra/net/header.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of Xpra.
2# Copyright (C) 2011-2019 Antoine Martin <antoine@xpra.org>
3# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
4# later version. See the file COPYING for details.
6import struct
8#Note: since encoding flags and compression flags are all mutually exclusive,
9# (ie: only one encoder and at most one compressor can be used at a time)
10# we could theoretically add many more values here,
11# not necessarily limitting ourselves to the ones that land on a bit.
13#packet encoding flags:
14FLAGS_BENCODE = 0x0 #assume bencode if not other flag is set
15FLAGS_RENCODE = 0x1
16FLAGS_CIPHER = 0x2
17FLAGS_YAML = 0x4
18FLAGS_FLUSH = 0x8
20#compression flags are carried in the "level" field,
21#the low bits contain the compression level, the high bits the compression algo:
22ZLIB_FLAG = 0x0 #assume zlib if no other compression flag is set
23LZ4_FLAG = 0x10
24LZO_FLAG = 0x20
25BROTLI_FLAG = 0x40
26FLAGS_NOHEADER = 0x10000 #never encoded, so we can use a value bigger than a byte
29_header_unpack_struct = struct.Struct(b'!cBBBL')
30HEADER_SIZE = _header_unpack_struct.size
31assert HEADER_SIZE==8
33def unpack_header(buf):
34 return _header_unpack_struct.unpack_from(buf)
36#'P' + protocol-flags + compression_level + packet_index + data_size
37_header_pack_struct = struct.Struct(b'!BBBBL')
38assert ord("P") == 80
39def pack_header(proto_flags, level, index, payload_size) -> bytes:
40 return _header_pack_struct.pack(80, proto_flags, level, index, payload_size)