Ejemplo n.º 1
0
        public override int GetHashCode()
        {
            int hashcode = 157;

            unchecked {
                if ((Key != null))
                {
                    hashcode = (hashcode * 397) + Key.GetHashCode();
                }
                hashcode = (hashcode * 397) + VType.GetHashCode();
                if ((VStr != null) && __isset.vStr)
                {
                    hashcode = (hashcode * 397) + VStr.GetHashCode();
                }
                if (__isset.vDouble)
                {
                    hashcode = (hashcode * 397) + VDouble.GetHashCode();
                }
                if (__isset.vBool)
                {
                    hashcode = (hashcode * 397) + VBool.GetHashCode();
                }
                if (__isset.vLong)
                {
                    hashcode = (hashcode * 397) + VLong.GetHashCode();
                }
                if ((VBinary != null) && __isset.vBinary)
                {
                    hashcode = (hashcode * 397) + VBinary.GetHashCode();
                }
            }
            return(hashcode);
        }
Ejemplo n.º 2
0
 public static string Decode(ByteStringReader reader,int limit)
 {
     var l = new VLong(reader).V;
       var bytes = reader.ReadBytes((int)l);
       if (l > limit) {
     return bytes.Slice(0,limit).GetStringUTF8();
       }
       return bytes.GetStringUTF8();
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="start">start position of unit</param>
        /// <param name="index">index position inside unit</param>
        /// <param name="word"></param>
        /// <param name="preString"></param>
        /// <param name="position"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static int Decode(byte[] buffer, int start, int index, out string word, string preString,
                                 out long position, out long length)
        {
            index += start;

            if (index >= buffer.Length)
            {
                word     = "";
                position = 0;
                length   = 0;

                return(-1);
            }

            VLong vPosition = new VLong();
            VLong vLength   = new VLong();


            MemoryStream m = new MemoryStream(buffer);

            m.Position = index;

            int bufferLen = m.ReadByte();

            if (bufferLen <= 0)
            {
                word     = "";
                position = 0;
                length   = 0;

                return(-1);
            }

            int preMatchLen = m.ReadByte();

            position = vPosition.ReadFromStream(m);
            length   = vPosition.ReadFromStream(m);

            word = preString.Substring(0, preMatchLen) + Encoding.UTF8.GetString(buffer, (int)m.Position, (int)(bufferLen - (m.Position - index - 1)));

            return(index + bufferLen + 1 - start);
        }
Ejemplo n.º 4
0
        public override string ToString()
        {
            var sb = new StringBuilder("Tag(");

            if ((Key != null))
            {
                sb.Append(", Key: ");
                Key.ToString(sb);
            }
            sb.Append(", VType: ");
            VType.ToString(sb);
            if ((VStr != null) && __isset.vStr)
            {
                sb.Append(", VStr: ");
                VStr.ToString(sb);
            }
            if (__isset.vDouble)
            {
                sb.Append(", VDouble: ");
                VDouble.ToString(sb);
            }
            if (__isset.vBool)
            {
                sb.Append(", VBool: ");
                VBool.ToString(sb);
            }
            if (__isset.vLong)
            {
                sb.Append(", VLong: ");
                VLong.ToString(sb);
            }
            if ((VBinary != null) && __isset.vBinary)
            {
                sb.Append(", VBinary: ");
                VBinary.ToString(sb);
            }
            sb.Append(')');
            return(sb.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Encode unicode string for head
        /// Encoding format:
        /// /buffer length/match length of pre string/encoding bytes/vlong for position
        /// </summary>
        /// <param name="tempMem">Temp memory stream</param>
        /// <param name="buffer">encode to this buffer</param>
        /// <param name="index">encode from index</param>
        /// <param name="word">word will be encoded</param>
        /// <param name="preString">previous string for match</param>
        /// <param name="position">index data position for this word</param>
        /// <param name="length">index data length for this word</param>
        public static int Encode(MemoryStream tempMem, byte[] buffer, int index, string word, string preString, long position, long length)
        {
            tempMem.Position = 0;

            VLong vPosition = new VLong(position);
            VLong vLength   = new VLong(length);

            int i = 0;

            while (i < preString.Length)
            {
                if (i >= word.Length)
                {
                    break;
                }

                if (preString[i] == 0)
                {
                    //PreString end with zero

                    break;
                }

                if (word[i] == preString[i])
                {
                    i++;
                }
                else
                {
                    break;
                }
            }

            int preMatchLen = i;

            if (preMatchLen >= word.Length)
            {
                throw new System.IO.IOException(string.Format("Reduplicate word:{0} in head!", word));
            }

            tempMem.WriteByte((byte)preMatchLen);
            vPosition.WriteToStream(tempMem);
            vLength.WriteToStream(tempMem);
            byte[] utf8Buffer = Encoding.UTF8.GetBytes(word.Substring(preMatchLen, word.Length - preMatchLen));
            tempMem.Write(utf8Buffer, 0, utf8Buffer.Length);

            long tempMemLen = tempMem.Position;

            if (tempMemLen + 1 >= 256)
            {
                throw new System.IO.IOException(string.Format("Word:{0} is too long to insert to head!", word));
            }

            if (tempMemLen + 1 >= buffer.Length - index)
            {
                return(-1);
            }

            buffer[index] = (byte)tempMemLen;
            index++;
            tempMem.Position = 0;
            tempMem.Read(buffer, index, (int)tempMemLen);
            return((int)(index + tempMemLen));
        }
Ejemplo n.º 6
0
 public VLongLiteral(BuiltinTypes types, VLong s, Location loc)
     : base(types, s, loc)
 {
 }