示例#1
0
 private void WriteTag(byte tag, SolrBinaryStream stream, int?length = null)
 {
     if (length.HasValue)
     {
         if ((tag & 0xe0) != 0)
         {
             if (length.Value < 0x1f)
             {
                 stream.Write(tag | length.Value);
             }
             else
             {
                 stream.Write(tag | 0x1f);
                 WriteVInt(length.Value - 0x1f, stream);
             }
         }
         else
         {
             stream.Write(tag);
             WriteVInt(length.Value, stream);
         }
     }
     else
     {
         stream.Write(tag);
     }
 }
示例#2
0
 private void WriteVLong(long value, SolrBinaryStream stream)
 {
     while ((value & ~0x7F) != 0)
     {
         stream.Write((byte)((value & 0x7f) | 0x80));
         value >>= 7;
     }
     stream.Write((byte)value);
 }
示例#3
0
 private void WriteVInt(int value, SolrBinaryStream stream)
 {
     while ((value & ~0x7F) != 0)
     {
         stream.Write(((value & 0x7f) | 0x80));
         value >>= 7;
     }
     stream.Write(value);
 }
示例#4
0
        private void WriteString(string value, SolrBinaryStream stream)
        {
            var bytes = Encoding.UTF8.GetBytes(value);

            WriteTag(STR, stream, bytes.Length);
            stream.Write(bytes, 0, bytes.Length);
        }
示例#5
0
 private void WriteInt(int value, SolrBinaryStream stream)
 {
     if (value > 0)
     {
         int b = SINT | (value & 0x0f);
         if (value >= 0x0f)
         {
             b |= 0x10;
             stream.Write(b);
             WriteVInt(value >> 4, stream);
         }
         else
         {
             stream.Write(b);
         }
     }
     else
     {
         stream.Write(INT);
         stream.WriteInt(value);
     }
 }
示例#6
0
 private void WriteLong(long value, SolrBinaryStream stream)
 {
     if (((ulong)value & 0xff00000000000000L) == 0)
     {
         int b = SLONG | ((int)value & 0x0f);
         if (value >= 0x0f)
         {
             b |= 0x10;
             stream.Write(b);
             WriteVLong(value >> 4, stream);
         }
         else
         {
             stream.Write(b);
         }
     }
     else
     {
         stream.Write(LONG);
         stream.WriteLong(value);
     }
 }
示例#7
0
        public void WriteJavaBin(object list, Stream stream)
        {
            var writeStream = new SolrBinaryStream(stream);

            try
            {
                writeStream.Write(VERSION);
                WriteVal(list, writeStream);
            }
            finally
            {
                writeStream.Flush();
                writeStream.Close();
            }
        }
示例#8
0
 private void WriteFloat(float value, SolrBinaryStream stream)
 {
     stream.Write(FLOAT);
     stream.WriteFloat(value);
 }
示例#9
0
 public void WriteJavaBin(object list, Stream stream)
 {
     var writeStream = new SolrBinaryStream(stream);
     try
     {
         writeStream.Write(VERSION);
         WriteVal(list, writeStream);
     }
     finally
     {
         writeStream.Flush();
         writeStream.Close();
     }
 }
示例#10
0
 private void WriteLong(long value, SolrBinaryStream stream)
 {
     if (((ulong)value & 0xff00000000000000L) == 0)
     {
         int b = SLONG | ((int)value & 0x0f);
         if (value >= 0x0f)
         {
             b |= 0x10;
             stream.Write(b);
             WriteVLong(value >> 4, stream);
         }
         else
             stream.Write(b);
     }
     else
     {
         stream.Write(LONG);
         stream.WriteLong(value);
     }
 }
示例#11
0
 private void WriteInt(int value, SolrBinaryStream stream)
 {
     if (value > 0)
     {
         int b = SINT | (value & 0x0f);
         if (value >= 0x0f)
         {
             b |= 0x10;
             stream.Write(b);
             WriteVInt(value >> 4, stream);
         }
         else
             stream.Write(b);
     }
     else
     {
         stream.Write(INT);
         stream.WriteInt(value);
     }
 }
示例#12
0
 private void WriteString(string value, SolrBinaryStream stream)
 {
     var bytes = Encoding.UTF8.GetBytes(value);
     WriteTag(STR, stream, bytes.Length);
     stream.Write(bytes, 0, bytes.Length);
 }
示例#13
0
 private bool WritePrimitive(object value, SolrBinaryStream stream)
 {
     if (value == null)
     {
         stream.Write(NULL);
         return true;
     }
     if (value is string)
     {
         WriteString((string)value, stream);
         return true;
     }
     if (value is int)
     {
         WriteInt((int)value, stream);
         return true;
     }
     if (value is long)
     {
         WriteLong((long)value, stream);
         return true;
     }
     if (value is float)
     {
         WriteFloat((float)value, stream);
         return true;
     }
     if (value is double)
     {
         stream.Write(DOUBLE);
         stream.WriteDouble((double)value);
         return true;
     }
     if (value is byte)
     {
         stream.Write(BYTE);
         stream.Write((byte)value);
         return true;
     }
     if (value is short)
     {
         stream.Write(SHORT);
         stream.WriteShort((short)value);
         return true;
     }
     if (value is DateTime)
     {
         stream.Write(DATE);
         stream.WriteLong((long)((DateTime)value).ToUniversalTime().Subtract(utcDateTime).TotalMilliseconds);
         return true;
     }
     if (value is bool)
     {
         if ((bool)value) stream.Write(BOOL_TRUE);
         else stream.Write(BOOL_FALSE);
         return true;
     }
     if (value is byte[])
     {
         var buf = (byte[])value;
         WriteByteArray(buf, 0, buf.Length, stream);
         return true;
     }
     if (value == END_OBJ)
     {
         WriteTag(END, stream);
         return true;
     }
     return false;
 }
示例#14
0
 private void WriteByteArray(byte[] buf, int offset, int length, SolrBinaryStream stream)
 {
     WriteTag(BYTEARR, stream, length);
     stream.Write(buf, offset, length);
 }
示例#15
0
 private void WriteFloat(float value, SolrBinaryStream stream)
 {
     stream.Write(FLOAT);
     stream.WriteFloat(value);
 }
示例#16
0
 private bool WritePrimitive(object value, SolrBinaryStream stream)
 {
     if (value == null)
     {
         stream.Write(NULL);
         return(true);
     }
     if (value is string)
     {
         WriteString((string)value, stream);
         return(true);
     }
     if (value is int)
     {
         WriteInt((int)value, stream);
         return(true);
     }
     if (value is long)
     {
         WriteLong((long)value, stream);
         return(true);
     }
     if (value is float)
     {
         WriteFloat((float)value, stream);
         return(true);
     }
     if (value is double)
     {
         stream.Write(DOUBLE);
         stream.WriteDouble((double)value);
         return(true);
     }
     if (value is byte)
     {
         stream.Write(BYTE);
         stream.Write((byte)value);
         return(true);
     }
     if (value is short)
     {
         stream.Write(SHORT);
         stream.WriteShort((short)value);
         return(true);
     }
     if (value is DateTime)
     {
         stream.Write(DATE);
         stream.WriteLong((long)((DateTime)value).ToUniversalTime().Subtract(utcDateTime).TotalMilliseconds);
         return(true);
     }
     if (value is bool)
     {
         if ((bool)value)
         {
             stream.Write(BOOL_TRUE);
         }
         else
         {
             stream.Write(BOOL_FALSE);
         }
         return(true);
     }
     if (value is byte[])
     {
         var buf = (byte[])value;
         WriteByteArray(buf, 0, buf.Length, stream);
         return(true);
     }
     if (value == END_OBJ)
     {
         WriteTag(END, stream);
         return(true);
     }
     return(false);
 }
示例#17
0
 private void WriteByteArray(byte[] buf, int offset, int length, SolrBinaryStream stream)
 {
     WriteTag(BYTEARR, stream, length);
     stream.Write(buf, offset, length);
 }
示例#18
0
 private void WriteVLong(long value, SolrBinaryStream stream)
 {
     while ((value & ~0x7F) != 0)
     {
         stream.Write((byte)((value & 0x7f) | 0x80));
         value >>= 7;
     }
     stream.Write((byte)value);
 }
示例#19
0
 private void WriteVInt(int value, SolrBinaryStream stream)
 {
     while ((value & ~0x7F) != 0)
     {
         stream.Write(((value & 0x7f) | 0x80));
         value >>= 7;
     }
     stream.Write(value);
 }
示例#20
0
 private void WriteTag(byte tag, SolrBinaryStream stream, int? length = null)
 {
     if (length.HasValue)
     {
         if ((tag & 0xe0) != 0)
         {
             if (length.Value < 0x1f)
             {
                 stream.Write(tag | length.Value);
             }
             else
             {
                 stream.Write(tag | 0x1f);
                 WriteVInt(length.Value - 0x1f, stream);
             }
         }
         else
         {
             stream.Write(tag);
             WriteVInt(length.Value, stream);
         }
     }
     else
     {
         stream.Write(tag);
     }
 }