FulcrumFS FulcrumFS
FulcrumFS FulcrumFS
DocFX + Singulink = ♥

Search Results for

    Method ToOrderedBytes

    ToOrderedBytes()

    Returns the 16-byte ordered encoding of the file ID, under which sequential (version 7) IDs sort in the order they were created and after every secure (version 4) ID.

    Declaration
    public byte[] ToOrderedBytes()
    Returns
    Type Description
    byte[]
    Remarks

    The encoding is for storing file IDs in an ordered binary database column, so that an index over the column receives new sequential IDs at its end instead of throughout it. Store it in a fixed 16-byte binary column: binary(16) on SQL Server, whose uniqueidentifier type orders values by their last six bytes first, and bytea or BLOB on other databases.

    Under ordinal comparison of the bytes (unsigned, first byte first, as databases compare binary values), the encoding of every version 7 ID is greater than the encoding of every version 4 ID, and version 7 IDs compare by their timestamp and then their counter, so the IDs from one FileIdGenerator compare in the order they were created. A repository that switches its FileIdMode from secure to sequential IDs therefore adds its new IDs after all of its old ones. In RFC 9562 byte order the same version 7 IDs would fall in a narrow band in the middle of the version 4 IDs, whose bytes are random, because a version 7 ID starts with the high byte of its timestamp, which is 0x01 from late 2004 to late 2039.

    The encoding is not RFC 9562 byte order: it moves the version nibble in front of the timestamp. Do not store values in this encoding and in RFC 9562 byte order in the same column; the same ID has different bytes in each, and the two orders disagree. Callers that want RFC 9562 byte order instead can use ToByteArray(bool) on Guid with bigEndian set to true. Use FromOrderedBytes(ReadOnlySpan<byte>) to create a file ID from its ordered encoding.

    ToOrderedBytes(Span<byte>)

    Writes the 16-byte ordered encoding of the file ID to the specified span. See ToOrderedBytes() for the order and its use.

    Declaration
    public void ToOrderedBytes(Span<byte> destination)
    Parameters
    Type Name Description
    Span<byte> destination

    The span to write the 16 bytes to.

    Exceptions
    Type Condition
    ArgumentException

    destination is shorter than 16 bytes.

    © Singulink. All rights reserved.