ISpanEncodable
Namespace: SnowBank.Data.Binary · interface
Provides functionality to encode the binary representation of an instance into a span
Remarks
This type is expected to be implemented on structs ONLY, in order to achieve the best performance by using JIT inlining and other optimizations as much as possible.
Methods
TryEncode
bool TryEncode(Span<byte> destination, out int bytesWritten)
Encodes this instance into its equivalent binary representation in the database
destination— Destination bufferbytesWritten— Number of bytes written to the buffer
Returns: true if the operation was successful and the buffer was large enough, or false if it was too small
TryGetSizeHint
bool TryGetSizeHint(out int sizeHint)
Returns a quick estimate of the initial buffer size that would be large enough to encode this instance, in a single call to TryEncode
sizeHint— Receives an initial capacity that will satisfy almost all values. There is no guarantees that the size will be exact, and the estimate may be smaller or larger than the actual encoded size.
Returns: true if a size could be quickly computed; otherwise, false
TryGetSpan
bool TryGetSpan(out ReadOnlySpan<byte> span)
Returns the already encoded binary representation of the instance, if already available.
span— Points to the in-memory binary representation of the encoded key
Returns: true if the key has already been encoded, or it its in-memory layout is the same; otherwise, false
This is only intended to support pass-through or already encoded keys (via Slice), or when the binary representation has been cached to allow multiple uses.