Questions tagged [pack]

A function in several scripting languages for packing data, creating a sequence of specifically ordered and aligned bytes, into a binary structure. The opposite of the `unpack` function. This tag should be used with a programming language tag as well. While also used as a directive or pragma in some compilers to cause the compiler to ignore standard variable alignment for data aggregates (i.e. struct), do not use this tag for posts on that subject.

The pack function combines several high-level variables into a single low-level binary representation that usually matches the machine-level representation that you would see in a C struct. The inverse operation is .

Most versions of pack and unpack functions use a format or template that specifies the byte by byte layout of the data being put into or copied out of the memory area containing the binary representation.

Documentation:

682 questions
5
votes
1 answer

NPM Pack including .DS_Store

According to the docs https://docs.npmjs.com/files/package.json#files, if you put a directory in the files section of package.json, certain files inside the specified directory will be excluded no matter what - including .DS_Store. Additionally,…
iceblueorbitz
  • 920
  • 1
  • 7
  • 17
5
votes
3 answers

Git for Windows - prevent .pack file date/time modification

I am using Git for Windows (version 2.15, but the same issue occurs in 2.14 and I think older versions as well) and I noticed a rather annoying behavior: When I perform some basic git operations*), the modification date of the…
pepak
  • 712
  • 4
  • 13
5
votes
1 answer

Why does this decrease the audio quality?

I am streaming audio in my flask app from a client to the server, but the received audio has very low quality. On the client, I preprocess the audio buffer as follows: this.node.onaudioprocess = function(e){ var buf =…
user2212461
  • 3,105
  • 8
  • 49
  • 87
5
votes
3 answers

How to return a template pack nested in other pack?

The following code works: #include #include struct Base {}; struct A : Base {}; struct B : Base {}; struct C : Base {}; struct D : Base {}; struct E : Base {}; struct F : Base {}; template struct…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
5
votes
5 answers

Python: How to transfer varrying length arrays over a network connection

I need to transfer an array of varying length in which each element is a tuple of two integers. As an example: path = [(1,1),(1,2)] path = [(1,1),(1,2),(2,2)] I am trying to use pack and unpack, however, since the array is of varying length I…
Devin
  • 81
  • 2
  • 9
5
votes
2 answers

Is pack('i',1) always 4 bytes?

On my machine PHP_INT_SIZE is 8 but pack('i',1) returns a 4 byte string anyway. The docs say i is a "signed integer (machine dependent size and byte order)" but that doesn't appear to be true. Is it fixed at 4 bytes? This means that…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
5
votes
4 answers

Packing bools with bit field (C++)

I'm trying to interface with Ada code using C++, so I'm defining a struct using bit fields, so that all the data is in the same place in both languages. The following is not precisely what I'm doing, but outlines the problem. The following is also a…
Keith M
  • 853
  • 10
  • 28
5
votes
1 answer

Perl pack()ing a message?

Background I have a device connected to my machine on a serial port that is message oriented, where each incoming command message is exactly eight 16-bit words. The most significant byte of each word is received first and the least significant byte…
rem45acp
  • 469
  • 5
  • 16
5
votes
4 answers

c++ Unpacking parameter pack from template arguments

How to achieve want I want below? The paramater pack I want to unpack is not in a function argument list but template argument list. #include #include const std::size_t SIZE = 10; template std::array
prestokeys
  • 4,817
  • 3
  • 20
  • 43
5
votes
2 answers

How do I convert Perl's pack 'Nc*' format to struct.pack for Python?

I'm trying to convert a Perl script to python, and it uses quite a few different packs. I've been able to figure out the lettering differences in the "templates" for each one, but I'm having an issue with understanding how to handle Perl's lack of…
Valdemarick
  • 247
  • 2
  • 4
  • 10
5
votes
1 answer

How does pack() and unpack() work in Ruby

In Ruby why we need array Packing? How does directive help to do such packing? I ran some code in my console to see what and how directives looks like in Array packing.But the output is closely same with each directives. Then in core how they…
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
5
votes
2 answers

python struct pack with space padding

I need to create/send binary data in python using a given protocol. The protocol calls for fixed width fields , with space padding thrown in. Using python's struct.pack, the only thing I can think of is, calculating the space padding and adding it…
Pradyot
  • 2,897
  • 7
  • 41
  • 58
5
votes
1 answer

compute CRC of struct in Python

I have the following struct, from the NRPE daemon code in C: typedef struct packet_struct { int16_t packet_version; int16_t packet_type; uint32_t crc32_value; int16_t result_code; char buffer[1024]; } packet; I want to send this data…
verideskstar
  • 183
  • 2
  • 8
4
votes
3 answers

pack/unpack functions for C++

NOTE: I know that this has been asked many times before, but none of the questions have had a link to a concrete, portable, maintained library for this. I need a C or C++ library that implements Python/Ruby/Perl like pack/unpack functions. Does such…
Linuxios
  • 34,849
  • 13
  • 91
  • 116
4
votes
3 answers

Converting grouped hex characters into a bitstring in Perl

I have some 256-character strings of hexadecimal characters which represent a sequence of bit flags, and I'm trying to convert them back into a bitstring so I can manipulate them with &, |, vec and the like. The hex strings are written in…
wisnij
  • 317
  • 1
  • 3
  • 9