private static BsonItem ReadItem(byte code, BsonDocument document, EasyReader reader) { object val = null; switch (code) { case 0x01: // double val = reader.ReadDouble(); break; case 0x02: // string val = reader.ReadString(Encoding.UTF8).TrimEnd('\x00'); if (document.StringTableMode == BsonStringTableMode.KeysAndValues) val = document.ReverseStringTable[int.Parse((string)val)]; break; case 0x03: // document val = Read(reader, document).Top; break; case 0x04: // array val = Read(reader, document, true).Top; break; case 0x05: // binary var length = reader.ReadInt32(); var subtype = reader.ReadByte(); if (subtype != 0x00) throw new NotSupportedException("BSON subtypes other than 'generic binary data' are not supported."); val = reader.ReadBytes(length); break; case 0x06: // undefined break; case 0x07: // ObjectId // why does this parser support ObjectIds and not other binary data? // shhhhh val = Encoding.ASCII.GetString(reader.ReadBytes(12)); break; case 0x08: // boolean val = reader.ReadBoolean(); break; case 0x09: // UTC datetime val = reader.ReadInt64(); break; case 0x0A: // null break; case 0x0B: // regex // why are you using regex in a Rant package? throw new NotSupportedException("Regular expressions are not supported."); case 0x0C: // db pointer throw new NotSupportedException("DB pointers are not supported."); case 0x0D: // Javascript code case 0x0F: // JS code with scope throw new NotSupportedException("Javascript in BSON is not supported."); case 0x0E: // depreceated val = reader.ReadString(Encoding.UTF8); break; case 0x10: // 32 bit integer val = reader.ReadInt32(); break; case 0x11: // timestamp case 0x12: // 64 bit integer val = reader.ReadInt64(); break; case 0xFF: // min key case 0x7F: // max key // we don't care about these so let's just skip em break; } if (!(val is BsonItem)) return new BsonItem(val) { Type = code }; var i = (BsonItem)val; i.Type = code; return i; }
private static BsonItem ReadItem(byte code, BsonDocument document, EasyReader reader) { object val = null; switch (code) { case 0x01: // double val = reader.ReadDouble(); break; case 0x02: // string val = reader.ReadString(Encoding.UTF8).TrimEnd('\x00'); if (document.StringTableMode == BsonStringTableMode.KeysAndValues) { val = document.ReverseStringTable[int.Parse((string)val)]; } break; case 0x03: // document val = Read(reader, document).Top; break; case 0x04: // array val = Read(reader, document, true).Top; break; case 0x05: // binary var length = reader.ReadInt32(); var subtype = reader.ReadByte(); if (subtype != 0x00) { throw new NotSupportedException("BSON subtypes other than 'generic binary data' are not supported."); } val = reader.ReadBytes(length); break; case 0x06: // undefined break; case 0x07: // ObjectId // why does this parser support ObjectIds and not other binary data? // shhhhh val = Encoding.ASCII.GetString(reader.ReadBytes(12)); break; case 0x08: // boolean val = reader.ReadBoolean(); break; case 0x09: // UTC datetime val = reader.ReadInt64(); break; case 0x0A: // null break; case 0x0B: // regex // why are you using regex in a Rant package? throw new NotSupportedException("Regular expressions are not supported."); case 0x0C: // db pointer throw new NotSupportedException("DB pointers are not supported."); case 0x0D: // Javascript code case 0x0F: // JS code with scope throw new NotSupportedException("Javascript in BSON is not supported."); case 0x0E: // depreceated val = reader.ReadString(Encoding.UTF8); break; case 0x10: // 32 bit integer val = reader.ReadInt32(); break; case 0x11: // timestamp case 0x12: // 64 bit integer val = reader.ReadInt64(); break; case 0xFF: // min key case 0x7F: // max key // we don't care about these so let's just skip em break; } if (!(val is BsonItem)) { return new BsonItem(val) { Type = code } } ; var i = (BsonItem)val; i.Type = code; return(i); } }