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); } }
private void WriteVLong(long value, SolrBinaryStream stream) { while ((value & ~0x7F) != 0) { stream.Write((byte)((value & 0x7f) | 0x80)); value >>= 7; } stream.Write((byte)value); }
private void WriteVInt(int value, SolrBinaryStream stream) { while ((value & ~0x7F) != 0) { stream.Write(((value & 0x7f) | 0x80)); value >>= 7; } stream.Write(value); }
private void WriteString(string value, SolrBinaryStream stream) { var bytes = Encoding.UTF8.GetBytes(value); WriteTag(STR, stream, bytes.Length); stream.Write(bytes, 0, bytes.Length); }
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); } }
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); } }
public void WriteJavaBin(object list, Stream stream) { var writeStream = new SolrBinaryStream(stream); try { writeStream.Write(VERSION); WriteVal(list, writeStream); } finally { writeStream.Flush(); writeStream.Close(); } }
private void WriteFloat(float value, SolrBinaryStream stream) { stream.Write(FLOAT); stream.WriteFloat(value); }
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); } }
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); } }
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; }
private void WriteByteArray(byte[] buf, int offset, int length, SolrBinaryStream stream) { WriteTag(BYTEARR, stream, length); stream.Write(buf, offset, length); }
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); }
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); } }