Esempio n. 1
0
def stdServer(server,
              contractSerializer):  # type: (Server, Serializer) -> None
    sout = sys.stdout
    sin = sys.stdin

    def writeBytes(value):  # type: (bytes) -> None
        sout.write(value)

    def readBytes(length):  # type: (int) -> bytes
        buffer = b''
        while len(buffer) < length:
            chunk = sin.read(length - len(buffer))
            if len(chunk) == 0:
                raise RuntimeError("pipe connection broken")
            buffer += chunk
        return buffer

    messageSerializer = MessageSerializer(contractSerializer)
    writer = Writer(writeBytes)
    reader = Reader(readBytes)
    while True:
        messageSerializer.write(
            server.invoke(cast(Request, messageSerializer.read(reader))),
            writer)
        sout.flush()
Esempio n. 2
0
def stdServer(server: Server, contractSerializer: Serializer) -> None:
    sout = sys.stdout.buffer
    sin = sys.stdin.buffer

    def writeBytes(value: bytes) -> None:
        sent = 0
        while sent < len(value):
            written = sout.write(value[sent:])
            if written == 0:
                raise RuntimeError("pipe connection broken")
            sent += written

    def readBytes(length: int) -> bytes:
        buffer = b''
        while len(buffer) < length:
            chunk = sin.read(length - len(buffer))
            if len(chunk) == 0:
                raise RuntimeError("pipe connection broken")
            buffer += chunk
        return buffer

    messageSerializer = MessageSerializer(contractSerializer)
    writer = Writer(writeBytes)
    reader = Reader(readBytes)
    while True:
        messageSerializer.write(
            server.invoke(cast(Request, messageSerializer.read(reader))),
            writer)
        sout.flush()
Esempio n. 3
0
 def writeBase(self, value: 'Expiration', writer: yass.Writer) -> None:
     writer.writeZigZagInt(value.year)
Esempio n. 4
0
 def writeBase(self, value: 'Expiration', writer: yass.Writer) -> None:
     writer.writeZigZagInt(value.year)
     writer.writeZigZagInt(value.month)
     writer.writeZigZagInt(value.day)
Esempio n. 5
0
 def writeBase(self, value: "Expiration", writer: yass.Writer) -> None:
     writer.writeZigZagInt(value.year)
     writer.writeZigZagInt(value.month)
     writer.writeZigZagInt(value.day)
Esempio n. 6
0
def createWriter(io):  # type: (BytesIO) -> Writer
    def writeBytes(b):  # type: (bytes) -> None
        io.write(b)

    return Writer(writeBytes)
Esempio n. 7
0
def createWriter(io: BytesIO) -> Writer:
    def writeBytes(b: bytes) -> None:
        if io.write(b) != len(b):
            raise RuntimeError('IO error')

    return Writer(writeBytes)
Esempio n. 8
0
 def writeBase(self, value: 'Integer', writer: yass.Writer) -> None:
     writer.writeZigZagInt(value.value)