如何排序列表按字节顺序为AWS-电话 [英] How to sort a list by byte-order for AWS-Calls
问题描述
在看看的http://联营公司 - 亚马逊。 s3.amazonaws.com/signed-requests/helper/index.html
下面的名称 - 值对:
服务= AWSECommerceService
版本= 2011-08-01
AssociateTag = PutYourAssociateTagHere
操作= ItemSearch
SearchIndex =图书
关键词=哈利·波特+
时间戳= 2015-09-26T14:10:56.000Z
AWSAccessKeyId = 123
的名称 - 值对已按字节顺序进行排序
应导致
AWSAccessKeyId = 123
AssociateTag = PutYourAssociateTagHere
关键词=哈里%20potter
操作= ItemSearch
SearchIndex =图书
服务= AWSECommerceService
时间戳= 2015-09-26T14%3A10%3A56.000Z
版本= 2011-08-01
如何实现这一目标在研发?
据我可以告诉他们被排序的
as.numeric(charToRaw(名称))
值。如果第一个值等于然后它们通过第二个分选,然后在第三等
问:如何做到这一点在研发
#名称 - 值对
NVP< - 列表(
服务=AWSECommerceService
版本=2011-08-01,
AssociateTag=PutYourAssociateTagHere,
运行=ItemSearch
SearchIndex=书,
关键词=哈利·波特,
时间戳=2015-09-26T14:10:56.000Z
AWSAccessKeyId=123
)
获取字节:
字节< - 功能(CHR){
as.data.frame(T(as.numeric(charToRaw(CHR))))
}
字节计算,和rbind值
B< - lapply(名称(NVP),字节)
B< - data.table :: rbindlist(B,补= TRUE)#比基地等:: rbind,这填补了NA
ORDER BY第一列的名称,然后通过第二,第三方,...等等
名称(NVP)[do.call(订单,as.list(B))]
[1]AWSAccessKeyIdAssociateTag,关键词操作SearchIndex
[6]服务时间戳,版本
所以最后 NVP [do.call(订单,as.list(B))]
的正确排序列表返回
Having a look at http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html
The following Name-Value Pairs:
Service=AWSECommerceService
Version=2011-08-01
AssociateTag=PutYourAssociateTagHere
Operation=ItemSearch
SearchIndex=Books
Keywords=harry+potter
Timestamp=2015-09-26T14:10:56.000Z
AWSAccessKeyId=123
The name-value pairs have been sorted according to byte-order
Should result in
AWSAccessKeyId=123
AssociateTag=PutYourAssociateTagHere
Keywords=harry%20potter
Operation=ItemSearch
SearchIndex=Books
Service=AWSECommerceService
Timestamp=2015-09-26T14%3A10%3A56.000Z
Version=2011-08-01
How to achieve this in R?
As far as i can tell they are sorted by their
as.numeric(charToRaw(name))
values. If the first value is equal then they are sorted by the second one, then the third and so on.
Question: How to do this in R?
# Name-Value-Pairs
nvp <- list(
"Service"="AWSECommerceService",
"Version"="2011-08-01",
"AssociateTag"="PutYourAssociateTagHere",
"Operation"="ItemSearch",
"SearchIndex"="Books",
"Keywords"="harry potter",
"Timestamp"="2015-09-26T14:10:56.000Z",
"AWSAccessKeyId"="123"
)
Get Bytes:
bytes <- function(chr){
as.data.frame(t(as.numeric(charToRaw(chr))))
}
Calculate Bytes, and rbind the values
b <- lapply(names(nvp), bytes)
b <- data.table::rbindlist(b, fill=TRUE) # other than base::rbind, this fills by NA
Order the names by first column, then by second, by third, ... and so on
names(nvp)[do.call(order, as.list(b))]
[1] "AWSAccessKeyId" "AssociateTag" "Keywords" "Operation" "SearchIndex"
[6] "Service" "Timestamp" "Version"
So finally nvp[do.call(order, as.list(b))]
returns in the properly sorted list
这篇关于如何排序列表按字节顺序为AWS-电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!