コード例 #1
0
ファイル: hqproto.py プロジェクト: damantou/xy-project
def split_response(stream):
    resps = []
    while 1:
        bs = bytestr(stream)
        if len(stream) < 16: break # even not have a complete header
        respmagic, compresstype, seqno, packtype, cmd, datalen, origdatalen = bs.read_struct("=4sBIB2sHH")
        if respmagic != ResponseMagic:
            try:
                stream = stream[stream.index(ResponseMagic):]
            except:
                stream = ''
            continue
        
        bs.cut()
        if len(bs.buf) < datalen: break
        stream = bs.buf[datalen:]
        
        data = bs.read_s(datalen)
        if compresstype==0x1c:
            try:
                data = decompress(data)
            except:
                data = ''

        if origdatalen != len(data):
            data = ''
        
        resps.append((seqno, cmd, data))           
    return tuple(resps), stream
コード例 #2
0
ファイル: hqproto.py プロジェクト: damantou/xy-project
 def build_request(cls, seqno, *args, **kwargs):
     '''
     char zip;               // always 0x0c: data-uncompressed
     uint seq_id;            // 同一种命令的 seq_id。
     char packet_type;    // 00: 回应。 1,2,3... request count
     ushort len;            //    数据长度
     ushort len1;            //  数据长度重复
     #ushort cmd;            // b4 bf: 分钟线。。b5 bf 单笔成交
     '''
     bs = bytestr()
     bs.write_s(cls.cmd)
     cls._build_request(bs, *args, **kwargs)
     length = len(bs.buf)
     bs.pos = 0
     bs.write_struct("=BIBHH", 0x0c, seqno, 1, length, length)
     return bs.buf
コード例 #3
0
ファイル: hqproto.py プロジェクト: damantou/xy-project
 def parse_response(cls, resp):
     bs = bytestr(resp)
     return cls._parse_response(bs)