buffer

Node Buffers, from utf8 to binary

谁都会走 提交于 2020-01-09 10:10:10
问题 I'm receiving data as utf8 from a source and this data was originally in binary form (it was a Buffer ). I have to convert back this data to a Buffer . I'm having a hard time figuring how to do this. Here's a small sample that shows my problem: var hexString = 'e61b08020304e61c09020304e61d0a020304e61e65'; var buffer1 = new Buffer(hexString, 'hex'); var str = buffer1.toString('utf8'); var buffer2 = new Buffer(str, 'utf8'); console.log('original content:', hexString); console.log('buffer1

Writing a full buffer using write() system call

守給你的承諾、 提交于 2020-01-09 07:51:10
问题 I want to write a buffer filled with BUFF_SIZE bytes over a TCP socket using the write system call: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); The documentation states that write() writes up to count bytes from the buffer pointed buf to the file referred to by the file descriptor fd. Of course, the number of actual bytes written can be detected by the return value. However, if I want to ensure that my whole buffer of bytes gets sent over the connection, what

GNU buffer overflow using malloc

这一生的挚爱 提交于 2020-01-07 09:54:17
问题 I am running in a loop the following function: int* rpermute(int n) { int* a = malloc(n * sizeof(int)); int k; for (k = 0; k < n; k++) { a[k] = k; } for (k = n - 1; k > 0; k--) { int j = rand() % (k + 1); int temp = a[j]; a[j] = a[k]; a[k] = temp; } return a; } If I set a new int variable in my code every variable is changing, I assume it is a buffer overflow problem. Running the valgrind i get the following: ==4459== 73,036 bytes in 19 blocks are definitely lost in loss record 1 of 1 ==4459=

利用FFmpeg和管道(pipe),解决非URL和非文件的输入形式

故事扮演 提交于 2020-01-07 08:30:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 利用FFmpeg和管道(pipe),解决非URL和非文件的输入形式 问题描述:利用FFmpeg来解码,但是输入方式不是URL,也不是文件系统中的文件,而是内存中的buffer。 解决此问题有两个思路,首先明确一点,libavformat中有几个类,有URLProtocol(虽然叫URLxxx,但是不仅仅是URL的,它可是掌管了所有的输入方式),AVOutputFormat(有muxer也有demuxer),AVInputFormat(有muxer也有demuxer)。 它们对应实例可以举几个例子: URLProtocol::ff_pipe_protocol、ff_http_protocol、ff_file_protocol。。。 AVOutputFormat:ff_mpegts_demuxer、ff_mp3_demuxer。。。 AVInputFormat:ff_mpegts_demuxer、ff_mp3_demuxer。。。 然后来说int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);函数,它的filename参数只接受URL或者文件名

Google Protocol Buffer 的各语言实现版本

十年热恋 提交于 2020-01-07 07:15:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Google Protocol Buffer 专门用来串行化和反串行化对象,但官方仅实现了C++、Python、Java三种语言。其他语言版本也相继由不同的作者来实现。虽然有一定缺陷,也足以在大部分的项目中使用了。 .proto 的基本写法: package feeds; message Feed { optional string title = 1; message Entry { optional string title = 1; } repeated Entry entry = 2; } Python、C++、Java三种语言版本请见 https://developers.google.com/protocol-buffers/docs/reference/overview 代码生成: <?php require_once('../parser/pb_parser.php'); $test = new PBParser(); $test->parse('./feeds.proto'); ?> 串行化: <?php require_once('message/pb_message.php'); require_once('pb_proto_test.php'); $feed = new Feed();

Setting socket buffer size in Apache HttpClient

我们两清 提交于 2020-01-07 02:33:07
问题 How do you set the socket buffer size in Apache HttpClient version 4.3.3? 回答1: HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 128 * 1024); HttpPost post = new HttpPost(url); String res = null; try { post.addHeader("Connection", "Keep-Alive"); post.addHeader("Content-Name", selectedFile.getName()); post.setEntity(new ByteArrayEntity(fileBytes)); HttpResponse response = client.execute(post); res = EntityUtils.toString

ITK Importing Image Data from a Buffer

拈花ヽ惹草 提交于 2020-01-06 18:12:34
问题 I have coded a method to create an Itk image from a buffer (in my case it's a Cimg image type). This is the algorithme : void Cimg_To_ITK (CImg<uchar> img) { const unsigned int Dimension = 2; typedef itk::RGBPixel< unsigned char > RGBPixelType; typedef itk::Image< RGBPixelType, Dimension > RGBImageType; typedef itk::ImportImageFilter< RGBPixelType, Dimension > ImportFilterType; ImportFilterType::Pointer importFilter = ImportFilterType::New(); typedef itk::ImageFileWriter< RGBImageType >

ITK Importing Image Data from a Buffer

感情迁移 提交于 2020-01-06 18:12:27
问题 I have coded a method to create an Itk image from a buffer (in my case it's a Cimg image type). This is the algorithme : void Cimg_To_ITK (CImg<uchar> img) { const unsigned int Dimension = 2; typedef itk::RGBPixel< unsigned char > RGBPixelType; typedef itk::Image< RGBPixelType, Dimension > RGBImageType; typedef itk::ImportImageFilter< RGBPixelType, Dimension > ImportFilterType; ImportFilterType::Pointer importFilter = ImportFilterType::New(); typedef itk::ImageFileWriter< RGBImageType >

C read stdin buffer before it is submit

那年仲夏 提交于 2020-01-06 14:11:58
问题 It is likely that this type of scenario is not possible as I have not found this behavior documented anywhere but was curious if anyone had any tricks to accomplish something like this. Is it possible to determine the contents of the stdin buffer for a program before the user actually hits enter to submit the data? I am attempting to do this as I have built a simple terminal chat program which sends messages from one terminal to another for easy communication. The issue we have run into is

using GetFrontBufferData(), & place screenshot in separate device backbuffer

懵懂的女人 提交于 2020-01-06 09:02:53
问题 Ok, so for anyone who's used it much - this should be a SUPER easy question. I was just searching online for a way to use DirectX/Direct3D to take faster screenshots, and everyone was talking about GetFrontBufferData() and how wonderful it was. I've pounded at it for a while but am starting to think they're using the term "screenshot" incorrectly... My call succeeds, but I never get a "screenshot". So the question is , can you actually use GetFrontBufferData() to make a REAL screenshot of the