bytearray

record voice in a Queue<byte[]> and send it to the server

强颜欢笑 提交于 2019-12-19 09:44:01
问题 I am developing voice application. I need a buffer queue of some sort so that i record continuosly in a thread , place the buffers full of bytes into the queue and to transmit to the server, and i take the next buffer from the queue. Here is the recording code: Queue<byte[]> qArray = new LinkedList<byte[]>(); recordingThread = new Thread(new Runnable() { @Override public void run() { bData = new byte[BufferElements]; while (isRecording) { recorder.read(bData, 0, BufferElements); qArray.add

Create new FileStream out of a byte array

人走茶凉 提交于 2019-12-19 09:03:44
问题 I am attempting to create a new FileStream object from a byte array. I'm sure that made no sense at all so I will try to explain in further detail below. Tasks I am completing: 1) Reading the source file which was previously compressed 2) Decompressing the data using GZipStream 3) copying the decompressed data into a byte array. What I would like to change: 1) I would like to be able to use File.ReadAllBytes to read the decompressed data. 2) I would then like to create a new filestream object

Serializing object to byte-array in C++

℡╲_俬逩灬. 提交于 2019-12-19 08:58:56
问题 I am working on an embedded device (microcontroller), and I want to save objects to permanent storage (an EEPROM). Most of the serialization solutions I can find, use the file-system in some way, but my target has no file-system. Therefore my question is, how can I serialize an object to a byte-array so I can save that byte-array to an EEPROM afterwards? Here is an example of what i am trying to do: class Person{ //Constructor, getters and setters are omitted void save(){ char buffer[sizeof

Create a thumbnail and then convert to byte array

谁都会走 提交于 2019-12-19 06:37:30
问题 I'm having a heck of a time with creating thumbnails and then converting them into a byte array. I've tried three methods, and all 3 times I get an error. The first was using Bitmap.GetThumbnailImage, which I have used in the past and then saved directly into Response.OutputStream The second was using System.Drawing.Graphics with DrawImage(). Still no go. The third was just to create a new bitmap, pass in the old bitmap, and set the new size. Same error. Value cannot be null. Parameter name:

Convert byte string to bytes or bytearray

纵饮孤独 提交于 2019-12-19 05:47:28
问题 I have a string as follows: b'\x00\x00\x00\x00\x07\x80\x00\x03' How can I convert this to an array of bytes? ... and back to a string from the bytes? 回答1: in python 3: >>> a=b'\x00\x00\x00\x00\x07\x80\x00\x03' >>> b = list(a) >>> b [0, 0, 0, 0, 7, 128, 0, 3] >>> c = bytes(b) >>> c b'\x00\x00\x00\x00\x07\x80\x00\x03' >>> 回答2: From string to array of bytes: a = bytearray.fromhex('00 00 00 00 07 80 00 03') or a = bytearray(b'\x00\x00\x00\x00\x07\x80\x00\x03') and back to string: key = ''.join

bytes vs bytearray in Python 2.6 and 3

天大地大妈咪最大 提交于 2019-12-19 05:12:55
问题 I'm experimenting with bytes vs bytearray in Python 2.6. I don't understand the reason for some differences. A bytes iterator returns strings: for i in bytes(b"hi"): print(type(i)) Gives: <type 'str'> <type 'str'> But a bytearray iterator returns int s: for i in bytearray(b"hi"): print(type(i)) Gives: <type 'int'> <type 'int'> Why the difference? I'd like to write code that will translate well into Python 3. So, is the situation the same in Python 3? 回答1: In Python 2.6 bytes is merely an

Convert list of byte strings to bytearray (byte stream)

五迷三道 提交于 2019-12-19 04:21:10
问题 I have a list of hex strings representing bytes, of the form "FF". I want to convert the whole list to a byte stream so I can send it over a socket (Python 3). It looks like the bytearray type would work, but I can't find any way to directly convert the list to a bytearray. I can do it manually in a loop, but figure there must be a better Python way to do this. 回答1: hexstrings = ["DE", "AD", "BE", "EF"] # big-endian 0xDEADBEEF bytes = bytearray(int(x, 16) for x in hexstrings) bytes =

Convert list of byte strings to bytearray (byte stream)

我们两清 提交于 2019-12-19 04:21:07
问题 I have a list of hex strings representing bytes, of the form "FF". I want to convert the whole list to a byte stream so I can send it over a socket (Python 3). It looks like the bytearray type would work, but I can't find any way to directly convert the list to a bytearray. I can do it manually in a loop, but figure there must be a better Python way to do this. 回答1: hexstrings = ["DE", "AD", "BE", "EF"] # big-endian 0xDEADBEEF bytes = bytearray(int(x, 16) for x in hexstrings) bytes =

struct.unpack with bytearray's

时光毁灭记忆、已成空白 提交于 2019-12-19 04:12:59
问题 I wrote an application that uses struct.unpack on byte arrays. Running it on my machine using python 2.7.5 it works well: >>> data bytearray(b'\x07\x00\x00\x00\x00\x00\x00\x00') >>> struct.unpack("<Q", data) (7,) however, I tried to use it with a python version 2.7.3 I got an exception: error: unpack requires a string argument of length 8 I need to explicitly cast the bytearray to string before unpacking it. Is this related to the python version change? the struct manual says nothing about

How to reverse the order of a byte array in c#?

有些话、适合烂在心里 提交于 2019-12-18 14:56:44
问题 How do you reverse the order of a byte array in c#? 回答1: You could use the Array.Reverse method: byte[] bytes = GetTheBytes(); Array.Reverse(bytes, 0, bytes.Length); Or, you could always use LINQ and do: byte[] bytes = GetTheBytes(); byte[] reversed = bytes.Reverse().ToArray(); 回答2: Array.Reverse(byteArray); 回答3: you can use the linq method: MyBytes.Reverse() as well as the Array.Reverse() method. Which one you should use depends on your needs. The main thing to be aware of is that the linq