/// <summary> /// Creates a new reader against a stream /// </summary> /// <param name="source">The source stream</param> /// <param name="model">The model to use for serialization; this can be null, but this will impair the ability to deserialize sub-objects</param> /// <param name="context">Additional context about this serialization operation</param> /// <param name="length">The number of bytes to read, or -1 to read until the end of the stream</param> public ProtoReader(Stream source, TypeModel model, SerializationContext context, int length) { if (source == null) { throw new ArgumentNullException("source"); } if (!source.CanRead) { throw new ArgumentException("Cannot read from stream", "source"); } this.source = source; this.ioBuffer = BufferPool.GetBuffer(); this.model = model; isFixedLength = length >= 0; dataRemaining = isFixedLength ? length : 0; if (context == null) { context = SerializationContext.Default; } else { context.Freeze(); } this.context = context; }
/// <summary> /// Creates a new writer against a stream /// </summary> /// <param name="dest">The destination stream</param> /// <param name="model">The model to use for serialization; this can be null, but this will impair the ability to serialize sub-objects</param> /// <param name="context">Additional context about this serialization operation</param> public ProtoWriter(Stream dest, 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"); this.dest = dest; this.ioBuffer = BufferPool.GetBuffer(); this.model = model; this.wireType = WireType.None; if (context == null) { context = SerializationContext.Default; } else { context.Freeze(); } this.context = context; }
static SerializationContext() { @default = new SerializationContext(); @default.Freeze(); }
private static void Init(ProtoReader reader, Stream source, TypeModel model, SerializationContext context, int length) { if (source == null) { throw new ArgumentNullException("source"); } if (!source.CanRead) { throw new ArgumentException("Cannot read from stream", "source"); } reader.source = source; reader.ioBuffer = BufferPool.GetBuffer(); reader.model = model; reader.dataRemaining = ((reader.isFixedLength = (length >= 0)) ? length : 0); if (context == null) { context = SerializationContext.Default; } else { context.Freeze(); } reader.context = context; reader.position = (reader.available = (reader.depth = (reader.fieldNumber = (reader.ioIndex = 0)))); reader.blockEnd = int.MaxValue; reader.internStrings = true; reader.wireType = WireType.None; reader.trapCount = 1u; if (reader.netCache == null) { reader.netCache = new NetObjectCache(); } }
private static void Init(ProtoWriter writer, Stream dest, 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"); writer.dest = dest; writer.ioBuffer = BufferPool.GetBuffer(); writer.model = model; writer.wireType = WireType.None; if (context == null) { context = SerializationContext.Default; } else { context.Freeze(); } writer.context = context; }
/// <summary> /// Creates a new writer against a stream /// </summary> /// <param name="model">The model to use for serialization; this can be null, but this will impair the ability to serialize sub-objects</param> /// <param name="context">Additional context about this serialization operation</param> protected private ProtoWriter(TypeModel model, SerializationContext context) { this.model = model; WireType = WireType.None; if (context == null) { context = SerializationContext.Default; } else { context.Freeze(); } Context = context; }
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(); }
/// <summary> /// Creates a new writer against a stream /// </summary> /// <param name="dest">The destination stream</param> /// <param name="model">The model to use for serialization; this can be null, but this will impair the ability to serialize sub-objects</param> /// <param name="context">Additional context about this serialization operation</param> public ProtoWriter(Stream dest, 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"); this.dest = dest; this.ioBuffer = BufferPool.GetBuffer(); this.model = model; this.wireType = WireType.None; if (context == null) { context = SerializationContext.Default; } else { context.Freeze(); } this.context = context; }