Skip to content

Commit a57f7c4

Browse files
committed
msgpack.lua
1 parent 0a6b63e commit a57f7c4

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = false
6+
charset = utf-8
7+
indent_style = tab

.luarc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"diagnostics": {
3+
"disable": ["lowercase-global"],
4+
"globals": ["peerdb"]
5+
}
6+
}
7+

msgpack.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
local msgpack = require 'msgpack'
2+
3+
local function RowToMap(row)
4+
local cols = peerdb.RowColumns(row)
5+
local map = {}
6+
for _, col in ipairs(cols) do
7+
local kind = peerdb.RowColumnKind(row, col)
8+
if string.sub(kind, 1, #'array_') == 'array_' then
9+
map[col] = msgpack.array(row[col])
10+
elseif kind == 'numeric' then
11+
local dec = row[col]
12+
map[col] = msgpack.ext(10, msgpack.encode(dec.exponent) .. dec.coefficient.bytes)
13+
elseif kind == 'bytes' or kind == 'bit' then
14+
map[col] = msgpack.bin(row[col])
15+
else
16+
map[col] = row[col]
17+
end
18+
end
19+
return map
20+
end
21+
22+
local RKINDMAP = {
23+
insert = string.byte('i', 1),
24+
update = string.byte('u', 1),
25+
delete = string.byte('d', 1),
26+
}
27+
28+
function onRecord(r)
29+
local kind = RKINDMAP[r.kind]
30+
if not kind then
31+
return
32+
end
33+
local record = {
34+
action = r.kind,
35+
lsn = r.checkpoint,
36+
time = r.commit_time,
37+
source = r.source,
38+
}
39+
if r.old then
40+
record.old = RowToMap(r.old)
41+
end
42+
if r.new then
43+
record.new = RowToMap(r.new)
44+
end
45+
return msgpack.encode(record)
46+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy