Skip to content

Commit 1abcc85

Browse files
committed
Format
1 parent 90d0865 commit 1abcc85

2 files changed

Lines changed: 83 additions & 53 deletions

File tree

test/cli_error_handling_generated/proto.gleam

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import protozoa/decode
99
import protozoa/encode
1010

1111
pub type ProblematicMessage {
12-
ProblematicMessage(
13-
import_: String,
14-
type_: String,
15-
fn_: String,
16-
)
12+
ProblematicMessage(import_: String, type_: String, fn_: String)
1713
}
1814

19-
pub fn encode_problematicmessage(problematicmessage: ProblematicMessage) -> BitArray {
15+
pub fn encode_problematicmessage(
16+
problematicmessage: ProblematicMessage,
17+
) -> BitArray {
2018
encode.message([
2119
encode.string_field(1, problematicmessage.import_),
2220
encode.string_field(2, problematicmessage.type_),
@@ -31,6 +29,8 @@ pub fn problematicmessage_decoder() -> decode.Decoder(ProblematicMessage) {
3129
decode.success(ProblematicMessage(import_: import_, type_: type_, fn_: fn_))
3230
}
3331

34-
pub fn decode_problematicmessage(data: BitArray) -> Result(ProblematicMessage, List(decode.DecodeError)) {
32+
pub fn decode_problematicmessage(
33+
data: BitArray,
34+
) -> Result(ProblematicMessage, List(decode.DecodeError)) {
3535
decode.run(data, problematicmessage_decoder())
36-
}
36+
}

test/validation_output/proto.gleam

Lines changed: 75 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,42 @@ pub type ServiceResponseResponse {
2727
}
2828

2929
pub type ServiceResponse {
30-
ServiceResponse(
31-
response: option.Option(ServiceResponseResponse),
32-
)
30+
ServiceResponse(response: option.Option(ServiceResponseResponse))
3331
}
3432

3533
pub type Duration {
36-
Duration(
37-
seconds: Int,
38-
nanos: Int,
39-
)
34+
Duration(seconds: Int, nanos: Int)
4035
}
4136

4237
pub type Empty {
4338
Empty
4439
}
4540

4641
pub type FieldMask {
47-
FieldMask(
48-
paths: List(String),
49-
)
42+
FieldMask(paths: List(String))
5043
}
5144

5245
pub type Timestamp {
53-
Timestamp(
54-
seconds: Int,
55-
nanos: Int,
56-
)
46+
Timestamp(seconds: Int, nanos: Int)
5747
}
5848

5949
pub fn encode_serviceresponse(serviceresponse: ServiceResponse) -> BitArray {
6050
encode.message([
6151
case serviceresponse.response {
6252
Some(oneof_value) -> {
6353
case oneof_value {
64-
Data(value) -> encode.field(1, wire.LengthDelimited, encode.length_delimited(encode_eventmessage(value)))
65-
EmptyData(value) -> encode.field(2, wire.LengthDelimited, encode.length_delimited(encode_empty(value)))
54+
Data(value) ->
55+
encode.field(
56+
1,
57+
wire.LengthDelimited,
58+
encode.length_delimited(encode_eventmessage(value)),
59+
)
60+
EmptyData(value) ->
61+
encode.field(
62+
2,
63+
wire.LengthDelimited,
64+
encode.length_delimited(encode_empty(value)),
65+
)
6666
}
6767
}
6868
None -> <<>>
@@ -73,9 +73,21 @@ pub fn encode_serviceresponse(serviceresponse: ServiceResponse) -> BitArray {
7373
pub fn encode_eventmessage(eventmessage: EventMessage) -> BitArray {
7474
encode.message([
7575
encode.string_field(1, eventmessage.event_name),
76-
encode.field(2, wire.LengthDelimited, encode.length_delimited(encode_timestamp(eventmessage.occurred_at))),
77-
encode.field(3, wire.LengthDelimited, encode.length_delimited(encode_duration(eventmessage.duration))),
78-
encode.field(4, wire.LengthDelimited, encode.length_delimited(encode_fieldmask(eventmessage.update_mask))),
76+
encode.field(
77+
2,
78+
wire.LengthDelimited,
79+
encode.length_delimited(encode_timestamp(eventmessage.occurred_at)),
80+
),
81+
encode.field(
82+
3,
83+
wire.LengthDelimited,
84+
encode.length_delimited(encode_duration(eventmessage.duration)),
85+
),
86+
encode.field(
87+
4,
88+
wire.LengthDelimited,
89+
encode.length_delimited(encode_fieldmask(eventmessage.update_mask)),
90+
),
7991
])
8092
}
8193

@@ -91,7 +103,8 @@ pub fn encode_empty(_empty: Empty) -> BitArray {
91103
}
92104

93105
pub fn encode_fieldmask(fieldmask: FieldMask) -> BitArray {
94-
let paths_fields = list.map(fieldmask.paths, fn(v) { encode.string_field(1, v) })
106+
let paths_fields =
107+
list.map(fieldmask.paths, fn(v) { encode.string_field(1, v) })
95108
encode.message(paths_fields)
96109
}
97110

@@ -102,36 +115,38 @@ pub fn encode_timestamp(timestamp: Timestamp) -> BitArray {
102115
])
103116
}
104117

105-
fn oneof_response_decoder() -> decode.Decoder(option.Option(ServiceResponseResponse)) {
118+
fn oneof_response_decoder() -> decode.Decoder(
119+
option.Option(ServiceResponseResponse),
120+
) {
106121
decode.from_field_dict(fn(fields) {
107122
case dict.get(fields, 1) {
108123
Ok([field, ..]) -> {
109124
case decode.message_field(_, eventmessage_decoder())(field) {
110125
Ok(value) -> Ok(option.Some(Data(value)))
111126
Error(_) -> {
112-
case dict.get(fields, 2) {
113-
Ok([field, ..]) -> {
114-
case decode.message_field(_, empty_decoder())(field) {
115-
Ok(value) -> Ok(option.Some(EmptyData(value)))
116-
Error(_) -> Ok(option.None)
117-
}
118-
}
119-
_ -> Ok(option.None)
120-
}
127+
case dict.get(fields, 2) {
128+
Ok([field, ..]) -> {
129+
case decode.message_field(_, empty_decoder())(field) {
130+
Ok(value) -> Ok(option.Some(EmptyData(value)))
131+
Error(_) -> Ok(option.None)
132+
}
133+
}
134+
_ -> Ok(option.None)
135+
}
121136
}
122137
}
123138
}
124139
_ -> {
125-
case dict.get(fields, 2) {
126-
Ok([field, ..]) -> {
127-
case decode.message_field(_, empty_decoder())(field) {
128-
Ok(value) -> Ok(option.Some(EmptyData(value)))
129-
Error(_) -> Ok(option.None)
140+
case dict.get(fields, 2) {
141+
Ok([field, ..]) -> {
142+
case decode.message_field(_, empty_decoder())(field) {
143+
Ok(value) -> Ok(option.Some(EmptyData(value)))
144+
Error(_) -> Ok(option.None)
145+
}
146+
}
147+
_ -> Ok(option.None)
130148
}
131149
}
132-
_ -> Ok(option.None)
133-
}
134-
}
135150
}
136151
})
137152
}
@@ -141,7 +156,9 @@ pub fn serviceresponse_decoder() -> decode.Decoder(ServiceResponse) {
141156
decode.success(ServiceResponse(response: response))
142157
}
143158

144-
pub fn decode_serviceresponse(data: BitArray) -> Result(ServiceResponse, List(decode.DecodeError)) {
159+
pub fn decode_serviceresponse(
160+
data: BitArray,
161+
) -> Result(ServiceResponse, List(decode.DecodeError)) {
145162
decode.run(data, serviceresponse_decoder())
146163
}
147164

@@ -150,10 +167,17 @@ pub fn eventmessage_decoder() -> decode.Decoder(EventMessage) {
150167
use occurred_at <- decode.then(decode.nested_message(2, timestamp_decoder()))
151168
use duration <- decode.then(decode.nested_message(3, duration_decoder()))
152169
use update_mask <- decode.then(decode.nested_message(4, fieldmask_decoder()))
153-
decode.success(EventMessage(event_name: event_name, occurred_at: occurred_at, duration: duration, update_mask: update_mask))
170+
decode.success(EventMessage(
171+
event_name: event_name,
172+
occurred_at: occurred_at,
173+
duration: duration,
174+
update_mask: update_mask,
175+
))
154176
}
155177

156-
pub fn decode_eventmessage(data: BitArray) -> Result(EventMessage, List(decode.DecodeError)) {
178+
pub fn decode_eventmessage(
179+
data: BitArray,
180+
) -> Result(EventMessage, List(decode.DecodeError)) {
157181
decode.run(data, eventmessage_decoder())
158182
}
159183

@@ -163,7 +187,9 @@ pub fn duration_decoder() -> decode.Decoder(Duration) {
163187
decode.success(Duration(seconds: seconds, nanos: nanos))
164188
}
165189

166-
pub fn decode_duration(data: BitArray) -> Result(Duration, List(decode.DecodeError)) {
190+
pub fn decode_duration(
191+
data: BitArray,
192+
) -> Result(Duration, List(decode.DecodeError)) {
167193
decode.run(data, duration_decoder())
168194
}
169195

@@ -180,7 +206,9 @@ pub fn fieldmask_decoder() -> decode.Decoder(FieldMask) {
180206
decode.success(FieldMask(paths: paths))
181207
}
182208

183-
pub fn decode_fieldmask(data: BitArray) -> Result(FieldMask, List(decode.DecodeError)) {
209+
pub fn decode_fieldmask(
210+
data: BitArray,
211+
) -> Result(FieldMask, List(decode.DecodeError)) {
184212
decode.run(data, fieldmask_decoder())
185213
}
186214

@@ -190,6 +218,8 @@ pub fn timestamp_decoder() -> decode.Decoder(Timestamp) {
190218
decode.success(Timestamp(seconds: seconds, nanos: nanos))
191219
}
192220

193-
pub fn decode_timestamp(data: BitArray) -> Result(Timestamp, List(decode.DecodeError)) {
221+
pub fn decode_timestamp(
222+
data: BitArray,
223+
) -> Result(Timestamp, List(decode.DecodeError)) {
194224
decode.run(data, timestamp_decoder())
195-
}
225+
}

0 commit comments

Comments
 (0)