/// <summary> /// Writes a protocol-buffer representation of the given instance to the supplied stream. /// </summary> /// <param name="instance">The existing instance to be serialized (cannot be null).</param> /// <param name="destination">The destination stream to write to.</param> #if OPTIMIZATION_NETWORK public static void Serialize <T>(SmartBuffer destination, T instance) { if (instance != null) { RuntimeTypeModel.Default.Serialize(destination, instance); } }
public SmartBuffer In(SmartBuffer value) { UInt16 size = (UInt16)value.Size; In(size); _Write(value.GetBuffer(), value.Size); return(this); }
public SmartBuffer Out(ref SmartBuffer value) { UInt16 size = 0; Out(out size); value.Resize(size + value.m_wpos); _Read(__InOut_buf, size); Array.Copy(__InOut_buf, 0, value.m_buff, value.m_wpos, size); value.m_wpos += size; return(this); }
private void Dispose() { // importantly, this does **not** own the stream, and does not dispose it #if OPTIMIZATION_NETWORK if (null != _destBuf) { Flush(this); _destBuf = null; } #else if (dest != null) { Flush(this); dest = null; } #endif model = null; BufferPool.ReleaseBufferToPool(ref ioBuffer); }
public void Reset(SmartBuffer buf, TypeModel model, SerializationContext context) { // if (dest == null) throw new ArgumentNullException("dest"); // if (!dest.CanWrite) throw new ArgumentException("Cannot write to stream", "dest"); //if (model == null) throw new ArgumentNullException("model"); #if OPTIMIZATION_NETWORK this._destBuf = buf; #else #endif this.ioBuffer = BufferPool.GetBuffer(); this.model = model; this.wireType = WireType.None; if (context == null) { context = SerializationContext.Default; } else { context.Freeze(); } this.context = context; NetCache.Clear(); }
public SmartBuffer(SmartBuffer r) { m_validateSize = m_rpos = m_wpos = 0; Resize(r.m_validateSize); }
public static object Merge(SmartBuffer source, object instance, Type type) { return(RuntimeTypeModel.Default.Deserialize(source, instance, type)); }
/// <summary> /// Applies a protocol-buffer stream to an existing instance. /// </summary> /// <typeparam name="T">The type being merged.</typeparam> /// <param name="instance">The existing instance to be modified (can be null).</param> /// <param name="source">The binary stream to apply to the instance (cannot be null).</param> /// <returns>The updated instance; this may be different to the instance argument if /// either the original instance was null, or the stream defines a known sub-type of the /// original instance.</returns> #if OPTIMIZATION_NETWORK_MERGE public static T Merge <T>(SmartBuffer source, T instance) { return((T)RuntimeTypeModel.Default.Deserialize(source, instance, typeof(T))); }
public static void DecodeProtoMsg <T>(this SmartBuffer buff, T msg) { Serializer.Merge(buff, msg); }
public static object DecodeProtoMsg(this SmartBuffer buff, byte[] bytes, object msg, Type type) { buff.Reset(); buff.In(bytes, 0, (uint)bytes.Length); return(Serializer.Merge(buff, msg, type)); }
public static object DecodeProtoMsg(this SmartBuffer buff, object msg, Type type) { return(Serializer.Merge(buff, msg, type)); }
public static void DecodeProtoMsg <T>(this SmartBuffer buff, byte[] bytes, T msg) { buff.Reset(); buff.In(bytes, 0, (uint)bytes.Length); Serializer.Merge(buff, msg); }