protected override Stream Export(BufferManager bufferManager, int count) { if (count > 256) { throw new ArgumentException(); } lock (this.ThisLock) { BufferStream bufferStream = new BufferStream(bufferManager); // Name if (this.Name != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Name, this.Name); } // CreationTime if (this.CreationTime != DateTime.MinValue) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CreationTime, this.CreationTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo)); } // Comment if (this.Comment != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Comment, this.Comment); } // Seeds foreach (var value in this.Seeds) { using (var stream = value.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Seed, stream); } } // Boxes foreach (var value in this.Boxes) { using (var stream = value.Export(bufferManager, count + 1)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Box, stream); } } // Certificate if (this.Certificate != null) { using (var stream = this.Certificate.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Certificate, stream); } } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { lock (this.ThisLock) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.Key) { this.Keys.Add(Key.Import(rangeStream, bufferManager)); } else if (id == (byte)SerializeId.CorrectionAlgorithm) { this.CorrectionAlgorithm = (CorrectionAlgorithm)Enum.Parse(typeof(CorrectionAlgorithm), ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.InformationLength) { this.InformationLength = ItemUtilities.GetInt(rangeStream); } else if (id == (byte)SerializeId.BlockLength) { this.BlockLength = ItemUtilities.GetInt(rangeStream); } else if (id == (byte)SerializeId.Length) { this.Length = ItemUtilities.GetLong(rangeStream); } } } } }
protected override Stream Export(BufferManager bufferManager, int count) { lock (this.ThisLock) { BufferStream bufferStream = new BufferStream(bufferManager); // TrustSignatures foreach (var value in this.TrustSignatures) { ItemUtilities.Write(bufferStream, (byte)SerializeId.TrustSignature, value); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); } }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // Hash if (this.Hash != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Hash, this.Hash); } // HashAlgorithm if (this.HashAlgorithm != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.HashAlgorithm, this.HashAlgorithm.ToString()); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
protected override Stream Export(BufferManager bufferManager, int count) { BufferStream bufferStream = new BufferStream(bufferManager); // Id if (this.Id != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Id, this.Id); } // Uris foreach (var value in this.Uris) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Uri, value); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); }
protected override Stream Export(BufferManager bufferManager, int count) { lock (this.ThisLock) { BufferStream bufferStream = new BufferStream(bufferManager); // Boxes foreach (var value in this.Boxes) { using (var stream = value.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Box, stream); } } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); } }
protected override Stream Export(BufferManager bufferManager, int count) { lock (this.ThisLock) { BufferStream bufferStream = new BufferStream(bufferManager); // Keys foreach (var value in this.Keys) { using (var stream = value.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Key, stream); } } // CorrectionAlgorithm if (this.CorrectionAlgorithm != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CorrectionAlgorithm, this.CorrectionAlgorithm.ToString()); } // InformationLength if (this.InformationLength != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.InformationLength, this.InformationLength); } // BlockLength if (this.BlockLength != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.BlockLength, this.BlockLength); } // Length if (this.Length != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Length, this.Length); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.Hash) { this.Hash = ItemUtilities.GetByteArray(rangeStream); } else if (id == (byte)SerializeId.HashAlgorithm) { this.HashAlgorithm = (HashAlgorithm)Enum.Parse(typeof(HashAlgorithm), ItemUtilities.GetString(rangeStream)); } } } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { lock (this.ThisLock) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.TrustSignature) { this.TrustSignatures.Add(ItemUtilities.GetString(rangeStream)); } } } } }
protected override Stream Export(BufferManager bufferManager, int count) { lock (this.ThisLock) { BufferStream bufferStream = new BufferStream(bufferManager); // Groups foreach (var value in this.Groups) { using (var stream = value.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Group, stream); } } // CompressionAlgorithm if (this.CompressionAlgorithm != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CompressionAlgorithm, this.CompressionAlgorithm.ToString()); } // CryptoAlgorithm if (this.CryptoAlgorithm != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CryptoAlgorithm, this.CryptoAlgorithm.ToString()); } // CryptoKey if (this.CryptoKey != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CryptoKey, this.CryptoKey); } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); } }
public int GetHashCode(byte[] value) { return(ItemUtilities.GetHashCode(value)); }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { if (count > 256) { throw new ArgumentException(); } lock (this.ThisLock) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.Name) { this.Name = ItemUtilities.GetString(rangeStream); } else if (id == (byte)SerializeId.CreationTime) { this.CreationTime = DateTime.ParseExact(ItemUtilities.GetString(rangeStream), "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); } else if (id == (int)SerializeId.Comment) { this.Comment = ItemUtilities.GetString(rangeStream); } else if (id == (byte)SerializeId.Seed) { this.Seeds.Add(Seed.Import(rangeStream, bufferManager)); } else if (id == (byte)SerializeId.Box) { this.Boxes.Add(Box.Import(rangeStream, bufferManager, count + 1)); } else if (id == (byte)SerializeId.Certificate) { this.Certificate = Certificate.Import(rangeStream, bufferManager); } } } } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { lock (this.ThisLock) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.Name) { this.Name = ItemUtilities.GetString(rangeStream); } else if (id == (byte)SerializeId.Length) { this.Length = ItemUtilities.GetLong(rangeStream); } else if (id == (byte)SerializeId.CreationTime) { this.CreationTime = DateTime.ParseExact(ItemUtilities.GetString(rangeStream), "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); } else if (id == (byte)SerializeId.Comment) { this.Comment = ItemUtilities.GetString(rangeStream); } else if (id == (byte)SerializeId.Rank) { this.Rank = ItemUtilities.GetInt(rangeStream); } else if (id == (byte)SerializeId.Key) { this.Key = Key.Import(rangeStream, bufferManager); } else if (id == (byte)SerializeId.Keyword) { this.Keywords.Add(ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.CompressionAlgorithm) { this.CompressionAlgorithm = (CompressionAlgorithm)Enum.Parse(typeof(CompressionAlgorithm), ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.CryptoAlgorithm) { this.CryptoAlgorithm = (CryptoAlgorithm)Enum.Parse(typeof(CryptoAlgorithm), ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.CryptoKey) { this.CryptoKey = ItemUtilities.GetByteArray(rangeStream); } else if (id == (byte)SerializeId.Certificate) { this.Certificate = Certificate.Import(rangeStream, bufferManager); } } } } }
protected override Stream Export(BufferManager bufferManager, int count) { lock (this.ThisLock) { BufferStream bufferStream = new BufferStream(bufferManager); // Name if (this.Name != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Name, this.Name); } // Length if (this.Length != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Length, this.Length); } // CreationTime if (this.CreationTime != DateTime.MinValue) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CreationTime, this.CreationTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo)); } // Comment if (this.Comment != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Comment, this.Comment); } // Rank if (this.Rank != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Rank, this.Rank); } // Key if (this.Key != null) { using (var stream = this.Key.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Key, stream); } } // Keywords foreach (var value in this.Keywords) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Keyword, value); } // CompressionAlgorithm if (this.CompressionAlgorithm != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CompressionAlgorithm, this.CompressionAlgorithm.ToString()); } // CryptoAlgorithm if (this.CryptoAlgorithm != 0) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CryptoAlgorithm, this.CryptoAlgorithm.ToString()); } // CryptoKey if (this.CryptoKey != null) { ItemUtilities.Write(bufferStream, (byte)SerializeId.CryptoKey, this.CryptoKey); } // Certificate if (this.Certificate != null) { using (var stream = this.Certificate.Export(bufferManager)) { ItemUtilities.Write(bufferStream, (byte)SerializeId.Certificate, stream); } } bufferStream.Seek(0, SeekOrigin.Begin); return(bufferStream); } }