Optimize message serialization 69/240669/5
authorMateusz Cegielka <m.cegielka@samsung.com>
Mon, 10 Aug 2020 11:24:30 +0000 (13:24 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 2 Sep 2020 08:54:41 +0000 (08:54 +0000)
commit8e9da70e3c15bddc9831702dbd0e97dfe19d2790
treeb5f65350473dd3e6547306f41cf1de90c5e78913
parent831d82cd099fb16f6c65c84527447867137a6f89
Optimize message serialization

There is a MessageBuffer class, which stores a list of byte slices as
std::list<std::vector<unsigned char>> and can be used for serializing
structs. Every member calls a Write method, which creates a new vector
and appends it to the list. After the list is built, a vector with an
exactly right size is allocated and the data is copied. Also, the class
contains unnecessary mutable state, because the logic is shared with
streaming deserialization.

I have replaced the serialization methods with a single function, which
serializes all objects twice. The first pass ignores the data and only
computes the message size, which allows the second pass that actually
writes the data to only use a single allocation. The new interface is
also simpler and more robust.

Change-Id: I6091b71083997faf9302ad8549ade467deb23a58
15 files changed:
src/manager/client-async/client-manager-async-impl.cpp
src/manager/client-async/client-manager-async-impl.h
src/manager/client/client-control.cpp
src/manager/client/client-manager-impl.cpp
src/manager/common/message-buffer.cpp
src/manager/common/message-buffer.h
src/manager/crypto/sw-backend/store.cpp
src/manager/crypto/tz-backend/store.cpp
src/manager/service/ckm-logic.cpp
src/manager/service/ckm-service.cpp
src/manager/service/encryption-service.cpp
src/manager/service/ocsp-logic.cpp
unit-tests/test_data-type.cpp
unit-tests/test_pkcs12.cpp
unit-tests/test_serialization.cpp