add hex helpers for LSSE

This commit is contained in:
2023-01-30 01:27:31 +00:00
parent 63a1e6c46d
commit 2cd4cb4403

View File

@@ -1,12 +1,24 @@
class LogStoreSstEntry < ReduxApplicationRecord
def key_hex
self.hex2bin(self.key)
# columns:
# key - bytea
# value - bytea
def hex_key
self.class.bin2hex(self.key)
end
def hex_value
self.class.bin2hex(self.value)
end
def self.find_by_hex_key(key_hex)
self.find_by(key: self.hex2bin(key_hex))
end
def self.hex2bin(str)
[str].pack("H*")
end
def self.bin2hex(bin)
bin.unpack("H*").first
bin.unpack("H*").first.upcase
end
end