diff options
-rw-r--r-- | nejdb/Ejdb.SON/BSONIterator.cs | 53 | ||||
-rw-r--r-- | nejdb/nejdb.userprefs | 7 |
2 files changed, 51 insertions, 9 deletions
diff --git a/nejdb/Ejdb.SON/BSONIterator.cs b/nejdb/Ejdb.SON/BSONIterator.cs index a7865be..6d0c239 100644 --- a/nejdb/Ejdb.SON/BSONIterator.cs +++ b/nejdb/Ejdb.SON/BSONIterator.cs @@ -22,18 +22,59 @@ using System.Diagnostics; namespace Ejdb.SON { - public sealed class BSONIteratorValue { + /** + * <summary>BSON field value</summary> + **/ + [Serializable] + public sealed class BSONValue { public readonly BSONType Type; public readonly string Key; public readonly object Value; - public BSONIteratorValue(BSONType type, string key, object value) { + public BSONValue(BSONType type, string key, object value) { this.Type = type; this.Key = key; this.Value = value; } - public BSONIteratorValue(BSONType type, string key) : this(type, key, null) { + public BSONValue(BSONType type, string key) : this(type, key, null) { + } + } + + /** + * <summary>BSON document deserialized data wrapper</summary> + **/ + [Serializable] + public sealed class BSONDocument { + Dictionary<string, BSONValue> _fields; + readonly List<BSONValue> _fieldslist; + + public BSONDocument() { + this._fields = null; + this._fieldslist = new List<BSONValue>(); + } + + public BSONDocument Add(BSONValue bv) { + _fieldslist.Add(bv); + if (_fields != null) { + _fields.Add(bv.Key, bv); + } + return this; + } + + public BSONValue GetBSONValue(string key) { + CheckFields(); + return _fields[key]; + } + + void CheckFields() { + if (_fields != null) { + return; + } + _fields = new Dictionary<string, BSONValue>(Math.Max(_fieldslist.Count + 1, 32)); + foreach (var bv in _fieldslist) { + _fields.Add(bv.Key, bv); + } } } @@ -45,7 +86,7 @@ namespace Ejdb.SON { string _entryKey; int _entryLen; bool _entryDataSkipped; - BSONIteratorValue _entryDataValue; + BSONValue _entryDataValue; public int DocumentLength { get { return this._doclen; } @@ -150,7 +191,7 @@ namespace Ejdb.SON { return _ctype; } - public BSONIteratorValue FetchIteratorValue() { + public BSONValue FetchIteratorValue() { if (_entryDataSkipped) { return _entryDataValue; } @@ -159,7 +200,7 @@ namespace Ejdb.SON { case BSONType.EOO: case BSONType.UNDEFINED: case BSONType.NULL: - _entryDataValue = new BSONIteratorValue(_ctype, _entryKey); + _entryDataValue = new BSONValue(_ctype, _entryKey); break; case BSONType.BOOL: break; diff --git a/nejdb/nejdb.userprefs b/nejdb/nejdb.userprefs index ebfe62c..f81032b 100644 --- a/nejdb/nejdb.userprefs +++ b/nejdb/nejdb.userprefs @@ -1,8 +1,9 @@ <Properties> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> - <MonoDevelop.Ide.Workbench ActiveDocument="Ejdb.SON/BSONType.cs"> + <MonoDevelop.Ide.Workbench ActiveDocument="Ejdb.SON/BSONIterator.cs"> <Files> - <File FileName="Ejdb.SON/BSONType.cs" Line="40" Column="15" /> + <File FileName="Ejdb.SON/BSONType.cs" Line="1" Column="1" /> + <File FileName="Ejdb.SON/BSONIterator.cs" Line="41" Column="1" /> </Files> <Pads> <Pad Id="ProjectPad"> @@ -12,7 +13,7 @@ <Node name="References" expanded="True" /> <Node name="Ejdb.DB" expanded="True" /> <Node name="Ejdb.SON" expanded="True"> - <Node name="BSONType.cs" selected="True" /> + <Node name="BSONIterator.cs" selected="True" /> </Node> <Node name="Ejdb.Tests" expanded="True" /> </Node> |