Skip to content

Commit 9789780

Browse files
committed
Fix bf_decode flag processing and sign handling
- Simplify flag metadata extraction: calculate length directly from assignPosition - Remove redundant grouping/summarization that was causing issues - Add row_number for proper flag ordering - Fix separator positions: use pos + length instead of just split - Add missing sign multiplication for floating-point decode (line 108) These changes fix decoding issues when flags have multiple values.
1 parent f695eb0 commit 9789780

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

R/bf_decode.R

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,13 @@ bf_decode <- function(x, registry, flags = NULL, sep = NULL, verbose = TRUE){
5353
# get the bits ...
5454
theBits <- map(.x = seq_along(registry@flags), .f = function(ix){
5555
tibble(pos = registry@flags[[ix]]$wasGeneratedBy$assignPosition[1],
56+
length = registry@flags[[ix]]$wasGeneratedBy$assignPosition[2] - registry@flags[[ix]]$wasGeneratedBy$assignPosition[1],
5657
name = names(registry@flags)[ix],
57-
flags = length(registry@flags[[ix]]$wasGeneratedBy$extractLevels$id),
58-
bits = length(registry@flags[[ix]]$wasGeneratedBy$assignPosition),
5958
desc = paste0(registry@flags[[ix]]$comment, collapse = " | "))
6059
}) |>
6160
bind_rows() |>
62-
arrange(pos)
63-
64-
# ... and the positions where they should be split
65-
theBits <- theBits |>
66-
group_by(name) |>
67-
summarise(split = max(pos),
68-
pos = if_else(n() == 1, as.character(split), paste0(min(pos), ":", max(pos))),
69-
desc = first(desc)) |>
70-
arrange(split)
61+
arrange(pos) |>
62+
mutate(rn = row_number())
7163

7264
# create look-up table for what the bits stand for
7365
lut <- separate_longer_delim(data = theBits, cols = desc, delim = " | ") |>
@@ -80,7 +72,7 @@ bf_decode <- function(x, registry, flags = NULL, sep = NULL, verbose = TRUE){
8072
}
8173
tempOut <- tempBits |>
8274
unite(col = "bin", 1:ncol(tempBits), sep = "") |>
83-
separate(col = bin, into = paste0("flag", theBits$split), sep = theBits$split)
75+
separate(col = bin, into = paste0("flag", theBits$rn), sep = c(theBits$pos + theBits$length))
8476

8577
if(!is.null(flags)){
8678
assertSubset(x = flags, choices = names(registry@flags))
@@ -113,14 +105,14 @@ bf_decode <- function(x, registry, flags = NULL, sep = NULL, verbose = TRUE){
113105
paste0("1", flagSplit[[ix]][3])
114106
})
115107

116-
temp <- .toDec(x = str_replace(significand, pattern = paste0("^(.{", exponent + 1, "})(.*)$"), replacement = "\\1.\\2"))
108+
temp <- sign * .toDec(x = str_replace(significand, pattern = paste0("^(.{", exponent + 1, "})(.*)$"), replacement = "\\1.\\2"))
117109
}
118110

119111
env_bind(.env = .GlobalEnv, !!flagName := temp)
120112
}
121113

122114
if(!is.null(sep)){
123-
out <- unite(tempOut, col = "bf_bin", paste0("flag", theBits$split), sep = sep)
115+
out <- unite(tempOut, col = "bf_bin", paste0("flag", theBits$rn), sep = sep)
124116
} else {
125117
colnames(tempOut) <- theFlags
126118
out <- tempOut

0 commit comments

Comments
 (0)