~bigbes/tarantool

tarantool-protobuf

ref: 78d234c122d158e32b053dd179a92b12e1b06834 tarantool-protobuf/cmd/conformance-runner.lua -rw-r--r-- 1.6 KiB
78d234c1 — Eugene Blikh runtime: pb.from_pb — build modules from a binary FileDescriptorSet 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env tarantool
--
-- protoc-gen-tarantool / pb runtime conformance test runner.
--
-- Speaks the Google protobuf conformance protocol on stdin/stdout: each
-- request and response is a little-endian uint32 length followed by a
-- `conformance.ConformanceRequest` / `conformance.ConformanceResponse`
-- serialized as protobuf. Loops until EOF.
--
-- Run against the canonical Google conformance binary like so:
--
--     conformance_test_runner --enforce_recommended \
--         tarantool cmd/conformance-runner.lua
--
-- LUA_PATH must let this script find `pb`, the generated modules, and
-- the conformance core module under `cmd/`:
--
--     LUA_PATH="./runtime/?/init.lua;./runtime/?.lua;\
--               ./examples/expected/?.lua;./examples/expected/?/init.lua;\
--               ./cmd/?.lua;;"

local core = require('cmd.conformance.core')

local function read_n(n)
    local got = io.stdin:read(n)
    if got == nil or #got < n then return nil end
    return got
end

local function read_request_bytes()
    local hdr = read_n(4)
    if hdr == nil then return nil end
    local b1, b2, b3, b4 = hdr:byte(1, 4)
    return read_n(b1 + b2 * 256 + b3 * 65536 + b4 * 16777216)
end

local function write_response_bytes(payload)
    local n = #payload
    io.stdout:write(string.char(
        n % 256,
        math.floor(n / 256) % 256,
        math.floor(n / 65536) % 256,
        math.floor(n / 16777216) % 256))
    io.stdout:write(payload)
    io.stdout:flush()
end

while true do
    local req_bytes = read_request_bytes()
    if req_bytes == nil then break end
    write_response_bytes(core.handle_request(req_bytes))
end

os.exit(0)