Core/CafeLib.Core/Support/ObjectId.cs
/// <summary>
/// Packs the components of an ObjectId into a byte array.
/// </summary>
/// <param name="timestamp">The timestamp.</param>
/// <param name="machine">The machine hash.</param>
/// <param name="pid">The PID.</param>
/// <param name="increment">The increment.</param>
/// <returns>A byte array.</returns>
Packs the components of an ObjectId into a byte array.
Packs the components of an ObjectId into a byte array .
public static byte[] Pack(int timestamp, int machine, short pid, int increment)
        {
            if ((machine & 0xff000000) != 0)
            {
                throw new ArgumentOutOfRangeException(nameof(machine), "The machine value must be between 0 and 16777215 (it must fit in 3 bytes).");
            }
            if ((increment & 0xff000000) != 0)
            {
                throw new ArgumentOutOfRangeException(nameof(increment), "The increment value must be between 0 and 16777215 (it must fit in 3 bytes).");
            }
            var bytes = new byte[12];
            bytes[0] = (byte)(timestamp >> 24);
            bytes[1] = (byte)(timestamp >> 16);
            bytes[2] = (byte)(timestamp >> 8);
            bytes[3] = (byte)(timestamp);
            bytes[4] = (byte)(machine >> 16);
            bytes[5] = (byte)(machine >> 8);
            bytes[6] = (byte)(machine);
            bytes[7] = (byte)(pid >> 8);
            bytes[8] = (byte)(pid);
            bytes[9] = (byte)(increment >> 16);
            bytes[10] = (byte)(increment >> 8);
            bytes[11] = (byte)(increment);
            return bytes;
        }
public static byte [ ] Pack ( int timestamp , int machine , short pid , int increment ) { if ( ( machine & 0xff000000 ) != 0 ) { throw new ArgumentOutOfRangeException ( nameof ( machine ) , " " ) ; } if ( ( increment & 0xff000000 ) != 0 ) { throw new ArgumentOutOfRangeException ( nameof ( increment ) , " " ) ; } var bytes = new byte [ 12 ] ; bytes [ 0 ] = ( byte ) ( timestamp >> 24 ) ; bytes [ 1 ] = ( byte ) ( timestamp >> 16 ) ; bytes [ 2 ] = ( byte ) ( timestamp >> 8 ) ; bytes [ 3 ] = ( byte ) ( timestamp ) ; bytes [ 4 ] = ( byte ) ( machine >> 16 ) ; bytes [ 5 ] = ( byte ) ( machine >> 8 ) ; bytes [ 6 ] = ( byte ) ( machine ) ; bytes [ 7 ] = ( byte ) ( pid >> 8 ) ; bytes [ 8 ] = ( byte ) ( pid ) ; bytes [ 9 ] = ( byte ) ( increment >> 16 ) ; bytes [ 10 ] = ( byte ) ( increment >> 8 ) ; bytes [ 11 ] = ( byte ) ( increment ) ; return bytes ; }
Packs the components of an ObjectId into a byte array.
Packs the components of an ObjectId into a byte array .
A byte array.
A byte array .
timestamp
int
None
machine
int
The machine hash.
The machine hash .
pid
short
None
increment
int
None