~bigbes/tarantool

tarantool-protobuf

ref: 8c1e6078b7b32825347c6e551e8ccff4e8c34e2e tarantool-protobuf/runtime/pb/descriptor_pb.lua -rw-r--r-- 6.0 KiB
8c1e6078 — Eugene Blikh c_runtime: map<K,V> encode + decode dispatch (ra6 3h) 2 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
-- Hand-built descriptors for the subset of google.protobuf.descriptor needed
-- to decode FileDescriptorSet wire bytes back into AST form. Used by
-- pb.from_pb (see runtime/pb/fileset.lua).
--
-- We model FieldDescriptorProto.type and .label as int32 scalars instead of
-- enums; the codec returns the wire integer either way and the translator
-- maps it to a proto3 type-name string by hand.
local codec = require('pb.codec')

local M = {}

local function finalize(desc)
    local fbi, fbn = {}, {}
    for _, f in ipairs(desc.fields) do
        fbi[f.id] = f
        fbn[f.name] = f
    end
    desc.field_by_id = fbi
    desc.field_by_name = fbn
    codec.compile_writers(desc)
    codec.compile_readers(desc)
    return desc
end

-- FieldOptions: subset.
M.FieldOptions = {
    name = 'google.protobuf.FieldOptions',
    fields = {
        {name = 'packed', id = 2, kind = 'scalar', proto_type = 'bool'},
    },
}

-- MessageOptions: subset.
M.MessageOptions = {
    name = 'google.protobuf.MessageOptions',
    fields = {
        {name = 'map_entry', id = 7, kind = 'scalar', proto_type = 'bool'},
    },
}

-- FieldDescriptorProto.
M.FieldDescriptorProto = {
    name = 'google.protobuf.FieldDescriptorProto',
    fields = {
        {name = 'name',            id = 1,  kind = 'scalar',  proto_type = 'string'},
        {name = 'extendee',        id = 2,  kind = 'scalar',  proto_type = 'string'},
        {name = 'number',          id = 3,  kind = 'scalar',  proto_type = 'int32'},
        {name = 'label',           id = 4,  kind = 'scalar',  proto_type = 'int32'},
        {name = 'type',            id = 5,  kind = 'scalar',  proto_type = 'int32'},
        {name = 'type_name',       id = 6,  kind = 'scalar',  proto_type = 'string'},
        {name = 'default_value',   id = 7,  kind = 'scalar',  proto_type = 'string'},
        {name = 'options',         id = 8,  kind = 'message', message = M.FieldOptions},
        {name = 'oneof_index',     id = 9,  kind = 'scalar',  proto_type = 'int32'},
        {name = 'json_name',       id = 10, kind = 'scalar',  proto_type = 'string'},
        {name = 'proto3_optional', id = 17, kind = 'scalar',  proto_type = 'bool'},
    },
}

M.OneofDescriptorProto = {
    name = 'google.protobuf.OneofDescriptorProto',
    fields = {
        {name = 'name', id = 1, kind = 'scalar', proto_type = 'string'},
    },
}

M.EnumValueDescriptorProto = {
    name = 'google.protobuf.EnumValueDescriptorProto',
    fields = {
        {name = 'name',   id = 1, kind = 'scalar', proto_type = 'string'},
        {name = 'number', id = 2, kind = 'scalar', proto_type = 'int32'},
    },
}

M.EnumDescriptorProto = {
    name = 'google.protobuf.EnumDescriptorProto',
    fields = {
        {name = 'name',  id = 1, kind = 'scalar', proto_type = 'string'},
        {name = 'value', id = 2, kind = 'message',
         message = M.EnumValueDescriptorProto, repeated = true},
    },
}

M.MethodDescriptorProto = {
    name = 'google.protobuf.MethodDescriptorProto',
    fields = {
        {name = 'name',             id = 1, kind = 'scalar', proto_type = 'string'},
        {name = 'input_type',       id = 2, kind = 'scalar', proto_type = 'string'},
        {name = 'output_type',      id = 3, kind = 'scalar', proto_type = 'string'},
        {name = 'client_streaming', id = 5, kind = 'scalar', proto_type = 'bool'},
        {name = 'server_streaming', id = 6, kind = 'scalar', proto_type = 'bool'},
    },
}

M.ServiceDescriptorProto = {
    name = 'google.protobuf.ServiceDescriptorProto',
    fields = {
        {name = 'name',   id = 1, kind = 'scalar', proto_type = 'string'},
        {name = 'method', id = 2, kind = 'message',
         message = M.MethodDescriptorProto, repeated = true},
    },
}

-- DescriptorProto recurses through nested_type. We pre-declare the table,
-- then patch in the recursive reference.
M.DescriptorProto = {name = 'google.protobuf.DescriptorProto'}
M.DescriptorProto.fields = {
    {name = 'name',        id = 1, kind = 'scalar',  proto_type = 'string'},
    {name = 'field',       id = 2, kind = 'message', message = M.FieldDescriptorProto, repeated = true},
    {name = 'nested_type', id = 3, kind = 'message', message = M.DescriptorProto,       repeated = true},
    {name = 'enum_type',   id = 4, kind = 'message', message = M.EnumDescriptorProto,   repeated = true},
    {name = 'options',     id = 7, kind = 'message', message = M.MessageOptions},
    {name = 'oneof_decl',  id = 8, kind = 'message', message = M.OneofDescriptorProto,  repeated = true},
}

M.FileDescriptorProto = {
    name = 'google.protobuf.FileDescriptorProto',
    fields = {
        {name = 'name',         id = 1,  kind = 'scalar',  proto_type = 'string'},
        {name = 'package',      id = 2,  kind = 'scalar',  proto_type = 'string'},
        {name = 'dependency',   id = 3,  kind = 'scalar',  proto_type = 'string', repeated = true, packed = false},
        {name = 'message_type', id = 4,  kind = 'message', message = M.DescriptorProto,        repeated = true},
        {name = 'enum_type',    id = 5,  kind = 'message', message = M.EnumDescriptorProto,    repeated = true},
        {name = 'service',      id = 6,  kind = 'message', message = M.ServiceDescriptorProto, repeated = true},
        {name = 'syntax',       id = 12, kind = 'scalar',  proto_type = 'string'},
    },
}

M.FileDescriptorSet = {
    name = 'google.protobuf.FileDescriptorSet',
    fields = {
        {name = 'file', id = 1, kind = 'message',
         message = M.FileDescriptorProto, repeated = true},
    },
}

-- Finalize bottom-up. Order matters only in that we should finalize a
-- descriptor before any descriptor that references it as a message field;
-- the codec's compile_readers walks field.message at compile time.
finalize(M.FieldOptions)
finalize(M.MessageOptions)
finalize(M.FieldDescriptorProto)
finalize(M.OneofDescriptorProto)
finalize(M.EnumValueDescriptorProto)
finalize(M.EnumDescriptorProto)
finalize(M.MethodDescriptorProto)
finalize(M.ServiceDescriptorProto)
finalize(M.DescriptorProto)
finalize(M.FileDescriptorProto)
finalize(M.FileDescriptorSet)

return M