Ejemplo n.º 1
0
        public static T Deserialize <T>(BixReader reader, BixContext ctx = null) where T : TypedDoc
        {
            var(got, ok) = TryDeserializeRootOrInternal <T>(true, reader, ctx);

            if (!ok)
            {
                throw new BixException(StringConsts.BIX_TYPE_NOT_SUPPORTED_ERROR.Args(typeof(T).FullName));
            }

            return(got);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Recycles the instance so it can be re-used by the next call to .Obtain()
 /// </summary>
 public virtual void Dispose()
 {
     m_Default            = false;
     m_TargetName         = TargetedAttribute.ANY_TARGET;
     Version              = Format.VERSION;
     m_Nesting            = 0;
     m_MaxDepth           = DEFAULT_MAX_DEPTH;
     m_HasHeader          = false;
     m_PolymorphicRoot    = false;
     m_PolymorphicMembers = true;
     State       = null;
     ts_Instance = this;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns an instance of context initialized for making local blocking call.
        /// The instance needs to be released by calling .Dispose()
        /// </summary>
        public static T Obtain <T>() where T : BixContext, new()
        {
            var self = ts_Instance as T;

            if (self == null)
            {
                self = new T();
            }
            else
            {
                ts_Instance = null;
            }

            return(self);
        }
Ejemplo n.º 4
0
        internal static BixContext ObtainDefault()
        {
            var self = ts_Instance;

            if (self == null)
            {
                self = new BixContext();
            }
            else
            {
                ts_Instance = null;
            }

            self.m_Default = true;

            return(self);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Serializes data document
        /// </summary>
        public static void Serialize(BixWriter writer, TypedDoc root, BixContext ctx = null)
        {
            if (!writer.IsAssigned)
            {
                throw new BixException(StringConsts.ARGUMENT_ERROR + "{0}.!Assigned".Args(nameof(BixWriter)));
            }

            if (ctx == null)
            {
                ctx = BixContext.ObtainDefault();
            }

            //1 Header
            if (ctx.HasHeader)
            {
                Writer.WriteHeader(writer, ctx);
            }

            //2 Payload
            Writer.WriteDoc(writer, root, ctx, isRoot: true);

            ctx.DisposeDefault();
        }
Ejemplo n.º 6
0
 public static object DeserializeAny(BixReader reader, BixContext ctx = null)
 {
     return(null);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Deserializes typed data document from BixReader
 /// </summary>
 public abstract void Deserialize(BixReader reader, TypedDoc doc, BixContext ctx);
Ejemplo n.º 8
0
 /// <summary>
 /// Serializes typed data document into BixWriter
 /// </summary>
 public abstract void Serialize(BixWriter writer, TypedDoc doc, BixContext ctx);