unpack

Maven custom archive extension - how do I use unpack-dependencies?

随声附和 提交于 2019-12-10 14:26:12
问题 I have a custom artfiact type web-module ; just a ZIP but with a custom extension. I then have a project depending on it, I want its dependencies of this custom type to be unpacked. The maven-dependency-plugin unpack-dependencies goal seemed to fit the bill, however I keep getting the error: [INFO] Unknown archiver type Embedded error: No such archiver: 'web-module'. [INFO] ------------------------------------------------------------------------ [INFO] Trace org.apache.maven.lifecycle

Can I use unpack to split a string into characters in Perl?

烈酒焚心 提交于 2019-12-10 13:27:37
问题 A common 'Perlism' is generating a list as something to loop over in this form: for($str=~/./g) { print "the next character from \"$str\"=$_\n"; } In this case the global match regex returns a list that is one character in turn from the string $str , and assigns that value to $_ Instead of a regex, split can be used in the same way or 'a'..'z' , map , etc. I am investigating unpack to generate a field by field interpretation of a string. I have always found unpack to be less straightforward

python: unpacking a string to a list

别来无恙 提交于 2019-12-10 11:47:40
问题 The answer to a question on multiple-value elements in a config file (which exactly fits my needs) suggests to "unpack the string from the config". I read the doc for unpacking arguments lists suggested in several places but I fail to understand how this relates to my problem. I am sure this must be obvious: having a string str = "123,456" , how can I transform it into the list [123,456] (the number of elements separated by a comma in the string may vary) Thank you. 回答1: Do you want a list of

simple reading of fortran binary data not so simple in python

て烟熏妆下的殇ゞ 提交于 2019-12-10 10:28:01
问题 I have a binary output file from a FORTRAN code. Want to read it in python. (Reading with FORTRAN and outputting text to read for python is not an option. Long story.) I can read the first record in a simplistic manner: >>> binfile=open('myfile','rb') >>> pad1=struct.unpack('i',binfile.read(4))[0] >>> ver=struct.unpack('d',binfile.read(8))[0] >>> pad2=struct.unpack('i',binfile.read(4))[0] >>> pad1,ver,pad2 (8,3.13,8) Just fine. But this is a big file and I need to do this more efficiently. So

Python custom mapping class **unpacking and 'keys' attribute

老子叫甜甜 提交于 2019-12-10 09:20:56
问题 I'd like to use a SimpleNameSpace which can also act as a mapping so to be able to be used with ** unpacking. Here is what I've done: class MySimpleNameSpace(object): # my initial attempt subclassed SimpleNameSpace and Mapping, with # possibility to use MySimpleNameSpace as a dict as well as a normal SimpleNameSpace. def __init__(self, **kw): self.__dict__.update(kw) def __getitem__(self, item): return getattr(self, item) def keys(self): return self.__dict__.keys() So far so good: def f(**kw)

Why is hex -> base64 so different from base64 -> hex using pack and unpack?

时间秒杀一切 提交于 2019-12-09 17:17:30
问题 I got this code working, which converts from hex to base64, and vice versa. I got to_base64 from another SO question, and I wrote to_hex with some guesswork and trial and error. class String def to_base64 [[self].pack("H*")].pack("m0") end def to_hex self.unpack("m0").first.unpack("H*").first end end But I don't really grok the pack and unpack methods, even after reading the docs. Specifically, I'm confused by the asymmetry between the two implementations. Conceptually, in both cases, we take

How do I unpack a number larger than 64 bits in ruby?

你。 提交于 2019-12-07 21:36:53
问题 Let's say I have an arbitrary string that's ~1000 bytes long. (I'm studying crypto.) How can I unpack that into a BigNum? I understand how to pack it into 8-bit numbers, say, or 32-bit numbers. s='I am a grumpy potato' s.unpack('C*') [73, 32, 97, 109, 32, 97, 32, 103, 114, 117, 109, 112, 121, 32, 112, 111, 116, 97, 116, 111] s.upack('L*') => [1835081801, 1730175264, 1886221682, 1869619321, 1869898100] Or, is there a straightforward way to combine, say, the 8-bit numbers into a BigNum? I could

PHP: pack/unpack补遗

江枫思渺然 提交于 2019-12-07 20:47:31
pack/unpack的介绍和使用加上这篇就第三篇了。确实知识点比较多,这篇算是收尾之作吧。仔细去文档上看pack/unpack的格式化字符说明,就会发现s, S, i, I, l, L, f, d都没有对应的大端序和小端序的格式化字符,所以有需要的时候必须自己实现。这个真不知道PHP开发项目组是怎么想的! 而且确实有人在 ‍ ‍ stackoverflow ‍ ‍ 上这么问了,详见: php-pack-format-for-signed-32-int-big-endian 。stackoverflow上的答案比较巧妙,所以我在这里进行借鉴。 L表示无符号长整型,按主机字节序。N表示无符号长整型,大端序。它们都是32位的,所以如果用L和N对同一个整数进行打包,如果结果相等,则本机字节序就是大端序,否则就是小端序。代码如下: <?php define('BIG_ENDIAN', pack('L', 1) === pack('N', 1)); if (BIG_ENDIAN) { echo "大端序"; } else { echo "小端序"; } echo "\n"; $ php -f test.php 小端序 大端序和小端序事实上是相反的字节序,比如要实现无符号短整型的大端序和小端序,可以用s格式化字符先进行打包,再判断大小端来决定是否需要反转字符串,代码如下: <?php

PHP: chr和pack、unpack那些事

眉间皱痕 提交于 2019-12-07 20:47:17
PHP是一门很灵活的语言。正因为它太灵活了,甚至有些怪异,所以大家对它的评价褒贬不一。其实我想说的是,任何一门语言都有它自身的哲学,有它存在的出发点。PHP为Web而生,它以快速上手、快速开发而著称,所以它也常被冠以简单、新手用的语言等标签。我倒不这么认为,所谓选对的工具去做对的事,没有包打天下的语言。而至于说其简单,却也未必。 引子 我之前有篇文详细介绍过pack和unpack: PHP: 深入pack/unpack ,如果有不明白的地方,建议再回过头去看多几遍。现在应该能够写出以下代码: <?php echo pack("C", 97) . "\n"; $ php -f test.php a 但是,为什么会输出'a'呢?虽然我们知道字符'a'的ASCII码就是97,但是pack方法返回的是二进制字符串,为什么不是输出一段二进制而是'a'?为了确认pack方法返回的是一段二进制字符串,这里我对官方的pack的描述截了个图: 确实如此,pack返回包含二进制字符串的数据,接下来详细进行分析。 程序是如何显示字符的 这里所说的'程序',其实是个宏观的概念。 对于在控制台中执行脚本(这里是指PHP作为cli脚本来执行),脚本的输出会写入标准输出(stdin)或标准错误(stderr),当然也有可能会重定向到某个文件描述符。拿标准输出来说,暂且忽略它是行缓冲、全缓冲或者是无缓冲

How to unpack (64-bit) unsigned long in 64-bit Perl?

前提是你 提交于 2019-12-07 15:22:18
问题 I'm trying to unpack an unsigned long value that is passed from a C program to a Perl script via SysV::IPC. It is known that the value is correct (I made a test which sends the same value into two queues, one read by Perl and the second by the C application), and all predecessing values are read correctly (used q instead of i! to work with 64-bit integers). It is also known that PHP had something similar in bugs (search for "unsigned long on 64 bit machines") (seems to be similar: Pack /