简体   繁体   中英

Shift one position behind in a raw conversion from a hex buffer

I've been trying to extract a table from a blob column in a database that was converted into a hex string in the process. I'm using R for all my job. A capture of the BLOB data column is highlighted below:

DATA column is a hex string coming from a BLOB column in a database

在此处输入图像描述

The problem is that the data when inspected in raw form is shifted one position ahead, completely modifying the conversion to my numeric arrays when I make the final conversion. A capture of the problem is highlighted below:

The first chunk is the right data, the second chunk is the data shifted one position ahead

在此处输入图像描述

My question is, how do I move the data one position behind?

Is there any package in R or Python capable of doing that shift?

I've been trying with hex2raw function from wkb package without success. Same with decode functions in Python.

In R, You can "shift" you data numerically

data <- as.raw(sample(256,10) - 1)
data2 <- as.raw((as.integer(data) * 16L) %% 256L + ( c(data[-1], 0L) %/% 16L)  )


data
#>  [1] 89 af 4f 94 66 e8 84 c1 93 01
data2
#>  [1] 9a f4 f9 46 6e 88 4c 19 30 10

EDIT

Other way:

data3 <- as.raw(
  as.integer(rawShift(data, 4)) + 
  as.integer(rawShift(c(data[-1],as.raw(0)), -4)))


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM