public static Message FromBson(BSONDocument bson) { var msg = new Message(); if (bson[FLD_GDID] is BSONBinaryElement binGdid) { msg.Gdid = DataDocConverter.GDID_BSONtoCLR(binGdid); } if (bson[FLD_GUID] is BSONBinaryElement binGuid) { msg.Guid = DataDocConverter.GUID_BSONtoCLR(binGuid); } if (bson[FLD_RELATED_TO] is BSONBinaryElement binRel) { msg.RelatedTo = DataDocConverter.GUID_BSONtoCLR(binRel); } if (bson[FLD_CHANNEL] is BSONInt64Element chn) { msg.Channel = new Atom((ulong)chn.Value); } if (bson[FLD_APP] is BSONInt64Element app) { msg.App = new Atom((ulong)app.Value); } if (bson[FLD_TYPE] is BSONInt32Element tp) { msg.Type = (MessageType)tp.Value; } if (bson[FLD_SOURCE] is BSONInt32Element src) { msg.Source = src.Value; } if (bson[FLD_TIMESTAMP] is BSONDateTimeElement utc) { msg.UTCTimeStamp = utc.Value; } if (bson[FLD_HOST] is BSONStringElement host) { msg.Host = host.Value; } if (bson[FLD_FROM] is BSONStringElement from) { msg.From = from.Value; } if (bson[FLD_TOPIC] is BSONStringElement topic) { msg.Topic = topic.Value; } if (bson[FLD_TEXT] is BSONStringElement text) { msg.Text = text.Value; } if (bson[FLD_PARAMETERS] is BSONStringElement pars) { msg.Parameters = pars.Value; } if (bson[FLD_EXCEPTION] is BSONStringElement except) { msg.ExceptionData = JsonReader.ToDoc <WrappedExceptionData>(except.Value); } if (bson[FLD_AD] is BSONDocumentElement ad) { msg.ArchiveDimensions = ArchiveConventions.EncodeArchiveDimensions(ad.Value); } return(msg); }