Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Object API for structs? #8140

Answered by dylanetaft
dylanetaft asked this question in Q&A
Discussion options

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.

#4601

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.

You must be logged in to vote

I fell to the latter, memory is already allocated for KeyInfo, no need to allocate twice.

Replies: 2 comments

Comment options

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?

You must be logged in to vote
0 replies
Comment options

I fell to the latter, memory is already allocated for KeyInfo, no need to allocate twice.

You must be logged in to vote
0 replies
Answer selected by dylanetaft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /