0

The methods AI showed me are not working. However, one method mentioned by AI seems to be usable, but it is private:

private CodedOutputStream(byte[] buffer, int offset, int length)

So, how can I serialize a protobuf message into a preallocated byte array? The preallocated array is large enough.

1 Answer 1

0

I think I found a way, it's easier than I thought:

    var size = msg.CalculateSize(); // msg is protobuf::Message
    var span = _cache.AsSpan(4, size); // _cache is pre-allocated byte array
    msg.WriteTo(span);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.