Esempio n. 1
0
 def serialize(dec):
     sign, digits, exponent = dec.as_tuple()
     unscaled = int(''.join([str(digit) for digit in digits]))
     if sign:
         unscaled *= -1
     scale = int32_pack(-exponent)
     unscaled = varint_pack(unscaled)
     return scale + unscaled
Esempio n. 2
0
 def serialize(dec):
     sign, digits, exponent = dec.as_tuple()
     unscaled = int(''.join([str(digit) for digit in digits]))
     if sign:
         unscaled *= -1
     scale = int32_pack(-exponent)
     unscaled = varint_pack(unscaled)
     return scale + unscaled
Esempio n. 3
0
 def send(self, f, streamid, compression=False):
     body = StringIO()
     self.send_body(body)
     body = body.getvalue()
     version = PROTOCOL_VERSION | HEADER_DIRECTION_FROM_CLIENT
     flags = 0  # no compression supported yet
     msglen = int32_pack(len(body))
     header = '%c%c%c%c%s' % (version, flags, streamid, self.opcode, msglen)
     f.write(header)
     if len(body) > 0:
         f.write(body)
Esempio n. 4
0
 def send(self, f, streamid, compression=False):
     body = StringIO()
     self.send_body(body)
     body = body.getvalue()
     version = PROTOCOL_VERSION | HEADER_DIRECTION_FROM_CLIENT
     flags = 0 # no compression supported yet
     msglen = int32_pack(len(body))
     header = '%c%c%c%c%s' % (version, flags, streamid, self.opcode, msglen)
     f.write(header)
     if len(body) > 0:
         f.write(body)
Esempio n. 5
0
 def send(self, f, streamid, compression=None):
     body = StringIO()
     self.send_body(body)
     body = body.getvalue()
     version = PROTOCOL_VERSION | HEADER_DIRECTION_FROM_CLIENT
     flags = 0
     if compression is not None and len(body) > 0:
         body = compression(body)
         flags |= 0x1
     msglen = int32_pack(len(body))
     header = ''.join(map(int8_pack, (version, flags, streamid, self.opcode))) \
              + msglen
     f.write(header)
     if len(body) > 0:
         f.write(body)
Esempio n. 6
0
 def send(self, f, streamid, compression=None):
     body = StringIO()
     self.send_body(body)
     body = body.getvalue()
     version = PROTOCOL_VERSION | HEADER_DIRECTION_FROM_CLIENT
     flags = 0
     if compression is not None and len(body) > 0:
         body = compression(body)
         flags |= 0x1
     msglen = int32_pack(len(body))
     header = ''.join(map(int8_pack, (version, flags, streamid, self.opcode))) \
              + msglen
     f.write(header)
     if len(body) > 0:
         f.write(body)
Esempio n. 7
0
def write_int(f, i):
    f.write(int32_pack(i))
Esempio n. 8
0
def write_int(f, i):
    f.write(int32_pack(i))