Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Need help decoding Bson
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
craiggwilson  
View profile   Translate to Translated (View Original)
 More options May 25 2012, 2:44 pm
From: craiggwilson <craiggwil...@gmail.com>
Date: Fri, 25 May 2012 11:44:55 -0700 (PDT)
Local: Fri, May 25 2012 2:44 pm
Subject: Re: Need help decoding Bson

Is the stream you are passing in encoded in BSON or is it a JSON string
encoded as binary?  As in, does the stream match the bson spec here:  
http://bsonspec.org/#/specification?

On Friday, May 25, 2012 1:15:45 PM UTC-4, sLaVeN wrote:

> Hi Robert,

> yes, there could have been an issue there because I was trying to
> convert the stream to string as well as bytes array which was giving
> me those issues. However, I tried now to pass in the stream directly
> to the Deserializer and it looks like its trying to do something but
> complains about Duplicate element. There is no duplicate element. We
> have WebApp where we can make these calls and Json that Im getting
> back is fine, no duplicates but when i try to do it from my C# code, i
> get the following error. Could there be a bug in the Driver? Thanks

> Unhandled Exception: System.InvalidOperationException: Duplicate
> element name 'm
> _fleg'.
>    at MongoDB.Bson.BsonDocument.Add(BsonElement element)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.BsonDocument.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonArray.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonValue.ReadFrom(BsonReader bsonReader)
>    at MongoDB.Bson.BsonElement.ReadFrom(BsonReader bsonReader,
> BsonElement& elem
> ent)
>    at MongoDB.Bson.BsonDocument.Deserialize(BsonReader bsonReader,
> Type nominalT
> ype, IBsonSerializationOptions options)
>    at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader
> bsonReade
> r, Type nominalType, IBsonSerializationOptions options)
>    at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream
> stream, Type
> nominalType)
>    at
> MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType]
> (Stream
>  stream)
>    at Test.Program.HttpRequest() in C:\project\XPathFormatingTools\Test
> \Test\Pro
> gram.cs:line 86
>    at Test.Program.Main(String[] args) in C:\project
> \XPathFormatingTools\Test\Te
> st\Program.cs:line 61
> Press any key to continue . . .

> On May 24, 7:29 pm, Robert Stam <rob...@10gen.com> wrote:
> > BSON is a binary encoding. If your file is not a binary file you won't
> be
> > able to decode it as BSON.

> > If your file is a text file containing JSON you will want to parse it a
> > different way:

> > string json; // load this from your file
> > BsonDocument document = BsonSerializer.Deserialize<BsonDocument>(json);

> > On Thu, May 24, 2012 at 7:57 PM, sLaVeN <slug...@gmail.com> wrote:
> > > Thanks Robert for the quick reply. I tried that but I am getting an
> > > exception.

> > > string bson = File.ReadAllText(@"C:\Users\myuser\Desktop\bson.txt");
> > > byte[] bytesarr = Encoding.UTF8.GetBytes(bson);  // Tried different
> > > Encoding here but that didn't seem to matter.
> > >  BsonDocument document =

> MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(bytesar
> r);

> > > Steps:
> > > 1) Convert bsonresponse to bytes array
> > > 2) Call the Deserializer you have provided
> > > 3) Execute and i get following exception

> > > Unhandled Exception: System.IO.EndOfStreamException: Attempted to read
> > > past the
> > > end of the stream.
> > >   at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream, Int32 count)
> > >   at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream)
> > >   at MongoDB.Bson.IO.BsonReader.Create(Stream stream,
> > > BsonBinaryReaderSettings
> > > settings)
> > >   at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Stream
> > > stream, Type
> > > nominalType)
> > >   at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(Byte[]
> > > bytes, Type n
> > > ominalType)
> > >   at
> > > MongoDB.Bson.Serialization.BsonSerializer.Deserialize[TNominalType]
> > > (Byte[]
> > >  bytes)
> > >   at Test.Program.Main(String[] args) in C:\project
> > > \XPathFormatingTools\Test\Te
> > > st\Program.cs:line 54

> > > Thanks Alot!

> > > On May 24, 3:49 pm, Robert Stam <rob...@10gen.com> wrote:
> > > > You can also deserialize BSON data directly from a binary stream,
> like
> > > this:

> > > >     Stream stream;
> > > >     var document = BsonSerializer.Deserialize<BsonDocument>(stream);

> > > > On Thu, May 24, 2012 at 6:43 PM, Robert Stam <rob...@10gen.com>
> wrote:
> > > > > Write whatever code you need to get the BSON data as a byte array,
> and
> > > > > then you can decode it using:

> > > > >     byte[] bytes;
> > > > >     BsonDocument document =
> > > > > BsonSerializer.Deserialize<BsonDocument>(bytes);

> > > > > On Thu, May 24, 2012 at 6:38 PM, sLaVeN <slug...@gmail.com>
> wrote:

> > > > >> Hi,

> > > > >> I need help decoding Bson. I am making a WebRequest and getting
> > > > >> encoded Bson blob which I need to decode in C#. IN java you would
> do
> > > > >> something like this

> > > > >> static main(args)
> > > > >>                {
> > > > >>                                if(args.length != 1)
> > > > >>                                {
> > > > >>                                                println("Usage
> > > > >> <binFile>")
> > > > >>                                }
> > > > >>                                BSONDecoder decoder = new
> > > > >> BSONDecoder()
> > > > >>                                BSONObject bson =
> decoder.readObject
> > > > >> (new FileInputStream(args[0]))
> > > > >>                                OutputBson(System.out, bson, 0)
> > > > >>                }

> > > > >> but I need to do similar in C#. Could somebody help me do this in
> C#?
> > > > >> What would be BSONDecoder equivalant in C#? I have the Mongo
> > > > >> Driver,BSON DLL so i just need to find out the right set of calls
> to
> > > > >> decode it.

> > > > >> Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.