private void DoFind(InlineSearchControl.SearchEventArgs e, bool next) { bool found = false; if (IsHexSelected()) { byte[] data; if (e.Data != null) { data = e.Data; } else { data = new BinaryEncoding().GetBytes(e.Text); } found = hexEditorControl.FindAndSelect(data, next); } else { string s; if (e.Text != null) { s = e.Text; } else { s = new BinaryEncoding().GetString(e.Data); } found = textEditorControl.FindAndSelect(s, next); } if (!found) { MessageBox.Show(this, CANAPE.Properties.Resources.BinaryDataEditorControl_NoMatch, CANAPE.Properties.Resources.BinaryDataEditorControl_NoMatchCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Read geometry in WKB format from the input. /// </summary> /// <returns>Parsed geometry or null if no other geometry is available.</returns> public Geometry Read() { if (_inputReader.PeekChar() == -1) { return(null); } try { BinaryEncoding encoding = (BinaryEncoding)_inputReader.ReadByte(); if (encoding == BinaryEncoding.BigEndian) { throw new NotSupportedException("Big endian encoding is not supprted in the current version of WkbReader."); } return(WkbReader.ReadGeometry(_inputReader)); } catch (EndOfStreamException) { throw new WkbFormatException("End of stream reached before end of valid WKB geometry end."); } }
public static void SetHeader(this IRequest request, string key, byte[]?data, BinaryEncoding encoding) { if (data == null) { return; } switch (encoding) { case BinaryEncoding.Base64: request.SetHeader(key, Convert.ToBase64String(data)); break; case BinaryEncoding.Hex: request.SetHeader(key, data.HexEncode()); break; default: throw new ArgumentOutOfRangeException(nameof(encoding), encoding, null); } }
private static void WriteStringPart(string value, DataWriter writer, Dictionary <string, int> stringCache) { Encoding encoding = new BinaryEncoding(); if (String.IsNullOrEmpty(value) || (value == ".")) { writer.Write(0); } else { if (stringCache.ContainsKey(value)) { ushort pos = (ushort)(0xC000 | stringCache[value]); writer.WriteUInt16(pos, false); } else { string[] values = value.Split(new[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries); if (values[0].Length > 63) { throw new InvalidDataException("DNS names components cannot be longer than 63 characters"); } long currPos = writer.GetStream().Position; writer.Write((byte)(values[0].Length & 0x3F)); writer.Write(values[0]); stringCache.Add(value, (int)currPos); if (values.Length > 1) { WriteStringPart(values[1], writer, stringCache); } else { WriteStringPart(null, writer, stringCache); } } } }
/// <summary> /// Converts encoding to an encoding object /// </summary> /// <param name="encoding"></param> /// <returns></returns> protected static Encoding GetEncodingFromType(FilterStringEncoding encoding) { Encoding ret; switch (encoding) { case FilterStringEncoding.ASCII: ret = new BinaryEncoding(); break; case FilterStringEncoding.UTF16_BE: ret = new UnicodeEncoding(true, false); break; case FilterStringEncoding.UTF16_LE: ret = new UnicodeEncoding(false, false); break; case FilterStringEncoding.UTF32_BE: ret = new UTF32Encoding(true, false); break; case FilterStringEncoding.UTF32_LE: ret = new UTF32Encoding(false, false); break; case FilterStringEncoding.UTF8: ret = new UTF8Encoding(); break; case FilterStringEncoding.UTF7: ret = new UTF7Encoding(); break; default: throw new ArgumentException(Properties.Resources.StringDataFrameFilterFactory_GetEncodigFromTypeException); } return(ret); }
/// <summary> /// Set the data to difference /// </summary> /// <param name="left">The left data</param> /// <param name="right">The right data</param> public void SetData(DataNode left, DataNode right) { _left = left.ToArray(); _right = right.ToArray(); BinaryEncoding enc = new BinaryEncoding(true); string leftStr = left.ToDataString(); string rightStr = right.ToDataString(); leftStr = leftStr.Replace('\0', ' '); rightStr = rightStr.Replace('\0', ' '); _leftlines = SplitLines(leftStr); _rightlines = SplitLines(rightStr); richTextBoxLeft.Lines = _leftlines; richTextBoxRight.Lines = _rightlines; hexEditorControlLeft.Bytes = _left; hexEditorControlRight.Bytes = _right; }
/// <summary> /// Writes the Encoding byte defined by <see cref="WkbWriterSettings.Encoding"/> property to the output stream. /// </summary> /// <param name="writer">The BinaryWriter to be used.</param> /// <param name="encoding">The encoding of binary data.</param> private static void WriteEncoding(BinaryWriter writer, BinaryEncoding encoding) { writer.Write((byte)encoding); }
void IAmqpSerializable.Encode(ByteBuffer buffer) { BinaryEncoding.Encode(new ArraySegment <byte>(this.buffer, this.Offset, this.Length), buffer); }
public override void DecodeValue(ByteBuffer buffer) { base.Value = BinaryEncoding.Decode(buffer, 0); }
internal override void EncodeValue(ByteBuffer buffer) { BinaryEncoding.Encode((ArraySegment <byte>) this.Value, buffer); }
/// <summary> /// Decodes a binary from the buffer and advances the buffer's position. /// </summary> /// <param name="buffer">The buffer to read.</param> /// <returns>A binary.</returns> /// <remarks>The method allocates a new buffer and copies the bytes to the returned buffer. /// To avoid allocation, call <see cref="BinaryEncoding.Decode(ByteBuffer, FormatCode, bool)"/>.</remarks> public static ArraySegment <byte> DecodeBinary(ByteBuffer buffer) { return(BinaryEncoding.Decode(buffer, 0)); }
public static string Encode(IEnumerable <byte> data, BinaryEncoding encoding) => Encode(data.ToArray(), encoding);
public override int GetValueEncodeSize() { return(BinaryEncoding.GetEncodeSize((ArraySegment <byte>)base.Value)); }
public override void EncodeValue(ByteBuffer buffer) { BinaryEncoding.Encode((ArraySegment <byte>)base.Value, buffer); }
/// <summary> /// Gets the encode size of a binary value. /// </summary> /// <param name="value">The binary value.</param> /// <returns>Encode size in bytes of the binary value.</returns> public static int GetBinaryEncodeSize(ArraySegment <byte> value) { return(BinaryEncoding.GetEncodeSize(value)); }
/// <summary> /// Encodes a binary value and appends the bytes to the buffer. /// </summary> /// <param name="data">The binary value.</param> /// <param name="buffer">The destination buffer.</param> public static void EncodeBinary(ArraySegment <byte> data, ByteBuffer buffer) { BinaryEncoding.Encode(data, buffer); }
public static DynValue open(ScriptExecutionContext executionContext, CallbackArguments args) { string filename = args.AsType(0, "open", DataType.String, false).String; DynValue vmode = args.AsType(1, "open", DataType.String, true); DynValue vencoding = args.AsType(2, "open", DataType.String, true); string mode = vmode.IsNil() ? "r" : vmode.String; string invalidChars = mode.Replace("+", "") .Replace("r", "") .Replace("a", "") .Replace("w", "") .Replace("b", "") .Replace("t", ""); if (invalidChars.Length > 0) { throw ScriptRuntimeException.BadArgument(1, "open", "invalid mode"); } try { string encoding = vencoding.IsNil() ? null : vencoding.String; // list of codes: http://msdn.microsoft.com/en-us/library/vstudio/system.text.encoding%28v=vs.90%29.aspx. // In addition, "binary" is available. Encoding e = null; bool isBinary = mode.Contains('b'); if (encoding == "binary") { isBinary = true; e = new BinaryEncoding(); } else if (encoding == null) { if (!isBinary) { e = GetUTF8Encoding(); } else { e = new BinaryEncoding(); } } else { if (isBinary) { throw new ScriptRuntimeException("Can't specify encodings other than nil or 'binary' for binary streams."); } e = Encoding.GetEncoding(encoding); } return(UserData.Create(Open(executionContext, filename, e, mode))); } catch (Exception ex) { return(DynValue.NewTuple(DynValue.Nil, DynValue.NewString(IoExceptionToLuaMessage(ex, filename)))); } }
internal override int GetValueEncodeSize() { return(BinaryEncoding.GetEncodeSize((ArraySegment <byte>) this.Value)); }
// Parse the buffer for message sections. If a section is specified in the flags, fully // decode it; otherwise attempt to fast advance the buffer. The handler is invoked at // least once with the first section found. The section could be null if it is not in // the flags. The parser stops if handler returns false. public static bool TryRead <T1, T2>(T1 t1, T2 t2, ByteBuffer buffer, SectionFlag sections, Func <T1, T2, Section, bool> sectionHandler, string context, out Error error) { error = null; if (buffer.TryAddReference()) { int pos = buffer.Offset; try { while (buffer.Length > 0) { int offset = buffer.Offset; SectionInfo info; if (!TryReadSectionInfo(buffer, out info, out error)) { return(false); } AmqpDescribed section; int length; if ((info.Flag & sections) > 0) { section = info.Ctor(); if (section.DescriptorCode == Data.Code) { section.Value = BinaryEncoding.Decode(buffer, 0, false); } else { section.DecodeValue(buffer); } section.Offset = offset; length = buffer.Offset - offset; section.Length = length; } else { // fast forward to next section FormatCode formatCode = AmqpEncoding.ReadFormatCode(buffer); if (formatCode != FormatCode.Null) { error = info.Scanner(formatCode, buffer); if (error != null) { return(false); } } section = null; length = buffer.Offset - offset; } Section s = new Section(info.Flag, offset, length, section); bool shouldContinue = sectionHandler(t1, t2, s); if (!shouldContinue) { break; } } return(true); } catch (SerializationException se) { error = GetDecodeError(se.Message); } catch (AmqpException ae) { error = ae.Error; } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } error = GetDecodeError(exception.Message); } finally { buffer.Seek(pos); buffer.RemoveReference(); } } else { // The delivery is already disposed. Treat it as decode error. error = GetDecodeError(Resources.AmqpBufferAlreadyReclaimed); } return(false); }
internal override void DecodeValue(ByteBuffer buffer) { this.Value = BinaryEncoding.Decode(buffer, 0); }
/// <summary> /// Writes the Encoding byte defined by <see cref="WkbWriterSettings.Encoding"/> property to the output stream. /// </summary> /// <param name="writer">The BinaryWriter to be used.</param> /// <param name="encoding">The encoding of binary data.</param> private static void WriteEncoding(BinaryWriter writer, BinaryEncoding encoding) { writer.Write((byte)encoding); }