@@ -84,20 +84,20 @@ defmodule Msgpax.Unpacker do
84
84
import Macro , only: [ pipe: 3 ]
85
85
86
86
for { format , { :value , value } } <- formats do
87
- def unpack ( << unquote_splicing ( format ) , rest :: bytes >> , [ ] , options ) do
87
+ def unpack ( << unquote_splicing ( format ) , rest :: bits >> , [ ] , options ) do
88
88
unpack ( rest , [ unquote ( value ) ] , options )
89
89
end
90
90
end
91
91
92
92
for { format , { :call , call } } <- formats do
93
93
rest = Macro . var ( :rest , nil )
94
94
options = Macro . var ( :options , nil )
95
- def unpack ( << unquote_splicing ( format ) , rest :: bytes >> , [ ] , options ) do
95
+ def unpack ( << unquote_splicing ( format ) , rest :: bits >> , [ ] , options ) do
96
96
unquote ( pipe ( rest , pipe ( [ ] , pipe ( options , pipe ( [ ] , call , 0 ) , 0 ) , 0 ) , 0 ) )
97
97
end
98
98
end
99
99
100
- def unpack ( << byte , _ :: bytes >> , [ ] , _options ) do
100
+ def unpack ( << byte , _ :: bits >> , [ ] , _options ) do
101
101
throw { :bad_format , byte }
102
102
end
103
103
@@ -109,25 +109,25 @@ defmodule Msgpax.Unpacker do
109
109
{ value , buffer }
110
110
end
111
111
112
- defp unpack_binary ( << buffer :: bytes >> , result , % { binary: true } = options , outer , value ) do
112
+ defp unpack_binary ( << buffer :: bits >> , result , % { binary: true } = options , outer , value ) do
113
113
unpack_continue ( buffer , [ Msgpax.Bin . new ( value ) | result ] , options , outer )
114
114
end
115
115
116
- defp unpack_binary ( << buffer :: bytes >> , result , options , outer , value ) do
116
+ defp unpack_binary ( << buffer :: bits >> , result , options , outer , value ) do
117
117
unpack_continue ( buffer , [ value | result ] , options , outer )
118
118
end
119
119
120
- def unpack_list ( << buffer :: bytes >> , result , options , outer , length ) do
120
+ def unpack_list ( << buffer :: bits >> , result , options , outer , length ) do
121
121
unpack_list ( buffer , result , options , outer , 0 , length )
122
122
end
123
123
124
- def unpack_list ( << buffer :: bytes >> , result , options , outer , count , count ) do
124
+ def unpack_list ( << buffer :: bits >> , result , options , outer , count , count ) do
125
125
{ value , rest } = Enum . split ( result , count )
126
126
unpack_continue ( buffer , [ :lists . reverse ( value ) | rest ] , options , outer )
127
127
end
128
128
129
129
for { format , { :value , value } } <- formats do
130
- def unpack_list ( << unquote_splicing ( format ) , rest :: bytes >> , result , options , outer , index , length ) do
130
+ def unpack_list ( << unquote_splicing ( format ) , rest :: bits >> , result , options , outer , index , length ) do
131
131
unpack_list ( rest , [ unquote ( value ) | result ] , options , outer , index + 1 , length )
132
132
end
133
133
end
@@ -137,27 +137,27 @@ defmodule Msgpax.Unpacker do
137
137
result = Macro . var ( :result , nil )
138
138
options = Macro . var ( :options , nil )
139
139
outer = Macro . var ( :outer , nil )
140
- def unpack_list ( << unquote_splicing ( format ) , rest :: bytes >> , result , options , outer , index , length ) do
140
+ def unpack_list ( << unquote_splicing ( format ) , rest :: bits >> , result , options , outer , index , length ) do
141
141
outer = [ { index , length } | outer ]
142
142
unquote ( pipe ( rest , pipe ( result , pipe ( options , pipe ( outer , call , 0 ) , 0 ) , 0 ) , 0 ) )
143
143
end
144
144
end
145
145
146
- def unpack_map ( << buffer :: bytes >> , result , options , outer , length ) do
146
+ def unpack_map ( << buffer :: bits >> , result , options , outer , length ) do
147
147
unpack_map ( buffer , result , options , outer , 0 , length , :key )
148
148
end
149
149
150
- def unpack_map ( << buffer :: bytes >> , result , options , outer , count , count , :key ) do
150
+ def unpack_map ( << buffer :: bits >> , result , options , outer , count , count , :key ) do
151
151
{ value , rest } = Enum . split ( result , count )
152
152
unpack_continue ( buffer , [ :maps . from_list ( value ) | rest ] , options , outer )
153
153
end
154
154
155
155
for { format , { :value , value } } <- formats do
156
- def unpack_map ( << unquote_splicing ( format ) , rest :: bytes >> , result , options , outer , index , length , :key ) do
156
+ def unpack_map ( << unquote_splicing ( format ) , rest :: bits >> , result , options , outer , index , length , :key ) do
157
157
unpack_map ( rest , [ unquote ( value ) | result ] , options , outer , index , length , :value )
158
158
end
159
159
160
- def unpack_map ( << unquote_splicing ( format ) , rest :: bytes >> , [ key | result ] , options , outer , index , length , :value ) do
160
+ def unpack_map ( << unquote_splicing ( format ) , rest :: bits >> , [ key | result ] , options , outer , index , length , :value ) do
161
161
unpack_map ( rest , [ { key , unquote ( value ) } | result ] , options , outer , index + 1 , length , :key )
162
162
end
163
163
end
@@ -167,13 +167,13 @@ defmodule Msgpax.Unpacker do
167
167
result = Macro . var ( :result , nil )
168
168
options = Macro . var ( :options , nil )
169
169
outer = Macro . var ( :outer , nil )
170
- def unpack_map ( << unquote_splicing ( format ) , rest :: bytes >> , result , options , outer , index , length , type ) do
170
+ def unpack_map ( << unquote_splicing ( format ) , rest :: bits >> , result , options , outer , index , length , type ) do
171
171
outer = [ { index , length , type } | outer ]
172
172
unquote ( pipe ( rest , pipe ( result , pipe ( options , pipe ( outer , call , 0 ) , 0 ) , 0 ) , 0 ) )
173
173
end
174
174
end
175
175
176
- defp unpack_ext ( << buffer :: bytes >> , result , options , outer , type , data ) do
176
+ defp unpack_ext ( << buffer :: bits >> , result , options , outer , type , data ) do
177
177
if type in 0 .. 127 do
178
178
unpack_continue ( buffer , [ unpack_ext ( type , data , options ) | result ] , options , outer )
179
179
else
@@ -194,19 +194,19 @@ defmodule Msgpax.Unpacker do
194
194
Msgpax.Ext . new ( type , data )
195
195
end
196
196
197
- def unpack_continue ( << buffer :: bytes >> , result , options , [ { index , length } | outer ] ) do
197
+ def unpack_continue ( << buffer :: bits >> , result , options , [ { index , length } | outer ] ) do
198
198
unpack_list ( buffer , result , options , outer , index + 1 , length )
199
199
end
200
200
201
- def unpack_continue ( << buffer :: bytes >> , result , options , [ { index , length , :key } | outer ] ) do
201
+ def unpack_continue ( << buffer :: bits >> , result , options , [ { index , length , :key } | outer ] ) do
202
202
unpack_map ( buffer , result , options , outer , index , length , :value )
203
203
end
204
204
205
- def unpack_continue ( << buffer :: bytes >> , [ { value , key } | result ] , options , [ { index , length , :value } | outer ] ) do
205
+ def unpack_continue ( << buffer :: bits >> , [ { value , key } | result ] , options , [ { index , length , :value } | outer ] ) do
206
206
unpack_map ( buffer , [ { key , value } | result ] , options , outer , index + 1 , length , :key )
207
207
end
208
208
209
- def unpack_continue ( << buffer :: bytes >> , result , options , [ ] ) do
209
+ def unpack_continue ( << buffer :: bits >> , result , options , [ ] ) do
210
210
unpack ( buffer , result , options )
211
211
end
212
212
end
0 commit comments