1 Star 0 Fork 0

damone/FastBinaryEncoding

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
serialization.py 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
Ivan Shynkarenka 提交于 2018-08-22 21:52 +08:00 . Python
import fbe
import proto
from proto import proto
def main():
# Create a new account with some orders
account = proto.Account(1, "Test", proto.State.good, proto.Balance("USD", 1000.0), proto.Balance("EUR", 100.0))
account.orders.append(proto.Order(1, "EURUSD", proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0))
account.orders.append(proto.Order(2, "EURUSD", proto.OrderSide.sell, proto.OrderType.limit, 1.0, 100.0))
account.orders.append(proto.Order(3, "EURUSD", proto.OrderSide.buy, proto.OrderType.stop, 1.5, 10.0))
# Serialize the account to the FBE stream
writer = proto.AccountModel(fbe.WriteBuffer())
writer.serialize(account)
assert writer.verify()
# Show the serialized FBE size
print("FBE size: {}".format(writer.buffer.size))
# Deserialize the account from the FBE stream
reader = proto.AccountModel(fbe.ReadBuffer())
reader.attach_buffer(writer.buffer)
assert reader.verify()
reader.deserialize(account)
# Show account content
print()
print(account)
if __name__ == "__main__":
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/damone/FastBinaryEncoding.git
git@gitee.com:damone/FastBinaryEncoding.git
damone
FastBinaryEncoding
FastBinaryEncoding
master

搜索帮助