public async static Task <byte[]> GetBytes(string text, BinaryMode type) { try { switch (type) { case BinaryMode.String: return(Settings.Encoding.GetBytes(text)); case BinaryMode.Base64: return(Convert.FromBase64String(text)); case BinaryMode.DecWithComma: return(GetBytesFromDecWithComma(text)); case BinaryMode.HexWithDash: return(GetBytesFromHexWithDash(text)); case BinaryMode.Hex: return(GetBytesFromHex(text)); default: throw new Exception("GetBytes二进制类型不存在"); } } catch (Exception ex) { await ShowError("分析失败", ex); return(null); } }
public async static Task <string> GetString(byte[] bytes, BinaryMode type) { try { switch (type) { case BinaryMode.String: throw new Exception("无法转换为字符串"); case BinaryMode.Base64: return(Convert.ToBase64String(bytes)); case BinaryMode.DecWithComma: return(GetDecWithCommaString(bytes)); case BinaryMode.HexWithDash: return(GetHexWithDashString(bytes)); case BinaryMode.Hex: return(GetHexString(bytes)); default: throw new Exception("GetBytes二进制类型不存在"); } } catch (Exception ex) { await ShowError("分析失败", ex); return(null); } }
/// <summary> /// Reads the binary object. /// </summary> private T ReadBinaryObject <T>(bool doDetach) { var len = Stream.ReadInt(); var binaryBytesPos = Stream.Position; if (_mode != BinaryMode.Deserialize) { return(TypeCaster <T> .Cast(ReadAsBinary(binaryBytesPos, len, doDetach))); } Stream.Seek(len, SeekOrigin.Current); var offset = Stream.ReadInt(); var retPos = Stream.Position; Stream.Seek(binaryBytesPos + offset, SeekOrigin.Begin); _mode = BinaryMode.KeepBinary; try { return(Deserialize <T>()); } finally { _mode = BinaryMode.Deserialize; Stream.Seek(retPos, SeekOrigin.Begin); } }
/// <summary> /// Internal deserialization routine. /// </summary> /// <param name="mode">The mode.</param> /// <returns> /// Deserialized object. /// </returns> private T Deserialize <T>(BinaryMode mode) { if (_deserialized == null) { T res; using (IBinaryStream stream = new BinaryHeapStream(_data)) { stream.Seek(_offset, SeekOrigin.Begin); res = _marsh.Unmarshal <T>(stream, mode); } var desc = _marsh.GetDescriptor(true, _header.TypeId); if (!desc.KeepDeserialized) { return(res); } _deserialized = res; } return((T)_deserialized); }
private void AddOperationMessageBindingContent(BinaryMode binaryMode, MessageBinding messageBinding) { if (binaryMode != BinaryMode.Attachment) { AddOperationContentBinding(messageBinding.Extensions, x => x); return; } var soapPart = new MimePart(); addGlobalNamespace(NamespaceConstants.MIME); #if NETSTANDARD1_6_1 AddOperationContentBinding(soapPart.Extensions, x => x); #else AddOperationContentBinding(soapPart.Extensions, protocol.Style.CreateSoapHeader); #endif var filePart = new MimePart { Extensions = { new MimeContentBinding { Part = "file", Type = "application/binary" } } }; messageBinding.Extensions.Add(new MimeMultipartRelatedBinding { Parts = { soapPart, filePart } }); }
/// <summary> /// Unmarshal object. /// </summary> /// <param name="data">Data array.</param> /// <param name="mode">The mode.</param> /// <returns> /// Object. /// </returns> public T Unmarshal <T>(byte[] data, BinaryMode mode = BinaryMode.Deserialize) { using (var stream = new BinaryHeapStream(data)) { return(Unmarshal <T>(stream, mode)); } }
public static Variant FromBytes(byte[] bytes, BinaryMode mode, IVariantObjectFactory factory) { using (MemoryStream ms = new MemoryStream(bytes)) { BinaryReader reader = new BinaryReader(ms, mode, factory); return reader.Read(); } }
public BinaryReader(Stream stream, BinaryMode mode, IVariantObjectFactory factory, bool requireSeekableReader) { m_mode = mode; m_factory = factory; m_stream = stream; m_filter = stream; m_requireSeekableReader = requireSeekableReader; }
public static Variant FromBytes(byte[] bytes, BinaryMode mode, IVariantObjectFactory factory) { using (MemoryStream ms = new MemoryStream(bytes)) { BinaryReader reader = new BinaryReader(ms, mode, factory); return(reader.Read()); } }
unsafe public static Variant FromBytes(byte *bytes, long length, BinaryMode mode, IVariantObjectFactory factory) { using (UnmanagedMemoryStream ms = new UnmanagedMemoryStream(bytes, length)) { BinaryReader reader = new BinaryReader(ms, mode, factory); return(reader.Read()); } }
public static byte[] ToBytes(Variant value, BinaryMode mode) { using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms, mode)) { writer.Write(value); } return ms.ToArray(); } }
public static byte[] ToBytes(Variant value, BinaryMode mode) { using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms, mode)) { writer.Write(value); } return(ms.ToArray()); } }
public static int GetBytes(Variant value, BinaryMode mode, byte[] buffer, int bufferOffset) { using (var ms = new MemoryStream(buffer, bufferOffset, buffer.Length - bufferOffset)) { using (var writer = new BinaryWriter(ms, mode)) { writer.Write(value); } return((int)ms.Position); } }
/// <summary> /// Constructor. /// </summary> /// <param name="marsh">Marshaller.</param> /// <param name="stream">Input stream.</param> /// <param name="mode">The mode.</param> /// <param name="builder">Builder.</param> public BinaryReader (Marshaller marsh, IBinaryStream stream, BinaryMode mode, BinaryObjectBuilder builder) { _marsh = marsh; _mode = mode; _builder = builder; Stream = stream; }
/// <summary> /// Constructor. /// </summary> /// <param name="marsh">Marshaller.</param> /// <param name="descs">Descriptors.</param> /// <param name="stream">Input stream.</param> /// <param name="mode">The mode.</param> /// <param name="builder">Builder.</param> public BinaryReader (Marshaller marsh, IDictionary <long, IBinaryTypeDescriptor> descs, IBinaryStream stream, BinaryMode mode, BinaryObjectBuilder builder) { _marsh = marsh; _descs = descs; _mode = mode; _builder = builder; Stream = stream; }
public BinaryWriter(Stream stream, BinaryMode mode) { m_mode = mode; m_stream = stream; if ((m_mode & BinaryMode.Compress) != 0) { m_filter = new DeflateStream(stream, CompressionMode.Compress, true); } else { m_filter = stream; } m_mode |= BinaryMode.DateTimeAsTicks; m_disposed = false; }
public BinaryWriter(Stream stream, BinaryMode mode) { m_mode = mode; m_stream = stream; if ((m_mode & BinaryMode.Compress) != 0) { DeflateStream ds = new DeflateStream(stream, CompressionMode.Compress, true); m_filter = new BufferedStream(ds, c_bufferSize); } else { m_filter = stream; } m_mode |= BinaryMode.DateTimeAsTicks; m_disposed = false; }
public void setBinaryMode(BinaryMode mode) { var rep = new ActionReply(); switch (mode) { case BinaryMode.ASCII: rep = sendCommand("TYPE A"); break; case BinaryMode.Binary: rep = sendCommand("TYPE I"); break; } SysLog(rep); if (!rep.Success /*.Code != 200*/) { //throw new IOException(rep.Response.Substring(4)); SysLog("Unable to set correct binary mode - you sure this server supports either " + '"' + "TYPE A" + '"' + " or " + '"' + "TYPE I" + '"' + "?"); } }
/// <summary> /// Start unmarshal session. /// </summary> /// <param name="stream">Stream.</param> /// <param name="mode">The mode.</param> /// <returns>Reader.</returns> public BinaryReader StartUnmarshal(IBinaryStream stream, BinaryMode mode = BinaryMode.Deserialize) { return(new BinaryReader(this, stream, mode, null)); }
/// <summary> /// Unmarshal object. /// </summary> /// <param name="stream">Stream over underlying byte array with correct position.</param> /// <param name="mode">The mode.</param> /// <param name="builder">Builder.</param> /// <returns> /// Object. /// </returns> public T Unmarshal <T>(IBinaryStream stream, BinaryMode mode, BinaryObjectBuilder builder) { return(new BinaryReader(this, stream, mode, builder).Deserialize <T>()); }
/// <summary> /// Unmarshal object. /// </summary> /// <param name="stream">Stream over underlying byte array with correct position.</param> /// <param name="mode">The mode.</param> /// <returns> /// Object. /// </returns> public T Unmarshal <T>(IBinaryStream stream, BinaryMode mode = BinaryMode.Deserialize) { return(Unmarshal <T>(stream, mode, null)); }
public BinaryReader(System.IO.Stream stream, BinaryMode mode, IVariantObjectFactory factory) : this(stream, BinaryMode.Default, null, false) { }
public BinaryReader(Stream stream, BinaryMode mode, IVariantObjectFactory factory) : this(stream, mode, factory, false) { }
protected void ReadHeader() { byte[] bytes = new byte[4]; m_stream.Read(bytes, 0, 4); UInt32 magicNumber = BitConverter.ToUInt32(bytes, 0); if (magicNumber != BinaryConstants.PROTEAN_MAGIC) { throw new VariantException("Invalid magic number"); } // ignore version info for now m_stream.Read(bytes, 0, 4); m_stream.Read(bytes, 0, 4); m_mode = (BinaryMode)System.BitConverter.ToUInt32(bytes, 0); if ((m_mode & BinaryMode.Compress) != 0) { if ((m_mode & BinaryMode.ZlibHeader) != 0) { throw new VariantException("Binary data appears to contain ZLIB header which is currently not supported in the protean.NET BinaryReader"); } System.IO.Compression.DeflateStream deflateStream = new System.IO.Compression.DeflateStream(m_stream, System.IO.Compression.CompressionMode.Decompress, true); if (m_requireSeekableReader) { MemoryStream deflatedStream = new MemoryStream(); int value; while ((value = deflateStream.ReadByte()) != -1) { deflatedStream.WriteByte((byte)value); } m_filter = new MemoryStream(deflatedStream.ToArray(), 0, (int)deflatedStream.Length, false); } else { m_filter = deflateStream; } } }
public static unsafe Variant FromBytes(byte* bytes, long length, BinaryMode mode, IVariantObjectFactory factory) { using (UnmanagedMemoryStream ms = new UnmanagedMemoryStream(bytes, length)) { BinaryReader reader = new BinaryReader(ms, mode, factory); return reader.Read(); } }
/// <summary> /// Unmarshal object. /// </summary> /// <param name="data">Data array.</param> /// <param name="mode">The mode.</param> /// <returns> /// Object. /// </returns> public T Unmarshal <T>(byte[] data, BinaryMode mode = BinaryMode.Deserialize) { return(Unmarshal <T>(new BinaryHeapStream(data), mode)); }