-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Object API for structs? #8140
-
struct KeyInfo {
ed25519_pubkey:[ubyte:32];
x25519_pubkey:[ubyte:32];
}
table RegisterPublicKeyRequest {
requester_keyinfo:KeyInfo;
requester_nonce:[ubyte];
}
P2P::Protocol::RegisterPublicKeyRequestT req;
flatbuffers::span<uint8_t,32> s_pk(_sign_public_key,32);
flatbuffers::span<uint8_t,32> e_pk(_enc_public_key,32);
auto keyinfo = std::make_unique<P2P::Protocol::KeyInfo> (s_pk,e_pk);
req.requester_keyinfo = std::move(keyinfo);
req.requester_nonce = {3,3,2,1};
Is it OK to use std::move to set requester_keyinfo? I don't see a KeyInfoT class or struct for object API access to structs.
Or do I need to use --gen-mutable?
I actually don't need to write to the objects more than once, I just want to serialize in a different place and have easy access to the data up to the point of serializing, without having to pass the builder around to finish serializing.
Beta Was this translation helpful? Give feedback.
All reactions
I fell to the latter, memory is already allocated for KeyInfo, no need to allocate twice.
Replies: 2 comments
-
std::memcpy(req.requester_keyinfo->mutable_ed25519_pubkey()->data(),_sign_public_key,32);
std::memcpy(req.requester_keyinfo->mutable_x25519_pubkey()->data(),_enc_public_key,32);
Mutable works.
Is there a preference or best practice?
Beta Was this translation helpful? Give feedback.
All reactions
-
I fell to the latter, memory is already allocated for KeyInfo, no need to allocate twice.
Beta Was this translation helpful? Give feedback.