public void Add(byte[] bytes) { if (CurrentLength + bytes.Length > ExpectedLength) { throw new ArgumentOutOfRangeException(nameof(bytes), $"Length of bytes to add is out of range: {bytes.Length}, {CurrentLength}, {ExpectedLength}"); } Bytes.AddRange(bytes); }
public void AddVertex(List <string[]> vertexAttributeValuesList) { if (vertexAttributeValuesList.Count == parent.attributes.Count) { var bytes = new Bytes(); for (int i = 0; i < vertexAttributeValuesList.Count; i++) { var size = parent.attributes[i].size; var type = parent.attributes[i].type; var strList = new List <string>(vertexAttributeValuesList[i]); while (strList.Count < size) { strList.Add("0"); } try { if (type == GL_FLOAT) { bytes.AddRange(strList.ConvertAll(v => float.Parse(v))); } else { bytes.AddRange(strList.ConvertAll(v => int.Parse(v))); } } catch (Exception e) { } } int count = bytes.Count; for (int i = 0; i < parent.vertexByteSize; i++) { if (i < count) { buildResult.Add(bytes[i]); } else { buildResult.Add(0); } } } }
public void WriteDouble(double v) { byte[] temp = BitConverter.GetBytes(v); for (int i = 0; i < 8; i++) { b[7 - i] = temp[i]; } Bytes.AddRange(b); }
/// <summary> /// Combines the <paramref name="additionalChecksum"/> to the representation of this instance. /// </summary> /// <param name="additionalChecksum">An array of bytes containing a checksum of the additional data this instance must represent.</param> public ChecksumBuilder CombineWith(params byte[] additionalChecksum) { if (additionalChecksum == null) { return(this); } if (additionalChecksum.Length == 0) { return(this); } ComputedChecksum = null; Bytes.AddRange(additionalChecksum); return(this); }
public async void ImportClick(object sender, RoutedEventArgs e) { //Dialog OpenFileDialog dialog = new OpenFileDialog(); FileDialogFilter filter = new FileDialogFilter { Extensions = new[] { "bin" }.ToList(), Name = ".bin file" }; List <FileDialogFilter> list = new List <FileDialogFilter> { filter }; dialog.Filters = list; string[] fileNames = await dialog.ShowAsync(this); string output = ""; //Escape the method if the user exits the window if (fileNames.Length <= 0) { return; } int prevLength = Bytes.Count; //Read bytes and change output byte[] tempBytes = await File.ReadAllBytesAsync(fileNames[0]); AddBytes = tempBytes.ToList(); //If there is already data, then show the window that asks the pointer location if (prevLength > 0) { originalByteCount = Bytes.Count; Bytes.AddRange(tempBytes); } else { Bytes.AddRange(tempBytes); originalByteCount = tempBytes.Length; } ((TextBoxModel)DataContext).InputText += tempBytes.Aggregate("", (current, b) => current + b.ToString("X2") + " "); }
protected override async Task <IEnumerable <byte> > HandleCall(HttpListenerRequest request, HttpListenerResponse response) { switch (RemovePrefix(request.Url.PathAndQuery)) { case uploadPath: var bytesStream = new MemoryStream(); await request.InputStream.CopyToAsync(bytesStream); var bytes = bytesStream.ToArray(); Bytes.AddRange(bytesStream.ToArray().Take(_partialSize)); HandleHeaders(request, response); return(null); default: return(await base.HandleCall(request, response)); } }
public ByteBuffer(bool littleEndian, byte[] raw) : this(littleEndian) { buffer.AddRange(raw); }
public void WriteALLBytes(byte[] bs) { Bytes.AddRange(bs); }
public static void EditPointers(object sender, RoutedEventArgs e) { if (Bytes.Count <= 0) { return; } int index = Convert.ToInt32(((TextBoxModel)_dataContext).OffsetText, 16); int offset = ((AddBytes[index + 2] << 8) + AddBytes[index + 3]) * 4 - 8; //Next pointer int pointer = (((AddBytes[index] << 8) + AddBytes[index + 1]) * 4 - offset + Bytes.Count - AddBytes.Count) / 4; //Location of the start of the file int fileLocation = (((AddBytes[index + 2] << 8) + AddBytes[index + 3]) * 4 - offset + Bytes.Count - AddBytes.Count) / 4; //Update the last pointer in the og file int firstPointerLocation = (index + originalByteCount) / 4; Bytes[originalByteCount - 20] = (byte)(firstPointerLocation >> 8); Bytes[originalByteCount - 19] = (byte)(firstPointerLocation & 0xFF); Console.WriteLine($"First: {pointer:X} {fileLocation:X} {offset:X} {index:X} {originalByteCount:X}"); //Modify the pointers AddBytes[index] = (byte)((pointer & 0xFF00) >> 8); AddBytes[index + 1] = (byte)(pointer & 0xFF); AddBytes[index + 2] = (byte)((fileLocation & 0xFF00) >> 8); AddBytes[index + 3] = (byte)(fileLocation & 0xFF); int prevPointer = pointer; pointer *= 4; while (pointer < Bytes.Count) { //Update the pointers prevPointer = pointer; Console.WriteLine($"In Loop: {pointer:X} {fileLocation:X}"); Console.WriteLine( $"In Loop: {Bytes[pointer]:X2} {Bytes[pointer + 1]:X2} {Bytes[pointer + 2]:X2} {Bytes[pointer + 3]:X2} {Bytes.Count:X} {AddBytes.Count:X}"); fileLocation = (((Bytes[pointer + 2] << 8) + Bytes[pointer + 3]) * 4 - offset + Bytes.Count - AddBytes.Count) / 4; pointer = (((Bytes[pointer] << 8) + Bytes[pointer + 1]) * 4 - offset + Bytes.Count - AddBytes.Count); //Modify the pointers in the file AddBytes[prevPointer - (Bytes.Count - AddBytes.Count)] = (byte)(((pointer / 4) & 0xFF00) >> 8); AddBytes[prevPointer + 1 - (Bytes.Count - AddBytes.Count)] = (byte)((pointer / 4) & 0xFF); AddBytes[prevPointer + 2 - (Bytes.Count - AddBytes.Count)] = (byte)((fileLocation & 0xFF00) >> 8); AddBytes[prevPointer + 3 - (Bytes.Count - AddBytes.Count)] = (byte)(fileLocation & 0xFF); Console.WriteLine($"In Loop2: {pointer:X} {fileLocation:X} {prevPointer:X}"); //Console.WriteLine( // $"In Loop2: {Bytes[pointer]:X2} {Bytes[pointer + 1]:X2} {Bytes[pointer + 2]:X2} {Bytes[pointer + 3]:X2} {Bytes.Count:X} {AddBytes.Count:X}"); } Console.WriteLine($"A {fileLocation:X} {pointer:X} {prevPointer:X} {Bytes.Count} {AddBytes.Count}"); //Re add the bytes Bytes.RemoveRange(Bytes.Count - AddBytes.Count, AddBytes.Count); ((TextBoxModel)_dataContext).InputText.Remove(Bytes.Count - AddBytes.Count); Bytes.AddRange(AddBytes); ((TextBoxModel)_dataContext).InputText += AddBytes.Aggregate("", (current, b) => current + b.ToString("X2")); }
private async void ConnectToSerialPort() { DeviceInformationCollection serialDevices; while ((serialDevices = await DeviceInformation.FindAllAsync(SerialDevice.GetDeviceSelectorFromUsbVidPid(0x04D8, 0x000A))).Count < 1) { Debug.WriteLine("Unable to locate..."); } ReceiverConnected.IsChecked = true; SerialDevice serialPort; while ((serialPort = await SerialDevice.FromIdAsync(serialDevices[0].Id)) == null) { Debug.WriteLine("Failed to open serial port..."); } SerialPortOpen.IsChecked = true; serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000); serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000); serialPort.BaudRate = 9600; serialPort.Parity = SerialParity.None; serialPort.StopBits = SerialStopBitCount.One; serialPort.DataBits = 8; serialPort.Handshake = SerialHandshake.None; var dataReader = new DataReader(serialPort.InputStream); var buffer = new byte[1024]; while (true) { var bytesRead = await dataReader.LoadAsync((uint)buffer.Length); if (bytesRead > 0) { try { dataReader.ReadBytes(buffer); Bytes.AddRange(buffer.Take((int)bytesRead)); byte[] slipPacket; while ((slipPacket = Slip.ExtractSlipPacket(Bytes)) != null) { var waxPacket = WaxPacketConverter.FromBinary(slipPacket, DateTime.Now); if (waxPacket != null) { if (!Devices.Contains(waxPacket.DeviceId.ToString())) { Devices.Add(waxPacket.DeviceId.ToString()); } foreach (var sample in waxPacket.Samples) { _waxSendRepository.Send(new Wax3Data { DeviceId = waxPacket.DeviceId, Timestamp = sample.Timestamp, AccX = sample.X, AccY = sample.Y, AccZ = sample.Z }); } } } } catch (Exception e) { Debug.WriteLine(e); } } } }
public void AddVertex(List <object> vertexAttributeValuesList) { if (vertexAttributeValuesList.Count == parent.attributes.Count) { var bytes = new Bytes(); for (int i = 0; i < vertexAttributeValuesList.Count; i++) { var size = parent.attributes[i].size; var type = parent.attributes[i].type; if (vertexAttributeValuesList[i] is IEnumerable <string> ) { var strList = new List <string>(vertexAttributeValuesList[i] as IEnumerable <string>); while (strList.Count < size) { strList.Add("0"); } try { if (type == GL_FLOAT) { bytes.AddRange(strList.ConvertAll(v => float.Parse(v))); } else { bytes.AddRange(strList.ConvertAll(v => int.Parse(v))); } } catch (Exception e) { } } else if (vertexAttributeValuesList[i] is IEnumerable <float> ) { var floatList = new List <float>(vertexAttributeValuesList[i] as IEnumerable <float>); while (floatList.Count < size) { floatList.Add(0); } try { if (type == GL_FLOAT) { bytes.AddRange(floatList); } else { bytes.AddRange(floatList.ConvertAll(v => (int)v)); } } catch (Exception e) { } } else if (vertexAttributeValuesList[i] is IEnumerable <int> ) { var intList = new List <int>(vertexAttributeValuesList[i] as IEnumerable <int>); while (intList.Count < size) { intList.Add(0); } try { if (type == GL_FLOAT) { bytes.AddRange(intList.ConvertAll(v => (float)v)); } else { bytes.AddRange(intList); } } catch (Exception e) { } } else { throw new Exception(string.Format("Unknown datatype: {0}", vertexAttributeValuesList[i].GetType())); } } int count = bytes.Count; for (int i = 0; i < parent.vertexByteSize; i++) { if (i < count) { buildResult.Add(bytes[i]); } else { buildResult.Add(0); } } } }
public void Write(byte[] value) { Bytes.AddRange(value); }
public void Write(string value) { Bytes.AddRange(BitConverter.GetBytes(value.Length)); Bytes.AddRange(Encoding.ASCII.GetBytes(value)); }
public void Write(bool value) { Bytes.AddRange(BitConverter.GetBytes(value)); }