public SolrInputDocument ReadSolrInputDocument(FastInputStream dis) { int sz = ReadVInt(dis); float? docBoost = (float?)ReadVal(dis); SolrInputDocument sdoc = new SolrInputDocument(); sdoc.Boost = docBoost; for (int i = 0; i < sz; i++) { float boost = 1.0f; String fieldName; Object boostOrFieldName = ReadVal(dis); if (boostOrFieldName is float) { boost = (float)boostOrFieldName; fieldName = (String)ReadVal(dis); } else { fieldName = (String)boostOrFieldName; } Object fieldVal = ReadVal(dis); sdoc[fieldName] = new SolrInputField(fieldName, fieldVal, boost); } return(sdoc); }
public long ReadSmallLong(FastInputStream dis) { long v = tagByte & 0x0F; if ((tagByte & 0x10) != 0) { v = (ReadVLong(dis) << 4) | v; } return(v); }
public int ReadSmallInt(FastInputStream dis) { int v = tagByte & 0x0F; if ((tagByte & 0x10) != 0) { v = (ReadVInt(dis) << 4) | v; } return(v); }
public int ReadSize(FastInputStream stream) { int sz = tagByte & 0x1f; if (sz == 0x1f) { sz += ReadVInt(stream); } return(sz); }
public IList ReadArray(FastInputStream dis) { int sz = ReadSize(dis); ArrayList l = new ArrayList(sz); for (int i = 0; i < sz; i++) { l.Add(ReadVal(dis)); } return(l); }
/** * The counterpart for {@link #writeVInt(int, FastOutputStream)} * * @ If there is a low-level I/O error. */ public static int ReadVInt(FastInputStream stream) { byte b = (byte)stream.ReadByte(); int i = b & 0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { b = (byte)stream.ReadByte(); i |= (b & 0x7F) << shift; } return i; }
/** * The counterpart for {@link #writeVInt(int, FastOutputStream)} * * @ If there is a low-level I/O error. */ public static int ReadVInt(FastInputStream stream) { byte b = (byte)stream.ReadByte(); int i = b & 0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { b = (byte)stream.ReadByte(); i |= (b & 0x7F) << shift; } return(i); }
public static long ReadVLong(FastInputStream stream) { byte b = (byte)stream.ReadByte(); long i = b & 0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { b = (byte)stream.ReadByte(); i |= (long)(b & 0x7F) << shift; } return(i); }
public Object Unmarshal(Stream inputStream) { FastInputStream dis = new FastInputStream(inputStream); version = (byte)dis.ReadByte(); if (version != VERSION) { throw new ApplicationException("Invalid version (expected " + VERSION + ", but " + version + ") or the data in not in 'javabin' format"); } return(ReadVal(dis)); }
public IDictionary <Object, Object> ReadMap(FastInputStream dis) { int sz = ReadVInt(dis); IDictionary <Object, Object> m = new LinkedHashMap <Object, Object>(); for (int i = 0; i < sz; i++) { Object key = ReadVal(dis); Object val = ReadVal(dis); m[key] = val; } return(m); }
public SolrDocument ReadSolrDocument(FastInputStream dis) { NamedList nl = (NamedList)ReadVal(dis); SolrDocument doc = new SolrDocument(); for (int i = 0; i < nl.Count; i++) { String name = nl.GetName(i); Object val = nl.GetVal(i); doc.SetField(name, val); } return(doc); }
public SimpleOrderedMap ReadOrderedMap(FastInputStream dis) { int sz = ReadSize(dis); SimpleOrderedMap nl = new SimpleOrderedMap(); for (int i = 0; i < sz; i++) { String name = (String)ReadVal(dis); Object val = ReadVal(dis); nl.Add(name, val); } return(nl); }
public NamedList ReadNamedList(FastInputStream dis) { int sz = ReadSize(dis); NamedList nl = new NamedList(); for (int i = 0; i < sz; i++) { String name = (String)ReadVal(dis); Object val = ReadVal(dis); nl.Add(name, val); } return(nl); }
public String ReadStr(FastInputStream dis) { int sz = ReadSize(dis); if (chars == null || chars.Length < sz) { chars = new char[sz]; } if (bytes == null || bytes.Length < sz) { bytes = new byte[sz]; } dis.ReadFully(bytes, 0, sz); int outUpto = 0; for (int i = 0; i < sz;) { int b = bytes[i++] & 0xff; int ch; if (b < 0xc0) { ch = b; } else if (b < 0xe0) { ch = ((b & 0x1f) << 6) + (bytes[i++] & 0x3f); } else if (b < 0xf0) { ch = ((b & 0xf) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f); } else { ch = ((b & 0x7) << 18) + ((bytes[i++] & 0x3f) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f); } if (ch <= 0xFFFF) { // target is a character <= 0xFFFF chars[outUpto++] = (char)ch; } else { // target is a character in range 0xFFFF - 0x10FFFF int chHalf = ch - 0x10000; chars[outUpto++] = (char)((chHalf >> 0xA) + 0xD800); chars[outUpto++] = (char)((chHalf & 0x3FF) + 0xDC00); } } return(new String(chars, 0, outUpto)); }
public IList ReadIterator(FastInputStream fis) { ArrayList l = new ArrayList(); while (true) { Object o = ReadVal(fis); if (o == END_OBJ) { break; } l.Add(o); } return(l); }
public SolrDocumentList ReadSolrDocumentList(FastInputStream dis) { SolrDocumentList solrDocs = new SolrDocumentList(); IList list = (IList)ReadVal(dis); solrDocs.NumFound = (long)list[0]; solrDocs.Start = (long)list[1]; solrDocs.MaxScore = (float?)list[2]; ArrayList l = (ArrayList)ReadVal(dis); foreach (SolrDocument doc in l) { solrDocs.Add(doc); } return(solrDocs); }
public String ReadExternString(FastInputStream fis) { int idx = ReadSize(fis); if (idx != 0) {// idx != 0 is the index of the extern string return(stringsList[idx - 1]); } else {// idx == 0 means it has a string value String s = (String)ReadVal(fis); if (stringsList == null) { stringsList = new List <String>(); } stringsList.Add(s); return(s); } }
public long ReadSmallLong(FastInputStream dis) { long v = tagByte & 0x0F; if ((tagByte & 0x10) != 0) v = (ReadVLong(dis) << 4) | v; return v; }
public int ReadSmallInt(FastInputStream dis) { int v = tagByte & 0x0F; if ((tagByte & 0x10) != 0) v = (ReadVInt(dis) << 4) | v; return v; }
public int ReadSize(FastInputStream stream) { int sz = tagByte & 0x1f; if (sz == 0x1f) sz += ReadVInt(stream); return sz; }
public SimpleOrderedMap ReadOrderedMap(FastInputStream dis) { int sz = ReadSize(dis); SimpleOrderedMap nl = new SimpleOrderedMap(); for (int i = 0; i < sz; i++) { String name = (String)ReadVal(dis); Object val = ReadVal(dis); nl.Add(name, val); } return nl; }
public Object ReadVal(FastInputStream dis) { tagByte = (byte)dis.ReadByte(); // if ((tagByte & 0xe0) == 0) { // if top 3 bits are clear, this is a normal tag // OK, try type + size in single byte switch (tagByte >> 5) { case STR >> 5: return ReadStr(dis); case SINT >> 5: return ReadSmallInt(dis); case SLONG >> 5: return ReadSmallLong(dis); case ARR >> 5: return ReadArray(dis); case ORDERED_MAP >> 5: return ReadOrderedMap(dis); case NAMED_LST >> 5: return ReadNamedList(dis); case EXTERN_STRING >> 5: return ReadExternString(dis); } switch (tagByte) { case NULL: return null; case DATE: try { return dis.ReadLong().ConvertToDateTime(); } catch { return null; } case INT: return dis.ReadInt(); case BOOL_TRUE: return true; case BOOL_FALSE: return false; case FLOAT: return dis.ReadFloat(); case DOUBLE: return dis.ReadDouble(); case LONG: return dis.ReadLong(); case BYTE: return dis.ReadByte(); case SHORT: return dis.ReadShort(); case MAP: return ReadMap(dis); case SOLRDOC: return ReadSolrDocument(dis); case SOLRDOCLST: return ReadSolrDocumentList(dis); case BYTEARR: return ReadByteArray(dis); case ITERATOR: return ReadIterator(dis); case END: return END_OBJ; case SOLRINPUTDOC: return ReadSolrInputDocument(dis); } throw new ApplicationException("Unknown type " + tagByte); }
public SolrInputDocument ReadSolrInputDocument(FastInputStream dis) { int sz = ReadVInt(dis); float? docBoost = (float?)ReadVal(dis); SolrInputDocument sdoc = new SolrInputDocument(); sdoc.Boost = docBoost; for (int i = 0; i < sz; i++) { float boost = 1.0f; String fieldName; Object boostOrFieldName = ReadVal(dis); if (boostOrFieldName is float) { boost = (float)boostOrFieldName; fieldName = (String)ReadVal(dis); } else { fieldName = (String)boostOrFieldName; } Object fieldVal = ReadVal(dis); sdoc[fieldName] = new SolrInputField(fieldName, fieldVal, boost); } return sdoc; }
public String ReadExternString(FastInputStream fis) { int idx = ReadSize(fis); if (idx != 0) {// idx != 0 is the index of the extern string return stringsList[idx - 1]; } else {// idx == 0 means it has a string value String s = (String)ReadVal(fis); if (stringsList == null) stringsList = new List<String>(); stringsList.Add(s); return s; } }
public byte[] ReadByteArray(FastInputStream dis) { byte[] arr = new byte[ReadVInt(dis)]; dis.ReadFully(arr); return arr; }
public Object ReadVal(FastInputStream dis) { tagByte = (byte)dis.ReadByte(); // if ((tagByte & 0xe0) == 0) { // if top 3 bits are clear, this is a normal tag // OK, try type + size in single byte switch (tagByte >> 5) { case STR >> 5: return(ReadStr(dis)); case SINT >> 5: return(ReadSmallInt(dis)); case SLONG >> 5: return(ReadSmallLong(dis)); case ARR >> 5: return(ReadArray(dis)); case ORDERED_MAP >> 5: return(ReadOrderedMap(dis)); case NAMED_LST >> 5: return(ReadNamedList(dis)); case EXTERN_STRING >> 5: return(ReadExternString(dis)); } switch (tagByte) { case NULL: return(null); case DATE: try { return(dis.ReadLong().ConvertToDateTime()); } catch { return(null); } case INT: return(dis.ReadInt()); case BOOL_TRUE: return(true); case BOOL_FALSE: return(false); case FLOAT: return(dis.ReadFloat()); case DOUBLE: return(dis.ReadDouble()); case LONG: return(dis.ReadLong()); case BYTE: return(dis.ReadByte()); case SHORT: return(dis.ReadShort()); case MAP: return(ReadMap(dis)); case SOLRDOC: return(ReadSolrDocument(dis)); case SOLRDOCLST: return(ReadSolrDocumentList(dis)); case BYTEARR: return(ReadByteArray(dis)); case ITERATOR: return(ReadIterator(dis)); case END: return(END_OBJ); case SOLRINPUTDOC: return(ReadSolrInputDocument(dis)); } throw new ApplicationException("Unknown type " + tagByte); }
public byte[] ReadByteArray(FastInputStream dis) { byte[] arr = new byte[ReadVInt(dis)]; dis.ReadFully(arr); return(arr); }
public SolrDocument ReadSolrDocument(FastInputStream dis) { NamedList nl = (NamedList)ReadVal(dis); SolrDocument doc = new SolrDocument(); for (int i = 0; i < nl.Count; i++) { String name = nl.GetName(i); Object val = nl.GetVal(i); doc.SetField(name, val); } return doc; }
public SolrDocumentList ReadSolrDocumentList(FastInputStream dis) { SolrDocumentList solrDocs = new SolrDocumentList(); IList list = (IList)ReadVal(dis); solrDocs.NumFound = (long)list[0]; solrDocs.Start = (long)list[1]; solrDocs.MaxScore = (float?)list[2]; ArrayList l = (ArrayList)ReadVal(dis); foreach (SolrDocument doc in l) { solrDocs.Add(doc); } return solrDocs; }
public IList ReadIterator(FastInputStream fis) { ArrayList l = new ArrayList(); while (true) { Object o = ReadVal(fis); if (o == END_OBJ) break; l.Add(o); } return l; }
public String ReadStr(FastInputStream dis) { int sz = ReadSize(dis); if (chars == null || chars.Length < sz) chars = new char[sz]; if (bytes == null || bytes.Length < sz) bytes = new byte[sz]; dis.ReadFully(bytes, 0, sz); int outUpto = 0; for (int i = 0; i < sz; ) { int b = bytes[i++] & 0xff; int ch; if (b < 0xc0) { ch = b; } else if (b < 0xe0) { ch = ((b & 0x1f) << 6) + (bytes[i++] & 0x3f); } else if (b < 0xf0) { ch = ((b & 0xf) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f); } else { ch = ((b & 0x7) << 18) + ((bytes[i++] & 0x3f) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f); } if (ch <= 0xFFFF) { // target is a character <= 0xFFFF chars[outUpto++] = (char)ch; } else { // target is a character in range 0xFFFF - 0x10FFFF int chHalf = ch - 0x10000; chars[outUpto++] = (char)((chHalf >> 0xA) + 0xD800); chars[outUpto++] = (char)((chHalf & 0x3FF) + 0xDC00); } } return new String(chars, 0, outUpto); }
public IDictionary<Object, Object> ReadMap(FastInputStream dis) { int sz = ReadVInt(dis); IDictionary<Object, Object> m = new LinkedHashMap<Object, Object>(); for (int i = 0; i < sz; i++) { Object key = ReadVal(dis); Object val = ReadVal(dis); m[key] = val; } return m; }
public Object Unmarshal(Stream inputStream) { FastInputStream dis = new FastInputStream(inputStream); version = (byte)dis.ReadByte(); if (version != VERSION) { throw new ApplicationException("Invalid version (expected " + VERSION + ", but " + version + ") or the data in not in 'javabin' format"); } return ReadVal(dis); }
public NamedList ReadNamedList(FastInputStream dis) { int sz = ReadSize(dis); NamedList nl = new NamedList(); for (int i = 0; i < sz; i++) { String name = (String)ReadVal(dis); Object val = ReadVal(dis); nl.Add(name, val); } return nl; }
public static long ReadVLong(FastInputStream stream) { byte b = (byte)stream.ReadByte(); long i = b & 0x7F; for (int shift = 7; (b & 0x80) != 0; shift += 7) { b = (byte)stream.ReadByte(); i |= (long)(b & 0x7F) << shift; } return i; }
public IList ReadArray(FastInputStream dis) { int sz = ReadSize(dis); ArrayList l = new ArrayList(sz); for (int i = 0; i < sz; i++) { l.Add(ReadVal(dis)); } return l; }