@@ -24,9 +24,8 @@ import Fathom.Data.Sing
2424|||  bit temperamental and result in ambiguities when importing modules that
2525|||  contain types of the same name as those defined in the current module.
2626public  export
27- record CustomFormat  where 
28-   constructor MkCustomFormat 
29-   Rep  :  Type 
27+ record CustomFormatOf  (Rep  :  Type ) where
28+   constructor MkCustomFormatOf 
3029  decode  :  Decode (Rep, ByteStream) ByteStream
3130  encode  :  Encode Rep ByteStream
3231
@@ -41,7 +40,7 @@ data FormatOf : (A : Type) -> Type where
4140  Repeat  :  {0 A : Type } ->  (len  : Nat ) ->  FormatOf A ->  FormatOf (Vect  len A)
4241  Pair  :  {0 A, B : Type } ->  FormatOf A ->  FormatOf B ->  FormatOf (A, B)
4342  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 
4544
4645
4746namespace FormatOf 
@@ -97,6 +96,51 @@ namespace FormatOf
9796  encode (Custom  f) x =  f. encode x
9897
9998
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+ 
100144-- -----------------------
101145--  FORMAT DESCRIPTIONS --
102146-- -----------------------
@@ -224,35 +268,3 @@ namespace Format
224268  public export
225269  (>>= ) :  (f  : Format) ->  (Rep f ->  Format) ->  Format
226270  (>>= ) =  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