Bson library for Delphi?

Can anyone suggest a complete Bson library for Delphi? I am trying to use http://code.google.com/p/pebongo/source/browse/trunk/_bson.pas from http://bsonspec.org , but there are some structures that are not supported.


Or maybe I am not using it correctly, since this class does not have documentation, I cannot find the correct use for it.

I want to create a list of elements, these elements are my serializable objects.
But how to create a list and put an item in a "list"?

+7
source share
2 answers

I created the BSON implementation for Delphi before, mainly based on the existing Variant type in Delphi (and its TVarType). It also supports array options at some point.

see bsonDoc.pas: https://github.com/stijnsanders/TMongoWire

+7
source

I ran into the same problem and cracked the source code a bit. Here is what I prepared then:

procedure TBSONDocument.ReadStream(F: TStream); var len : Integer; elmtype : Byte; elmname : string; begin Clear; F.Read(len, SizeOf(len)); F.Read(elmtype, SizeOf(Byte) ); while elmtype <> BSON_EOF do begin elmname := _ReadString(F); SetLength(FItems, Length(FItems)+1); case elmtype of BSON_FLOAT: FItems[High(FItems)] := TBSONDoubleItem.Create; BSON_STRING: FItems[High(FItems )] := TBSONStringItem.Create; BSON_DOC: FItems[High(FItems )] := TBSONDocumentItem.Create; // Mrsky BSON_ARRAY: FItems[High(FItems)] := TBSONArrayItem.Create; BSON_BINARY: FItems[High(FItems)] := TBSONBinaryItem.Create; BSON_OBJECTID: FItems[High(FItems )] := TBSONObjectIDItem.Create; BSON_BOOLEAN: FItems[High(FItems )] := TBSONBooleanItem.Create; BSON_DATETIME: FItems[High(FItems)] := TBSONDatetimeItem.Create(0); // Mrsky BSON_REGEX: FItems[High(FItems)] := TBSONRegExItem.Create; BSON_DBPTR: FItems[High(FItems)] := TBSONDBRefItem.Create; BSON_JS: FItems[High(FItems )] := TBSONJSItem.Create; BSON_SYMBOL: FItems[High(FItems)] := TBSONSymbolItem.Create; BSON_JSSCOPE: FItems[High(FItems )] := TBSONScopedJSItem.Create; BSON_INT32: FItems[High(FItems )] := TBSONIntItem.Create; BSON_INT64: FItems[High(FItems )] := TBSONInt64Item.Create; BSON_MINKEY: FItems[High(FItems)] := TBSONItem.Create(BSON_MINKEY); BSON_MAXKEY: FItems[High(FItems)] := TBSONItem.Create(BSON_MAXKEY); else raise EBSONException.Create('Unimplemented element handler '+IntToStr(elmtype)); end; with FItems[High(FItems)] do begin elname := elmname; ReadStream(f); end; f.Read(elmtype, SizeOf(Byte)); end; end; 

I did not appreciate how the β€œFree” method was implemented, and removed all of them and introduced a new Destroy method of the destructor, where it fits.

Hope this helps you.

+1
source

All Articles