package ocaml-protoc

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file pb_parsing_parse_tree.ml

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
(*
  The MIT License (MIT)

  Copyright (c) 2016 Maxime Ransan <maxime.ransan@gmail.com>

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.

*)

(** Protobuf parse tree *)

type message_field_label =
  [ `Optional
  | `Required
  | `Repeated
  | `Nolabel (* proto3 field which replaces required and optional *)
  ]
(** A field property defining its occurence
*)

type oneof_field_label = unit
(** Oneof field fields label 

    Oneof fields have no label, they are simply choices for the 
    oneof fiel they belong to. *)

type 'a field = {
  field_name: string;
  field_number: int;
  field_label: 'a;
  field_type: Pb_field_type.unresolved_t;
  field_options: Pb_option.set;
}
(** message field. 

    Note this field is parametrized with the label type 
    so that it can be used both by normal field and one of 
    field since the only difference between the 2 is 
    the label.
*)

type message_field = message_field_label field
type oneof_field = oneof_field_label field

type map_field = {
  map_name: string;
  map_number: int;
  map_key_type: Pb_field_type.map_key_type;
  map_value_type: Pb_field_type.unresolved_t;
  map_options: Pb_option.set;
}

type oneof = {
  oneof_name: string;
  oneof_fields: oneof_field list;
}
(** oneof entity *)

type enum_value = {
  enum_value_name: string;
  enum_value_int: int;
}

type enum_body_content =
  | Enum_value of enum_value
  | Enum_option of Pb_option.t

type enum = {
  enum_id: int;
  enum_name: string;
  enum_body: enum_body_content list;
}

type extension_range_to =
  | To_max
  | To_number of int

type extension_range_from = int

type extension_range =
  | Extension_single_number of int
  | Extension_range of extension_range_from * extension_range_to

(** Body content defines all the possible consituant 
    of a message. 
*)
type message_body_content =
  | Message_field of message_field
  | Message_map_field of map_field
  | Message_oneof_field of oneof
  | Message_sub of message
  | Message_enum of enum
  | Message_extension of extension_range list
  | Message_reserved of extension_range list
  | Message_option of Pb_option.t

and message = {
  id: int;
  message_name: string;
  message_body: message_body_content list;
}
(** Message entity. 

    Note the ID is simply for uniquely (and easily) identifying a type. It is
    expected to be generated by a parser. The later compilation 
    functions expects this id to be unique.
*)

type rpc = {
  rpc_name: string;
  rpc_options: Pb_option.set;
  rpc_req_stream: bool;
  rpc_req: Pb_field_type.unresolved_t;
  rpc_res_stream: bool;
  rpc_res: Pb_field_type.unresolved_t;
}

type service_body_content =
  | Service_rpc of rpc
  | Service_option of Pb_option.t

type service = {
  service_name: string;
  service_body: service_body_content list;
}

type extend = {
  id: int;
  extend_name: string;
  extend_body: message_field list;
}

type import = {
  file_name: string;
  public: bool;
}

type proto = {
  proto_file_name: string option;
  syntax: string option;
  imports: import list;
  file_options: Pb_option.set;
  package: string option;
  messages: message list;
  services: service list;
  enums: enum list;
  extends: extend list;
}
(** Definition of a protobuffer message file. 
*)
OCaml

Innovation. Community. Security.