BaseMsgReadWriter

- Change `BaseMsgReadWriter` to encode/decode messages with abstract
method, which can be implemented by the subclasses. This allows us to
create subclasses `FixedSizeLenMsgReadWriter` and
`VarIntLenMsgReadWriter`.
This commit is contained in:
mhchia
2020-02-20 21:48:03 +08:00
parent 88f660a9c5
commit 6016ea731b
5 changed files with 59 additions and 30 deletions

View File

@ -3,7 +3,7 @@ from libp2p.crypto.keys import PrivateKey, PublicKey
from libp2p.crypto.pb import crypto_pb2
from libp2p.crypto.serialization import deserialize_public_key
from libp2p.io.abc import ReadWriteCloser
from libp2p.io.msgio import BaseMsgReadWriter
from libp2p.io.msgio import FixedSizeLenMsgReadWriter
from libp2p.network.connection.exceptions import RawConnError
from libp2p.network.connection.raw_connection_interface import IRawConnection
from libp2p.peer.id import ID
@ -23,7 +23,7 @@ PLAINTEXT_PROTOCOL_ID = TProtocol("/plaintext/2.0.0")
SIZE_PLAINTEXT_LEN_BYTES = 4
class PlaintextHandshakeReadWriter(BaseMsgReadWriter):
class PlaintextHandshakeReadWriter(FixedSizeLenMsgReadWriter):
size_len_bytes = SIZE_PLAINTEXT_LEN_BYTES