Lawo.EmberPlusSharp.Ember.EmberWriter.GetLengthLength C# (CSharp) Method

GetLengthLength() private static method

private static GetLengthLength ( int length, int &shift ) : int
length int
shift int
return int
        private static int GetLengthLength(int? length, out int shift)
        {
            if (!length.HasValue || (length <= sbyte.MaxValue))
            {
                shift = 0;
                return 1;
            }
            else if (length <= byte.MaxValue)
            {
                // Since lengths are unsigned we will get a shift of 0 for lengths < 256. A shift of 0 is equivalent to 1
                // byte, which is wrong for lengths > 127, see 8.1.3.5. For a shift > 0, the long form will be employed in
                // any case, so the correction below really only applies when value is in the range [128, 255].
                shift = 0;
                return 2;
            }
            else
            {
                shift = Get8BitStartShift(length.Value, false);
                return GetLengthFromShift8Bit(shift) + 1;
            }
        }