1
+ import typing
2
+
3
+ import betterproto2
4
+
1
5
from betterproto2_compiler .lib .google .protobuf import (
2
6
BoolValue as VanillaBoolValue ,
7
+ BytesValue as VanillaBytesValue ,
8
+ DoubleValue as VanillaDoubleValue ,
9
+ FloatValue as VanillaFloatValue ,
10
+ Int32Value as VanillaInt32Value ,
11
+ Int64Value as VanillaInt64Value ,
3
12
StringValue as VanillaStringValue ,
13
+ UInt32Value as VanillaUInt32Value ,
14
+ UInt64Value as VanillaUInt64Value ,
4
15
)
5
16
6
17
@@ -12,6 +23,165 @@ def from_wrapped(wrapped: bool) -> "BoolValue":
12
23
def to_wrapped (self ) -> bool :
13
24
return self .value
14
25
26
+ @classmethod
27
+ def from_dict (cls , value ):
28
+ if isinstance (value , bool ):
29
+ return BoolValue (value = value )
30
+ return super ().from_dict (value )
31
+
32
+ def to_dict (
33
+ self ,
34
+ * ,
35
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
36
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
37
+ include_default_values : bool = False ,
38
+ ) -> dict [str , typing .Any ] | typing .Any :
39
+ return self .value
40
+
41
+
42
+ class Int32Value (VanillaInt32Value ):
43
+ @staticmethod
44
+ def from_wrapped (wrapped : int ) -> "Int32Value" :
45
+ return Int32Value (value = wrapped )
46
+
47
+ def to_wrapped (self ) -> int :
48
+ return self .value
49
+
50
+ @classmethod
51
+ def from_dict (cls , value ):
52
+ if isinstance (value , int ):
53
+ return Int32Value (value = value )
54
+ return super ().from_dict (value )
55
+
56
+ def to_dict (
57
+ self ,
58
+ * ,
59
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
60
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
61
+ include_default_values : bool = False ,
62
+ ) -> dict [str , typing .Any ] | typing .Any :
63
+ return self .value
64
+
65
+
66
+ class Int64Value (VanillaInt64Value ):
67
+ @staticmethod
68
+ def from_wrapped (wrapped : int ) -> "Int64Value" :
69
+ return Int64Value (value = wrapped )
70
+
71
+ def to_wrapped (self ) -> int :
72
+ return self .value
73
+
74
+ @classmethod
75
+ def from_dict (cls , value ):
76
+ if isinstance (value , int ):
77
+ return Int64Value (value = value )
78
+ return super ().from_dict (value )
79
+
80
+ def to_dict (
81
+ self ,
82
+ * ,
83
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
84
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
85
+ include_default_values : bool = False ,
86
+ ) -> dict [str , typing .Any ] | typing .Any :
87
+ return self .value
88
+
89
+
90
+ class UInt32Value (VanillaUInt32Value ):
91
+ @staticmethod
92
+ def from_wrapped (wrapped : int ) -> "UInt32Value" :
93
+ return UInt32Value (value = wrapped )
94
+
95
+ def to_wrapped (self ) -> int :
96
+ return self .value
97
+
98
+ @classmethod
99
+ def from_dict (cls , value ):
100
+ if isinstance (value , int ):
101
+ return UInt32Value (value = value )
102
+ return super ().from_dict (value )
103
+
104
+ def to_dict (
105
+ self ,
106
+ * ,
107
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
108
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
109
+ include_default_values : bool = False ,
110
+ ) -> dict [str , typing .Any ] | typing .Any :
111
+ return self .value
112
+
113
+
114
+ class UInt64Value (VanillaUInt64Value ):
115
+ @staticmethod
116
+ def from_wrapped (wrapped : int ) -> "UInt64Value" :
117
+ return UInt64Value (value = wrapped )
118
+
119
+ def to_wrapped (self ) -> int :
120
+ return self .value
121
+
122
+ @classmethod
123
+ def from_dict (cls , value ):
124
+ if isinstance (value , int ):
125
+ return UInt64Value (value = value )
126
+ return super ().from_dict (value )
127
+
128
+ def to_dict (
129
+ self ,
130
+ * ,
131
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
132
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
133
+ include_default_values : bool = False ,
134
+ ) -> dict [str , typing .Any ] | typing .Any :
135
+ return self .value
136
+
137
+
138
+ class FloatValue (VanillaFloatValue ):
139
+ @staticmethod
140
+ def from_wrapped (wrapped : float ) -> "FloatValue" :
141
+ return FloatValue (value = wrapped )
142
+
143
+ def to_wrapped (self ) -> float :
144
+ return self .value
145
+
146
+ @classmethod
147
+ def from_dict (cls , value ):
148
+ if isinstance (value , float ):
149
+ return FloatValue (value = value )
150
+ return super ().from_dict (value )
151
+
152
+ def to_dict (
153
+ self ,
154
+ * ,
155
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
156
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
157
+ include_default_values : bool = False ,
158
+ ) -> dict [str , typing .Any ] | typing .Any :
159
+ return self .value
160
+
161
+
162
+ class DoubleValue (VanillaDoubleValue ):
163
+ @staticmethod
164
+ def from_wrapped (wrapped : float ) -> "DoubleValue" :
165
+ return DoubleValue (value = wrapped )
166
+
167
+ def to_wrapped (self ) -> float :
168
+ return self .value
169
+
170
+ @classmethod
171
+ def from_dict (cls , value ):
172
+ if isinstance (value , float ):
173
+ return DoubleValue (value = value )
174
+ return super ().from_dict (value )
175
+
176
+ def to_dict (
177
+ self ,
178
+ * ,
179
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
180
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
181
+ include_default_values : bool = False ,
182
+ ) -> dict [str , typing .Any ] | typing .Any :
183
+ return self .value
184
+
15
185
16
186
class StringValue (VanillaStringValue ):
17
187
@staticmethod
@@ -20,3 +190,42 @@ def from_wrapped(wrapped: str) -> "StringValue":
20
190
21
191
def to_wrapped (self ) -> str :
22
192
return self .value
193
+
194
+ @classmethod
195
+ def from_dict (cls , value ):
196
+ if isinstance (value , str ):
197
+ return StringValue (value = value )
198
+ return super ().from_dict (value )
199
+
200
+ def to_dict (
201
+ self ,
202
+ * ,
203
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
204
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
205
+ include_default_values : bool = False ,
206
+ ) -> dict [str , typing .Any ] | typing .Any :
207
+ return self .value
208
+
209
+
210
+ class BytesValue (VanillaBytesValue ):
211
+ @staticmethod
212
+ def from_wrapped (wrapped : bytes ) -> "BytesValue" :
213
+ return BytesValue (value = wrapped )
214
+
215
+ def to_wrapped (self ) -> bytes :
216
+ return self .value
217
+
218
+ @classmethod
219
+ def from_dict (cls , value ):
220
+ if isinstance (value , bytes ):
221
+ return BytesValue (value = value )
222
+ return super ().from_dict (value )
223
+
224
+ def to_dict (
225
+ self ,
226
+ * ,
227
+ output_format : betterproto2 .OutputFormat = betterproto2 .OutputFormat .PROTO_JSON ,
228
+ casing : betterproto2 .Casing = betterproto2 .Casing .CAMEL ,
229
+ include_default_values : bool = False ,
230
+ ) -> dict [str , typing .Any ] | typing .Any :
231
+ return self .value
0 commit comments