Пример #1
0
        private int ReadAsNumber(int n_bytes)
        {
            byte[] buffer = new byte[n_bytes];
            Read(buffer, 0, n_bytes);
            int result = 0;

            for (int i = 0; i < n_bytes; ++i)
            {
                result = (result << 8) | JavaUnsignedUtil.AsU8(buffer[i]);
            }
            return(result);
        }
Пример #2
0
        // Compute checksum over size bytes of buf
        public static int ComputeULongSum(byte[] buf, int offset, int size)
        {
            int checksum     = 0;
            int aligned_size = (size & ~3);

            for (int i = 0; i < aligned_size; i += 4)
            {
                checksum += (JavaUnsignedUtil.AsU8(buf[offset + i]) << 24) | (JavaUnsignedUtil.AsU8(buf[offset + i + 1]) <<
                                                                              16) | (JavaUnsignedUtil.AsU8(buf[offset + i + 2]) << 8) | JavaUnsignedUtil.AsU8(buf[offset + i + 3]);
            }
            // treat size not aligned on 4 as if it were padded to 4 with 0's
            if (size != aligned_size)
            {
                int v = 0;
                for (int i = aligned_size; i < size; ++i)
                {
                    v |= JavaUnsignedUtil.AsU8(buf[offset + i]) << (24 - 8 * (i & 3));
                }
                checksum += v;
            }
            return(checksum);
        }
Пример #3
0
 public virtual byte ReadByte()
 {
     return(JavaUnsignedUtil.ToU8(ReadAsNumber(1)));
 }
Пример #4
0
 public virtual short ReadShort()
 {
     return(JavaUnsignedUtil.ToU16(ReadAsNumber(2)));
 }
Пример #5
0
 public virtual int CompareTo(Woff2Common.Table o)
 {
     return(JavaUnsignedUtil.CompareAsUnsigned(tag, o.tag));
 }