class Response(schema.BinarySchema): vn = schema.MustEqual(schema.Bytes(1), b"\x00") rep = schema.SizedIntEnum(schema.uint8, Rep) dst_port = schema.uint16be dst_ip = schema.Convert(schema.Bytes(4), encode=socket.inet_aton, decode=socket.inet_ntoa)
class ClientRequest(schema.BinarySchema): ver = schema.MustEqual(schema.uint8, 4) cmd = schema.SizedIntEnum(schema.uint8, Cmd) dst_port = schema.uint16be dst_ip = schema.Convert(schema.Bytes(4), encode=socket.inet_aton, decode=socket.inet_ntoa) user_id = schema.EndWith(b"\x00")
class Content(schema.BinarySchema): name = schema.MustEqual(schema.Bytes(3), b"abc") name2 = schema.LengthPrefixedObject(schema.uint8, schema.Bytes(1))