Skip to content

Commit

Permalink
Merge pull request #6 from balena-os/byte-array
Browse files Browse the repository at this point in the history
Add support for byte arrrays
  • Loading branch information
flowzone-app[bot] authored Sep 20, 2023
2 parents a190c49 + 7e08174 commit 355cdfe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 29 additions & 1 deletion format.jq
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,38 @@ def fmt_unit($entry):
+"]"
;

# Convert a byte array into a string
# Source: https://stackoverflow.com/a/48431552

def btostring:
[foreach .[] as $item (
[0, 0]
;
if .[0] > 0 then [.[0] - 1, .[1] * 64 + ($item % 64)]
elif $item >= 240 then [3, $item % 8]
elif $item >= 224 then [2, $item % 16]
elif $item >= 192 then [1, $item % 32]
elif $item < 128 then [0, $item]
else error("Malformed UTF-8 bytes")
end
;
if .[0] == 0 then .[1] else empty end
)] | implode
;


def fmt_message($msg):
if $msg | type == "array" then
$msg | btostring
else
$msg
end
;

# Select fields from the journalctl output and tranform to
# a human readable format
def fmt_entry($entry):
[fmt_date($entry.__REALTIME_TIMESTAMP), fmt_unit($entry), .MESSAGE] | join(" ")
[fmt_date($entry.__REALTIME_TIMESTAMP), fmt_unit($entry), fmt_message(.MESSAGE)] | join(" ")
;

# Process the entry
Expand Down
1 change: 1 addition & 0 deletions repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type: docker

0 comments on commit 355cdfe

Please sign in to comment.