Exemplo n.º 1
0
        /// <summary>
        /// Encodes each face as a varint64 with value kNumFaces * count + face.
        /// 21 faces can fit in a single byte.  Varint64 is used so that 4G faces
        /// can be encoded instead of just 4G / 6 = ~700M.
        /// </summary>
        public void Encode(Encoder encoder)
        {
            encoder.Ensure(Encoder.kVarintMax64);

            // It isn't necessary to encode the number of faces left for the last run,
            // but since this would only help if there were more than 21 faces, it will
            // be a small overall savings, much smaller than the bound encoding.
            encoder.PutVarUInt64((UInt64)(S2CellId.kNumFaces * (Int64)Count + Face));
            System.Diagnostics.Debug.Assert(encoder.Avail() >= 0);
        }
Exemplo n.º 2
0
    /// <summary>
    /// Encodes an unsigned integer in little-endian format using "length" bytes.
    /// (The client must ensure that the encoder's buffer is large enough.)
    ///
    /// REQUIRES: T is an unsigned integer type.
    /// REQUIRES: 2 <= sizeof(T) <= 8
    /// REQUIRES: 0 <= length <= sizeof(T)
    /// REQUIRES: value < 256 ** length
    /// REQUIRES: encoder.Avail() >= length
    /// </summary>
    public static void EncodeUintWithLength(UInt16 value, int length, Encoder encoder)
    {
        System.Diagnostics.Debug.Assert(length >= 0 && length <= sizeof(UInt16));
        System.Diagnostics.Debug.Assert(encoder.Avail() >= length);

        while (--length >= 0)
        {
            encoder.Put8((byte)value);
            value = (UInt16)(value >> 8);
        }
        System.Diagnostics.Debug.Assert(value == 0);
    }