@@ -27,35 +27,25 @@ import Control.Monad.Eff
27
27
import Data.Maybe
28
28
import Node.Encoding
29
29
30
- -- |
31
- -- Type synonym indicating the value should be an octet (0-255). If the value
32
- -- provided is outside this range it will be used as modulo 255.
33
- --
30
+ -- | Type synonym indicating the value should be an octet (0-255). If the value
31
+ -- | provided is outside this range it will be used as modulo 255.
34
32
type Octet = Int
35
33
36
- -- |
37
- -- Type synonym indicating the value refers to an offset in a buffer.
38
- --
34
+ -- | Type synonym indicating the value refers to an offset in a buffer.
39
35
type Offset = Int
40
36
41
- -- |
42
- -- An instance of Node's Buffer class.
43
- --
37
+ -- | An instance of Node's Buffer class.
44
38
foreign import data Buffer :: *
45
39
46
40
instance showBuffer :: Show Buffer where
47
41
show = showImpl
48
-
42
+
49
43
foreign import showImpl :: Buffer -> String
50
44
51
- -- |
52
- -- Effect for buffer modification.
53
- --
45
+ -- | Effect for buffer modification.
54
46
foreign import data BufferWrite :: !
55
47
56
- -- |
57
- -- Enumeration of the numeric types that can be written to a buffer.
58
- --
48
+ -- | Enumeration of the numeric types that can be written to a buffer.
59
49
data BufferValueType
60
50
= UInt8
61
51
| UInt16LE
@@ -88,113 +78,81 @@ instance showBufferValueType :: Show BufferValueType where
88
78
show DoubleLE = " DoubleLE"
89
79
show DoubleBE = " DoubleBE"
90
80
91
- -- |
92
- -- Creates a new buffer of the specified size.
93
- --
81
+ -- | Creates a new buffer of the specified size.
94
82
foreign import create :: Int -> Buffer
95
83
96
- -- |
97
- -- Creates a new buffer from an array of octets, sized to match the array.
98
- --
84
+ -- | Creates a new buffer from an array of octets, sized to match the array.
99
85
foreign import fromArray :: Array Octet -> Buffer
100
86
101
- -- |
102
- -- Creates a new buffer from a string with the specified encoding, sized to
103
- -- match the string.
104
- --
87
+ -- | Creates a new buffer from a string with the specified encoding, sized to
88
+ -- | match the string.
105
89
fromString :: String -> Encoding -> Buffer
106
90
fromString str = fromStringImpl str <<< show
107
91
108
92
foreign import fromStringImpl :: String -> String -> Buffer
109
93
110
- -- |
111
- -- Reads a numeric value from a buffer at the specified offset.
112
- --
94
+ -- | Reads a numeric value from a buffer at the specified offset.
113
95
read :: BufferValueType -> Offset -> Buffer -> Int
114
96
read = readImpl <<< show
115
97
116
98
foreign import readImpl :: String -> Offset -> Buffer -> Int
117
99
118
- -- |
119
- -- Reads a section of a buffer as a string with the specified encoding.
120
- --
100
+ -- | Reads a section of a buffer as a string with the specified encoding.
121
101
readString :: Encoding -> Offset -> Offset -> Buffer -> String
122
102
readString = readStringImpl <<< show
123
103
124
104
foreign import readStringImpl :: String -> Offset -> Offset -> Buffer -> String
125
-
126
- -- |
127
- -- Reads the buffer as a string with the specified encoding.
128
- --
105
+
106
+ -- | Reads the buffer as a string with the specified encoding.
129
107
toString :: Encoding -> Buffer -> String
130
108
toString = toStringImpl <<< show
131
109
132
110
foreign import toStringImpl :: String -> Buffer -> String
133
111
134
- -- |
135
- -- Writes a numeric value to a buffer at the specified offset.
136
- --
112
+ -- | Writes a numeric value to a buffer at the specified offset.
137
113
write :: forall e . BufferValueType -> Int -> Offset -> Buffer -> Eff (buffer :: BufferWrite | e ) Unit
138
114
write = writeImpl <<< show
139
115
140
116
foreign import writeImpl ::
141
117
forall e . String -> Int -> Offset -> Buffer -> Eff (buffer :: BufferWrite | e ) Unit
142
118
143
- -- |
144
- -- Writes octets from a string to a buffer at the specified offset. Multi-byte
145
- -- characters will not be written to the buffer if there is not enough capacity
146
- -- to write them fully. The number of bytes written is returned.
147
- --
119
+ -- | Writes octets from a string to a buffer at the specified offset. Multi-byte
120
+ -- | characters will not be written to the buffer if there is not enough capacity
121
+ -- | to write them fully. The number of bytes written is returned.
148
122
writeString :: forall e . Encoding -> Offset -> Int -> String -> Buffer -> Eff (buffer :: BufferWrite | e ) Int
149
123
writeString = writeStringImpl <<< show
150
124
151
125
foreign import writeStringImpl ::
152
126
forall e . String -> Offset -> Int -> String -> Buffer -> Eff (buffer :: BufferWrite | e ) Int
153
127
154
- -- |
155
- -- Creates an array of octets from a buffer's contents.
156
- --
128
+ -- | Creates an array of octets from a buffer's contents.
157
129
foreign import toArray :: Buffer -> Array Octet
158
130
159
- -- |
160
- -- Reads an octet from a buffer at the specified offset.
161
- --
131
+ -- | Reads an octet from a buffer at the specified offset.
162
132
getAtOffset :: Offset -> Buffer -> Maybe Octet
163
133
getAtOffset = getAtOffsetImpl Just Nothing
164
134
165
135
foreign import getAtOffsetImpl ::
166
136
(Octet -> Maybe Octet ) -> Maybe Octet -> Offset -> Buffer -> Maybe Octet
167
137
168
- -- |
169
- -- Writes an octet in the buffer at the specified offset.
170
- --
138
+ -- | Writes an octet in the buffer at the specified offset.
171
139
foreign import setAtOffset ::
172
140
forall e . Octet -> Offset -> Buffer -> Eff (buffer :: BufferWrite | e ) Unit
173
141
174
- -- |
175
- -- Returns the size of a buffer.
176
- --
142
+ -- | Returns the size of a buffer.
177
143
foreign import size :: Buffer -> Int
178
144
179
- -- |
180
- -- Concatenates a list of buffers.
181
- --
145
+ -- | Concatenates a list of buffers.
182
146
foreign import concat :: Array Buffer -> Buffer
183
-
184
- -- |
185
- -- Concatenates a list of buffers, combining them into a new buffer of the
186
- -- specified length.
187
- --
147
+
148
+ -- | Concatenates a list of buffers, combining them into a new buffer of the
149
+ -- | specified length.
188
150
foreign import concat' :: Array Buffer -> Int -> Buffer
189
151
190
- -- |
191
- -- Copies a section of a source buffer into a target buffer at the specified
192
- -- offset.
193
- --
152
+ -- | Copies a section of a source buffer into a target buffer at the specified
153
+ -- | offset.
194
154
foreign import copy :: Offset -> Offset -> Buffer -> Offset -> Buffer -> Buffer
195
-
196
- -- |
197
- -- Fills a range in a buffer with the specified octet.
198
- --
155
+
156
+ -- | Fills a range in a buffer with the specified octet.
199
157
foreign import fill ::
200
158
forall e . Octet -> Offset -> Offset -> Buffer -> Eff (buffer :: BufferWrite | e ) Unit
0 commit comments