@@ -24,9 +24,8 @@ import Fathom.Data.Sing
24
24
||| bit temperamental and result in ambiguities when importing modules that
25
25
||| contain types of the same name as those defined in the current module.
26
26
public export
27
- record CustomFormat where
28
- constructor MkCustomFormat
29
- Rep : Type
27
+ record CustomFormatOf (Rep : Type ) where
28
+ constructor MkCustomFormatOf
30
29
decode : Decode (Rep, ByteStream) ByteStream
31
30
encode : Encode Rep ByteStream
32
31
@@ -41,7 +40,7 @@ data FormatOf : (A : Type) -> Type where
41
40
Repeat : {0 A : Type } -> (len : Nat ) -> FormatOf A -> FormatOf (Vect len A)
42
41
Pair : {0 A, B : Type } -> FormatOf A -> FormatOf B -> FormatOf (A, B)
43
42
Bind : {0 A : Type } -> {0 B : A -> Type } -> (f : FormatOf A) -> ((x : A) -> FormatOf (B x)) -> FormatOf (x : A ** B x)
44
- Custom : (f : CustomFormat ) -> FormatOf f.Rep
43
+ Custom : {0 A : Type } -> (f : CustomFormatOf A ) -> FormatOf A
45
44
46
45
47
46
namespace FormatOf
@@ -97,6 +96,51 @@ namespace FormatOf
97
96
encode (Custom f) x = f. encode x
98
97
99
98
99
+ -- ------------------
100
+ -- CUSTOM FORMATS --
101
+ -- ------------------
102
+
103
+
104
+ public export
105
+ u8 : FormatOf Nat
106
+ u8 = Custom (MkCustomFormatOf
107
+ { decode = map cast decodeU8
108
+ , encode = encodeU8 . cast {to = Bits8 }
109
+ })
110
+
111
+
112
+ public export
113
+ u16Le : FormatOf Nat
114
+ u16Le = Custom (MkCustomFormatOf
115
+ { decode = map cast (decodeU16 LE )
116
+ , encode = encodeU16 LE . cast {to = Bits16 }
117
+ })
118
+
119
+
120
+ public export
121
+ u16Be : FormatOf Nat
122
+ u16Be = Custom (MkCustomFormatOf
123
+ { decode = map cast (decodeU16 BE )
124
+ , encode = encodeU16 BE . cast {to = Bits16 }
125
+ })
126
+
127
+
128
+ public export
129
+ u32Le : FormatOf Nat
130
+ u32Le = Custom (MkCustomFormatOf
131
+ { decode = map cast (decodeU32 LE )
132
+ , encode = encodeU32 LE . cast {to = Bits32 }
133
+ })
134
+
135
+
136
+ public export
137
+ u32Be : FormatOf Nat
138
+ u32Be = Custom (MkCustomFormatOf
139
+ { decode = map cast (decodeU32 BE )
140
+ , encode = encodeU32 BE . cast {to = Bits32 }
141
+ })
142
+
143
+
100
144
-- -----------------------
101
145
-- FORMAT DESCRIPTIONS --
102
146
-- -----------------------
@@ -224,35 +268,3 @@ namespace Format
224
268
public export
225
269
(>>= ) : (f : Format) -> (Rep f -> Format) -> Format
226
270
(>>= ) = bind
227
-
228
-
229
- -- ------------------
230
- -- CUSTOM FORMATS --
231
- -- ------------------
232
-
233
-
234
- public export
235
- u8 : FormatOf Nat
236
- u8 = Custom (MkCustomFormat
237
- { Rep = Nat
238
- , decode = map cast decodeU8
239
- , encode = encodeU8 . cast {to = Bits8 }
240
- })
241
-
242
-
243
- public export
244
- u16Le : FormatOf Nat
245
- u16Le = Custom (MkCustomFormat
246
- { Rep = Nat
247
- , decode = map cast (decodeU16 LE )
248
- , encode = encodeU16 LE . cast {to = Bits16 }
249
- })
250
-
251
-
252
- public export
253
- u16Be : FormatOf Nat
254
- u16Be = Custom (MkCustomFormat
255
- { Rep = Nat
256
- , decode = map cast (decodeU16 BE )
257
- , encode = encodeU16 BE . cast {to = Bits16 }
258
- })
0 commit comments