add hex helpers for LSSE
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user