active_model_serializers_binary 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +10 -8
- data/Gemfile +5 -20
- data/Gemfile.lock +33 -140
- data/MIT-LICENSE +1 -1
- data/Rakefile +2 -31
- data/active_model_serializers_binary.gemspec +2 -17
- data/bin/test +5 -0
- data/lib/active_model_serializers_binary/active_model_serializers_binary.rb +142 -124
- data/lib/active_model_serializers_binary/base_type.rb +1 -1
- data/lib/active_model_serializers_binary/data_types.rb +261 -250
- data/lib/active_model_serializers_binary/railtie.rb +4 -0
- data/lib/active_model_serializers_binary/version.rb +1 -1
- data/test/active_model_serializers_binary_test.rb +3 -3
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/assets/stylesheets/application.css +1 -15
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/product.rb +28 -0
- data/test/dummy/app/models/silo.rb +6 -0
- data/test/dummy/app/models/type.rb +7 -0
- data/test/dummy/app/views/layouts/application.html.erb +10 -9
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/rails +3 -3
- data/test/dummy/bin/rake +2 -2
- data/test/dummy/bin/setup +33 -0
- data/test/dummy/config/application.rb +12 -13
- data/test/dummy/config/boot.rb +3 -3
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/database.yml +3 -3
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +46 -15
- data/test/dummy/config/environments/production.rb +38 -33
- data/test/dummy/config/environments/test.rb +34 -13
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -2
- data/test/dummy/config/initializers/inflections.rb +4 -4
- data/test/dummy/config/initializers/permissions_policy.rb +11 -0
- data/test/dummy/config/locales/en.yml +13 -3
- data/test/dummy/config/puma.rb +43 -0
- data/test/dummy/config/routes.rb +3 -53
- data/test/dummy/config/storage.yml +34 -0
- data/test/dummy/config.ru +3 -1
- data/test/dummy/db/migrate/20170830125642_create_silos.rb +10 -0
- data/test/dummy/db/schema.rb +5 -6
- data/test/dummy/lib/test_parser.rb +23 -5
- data/test/dummy/public/404.html +6 -6
- data/test/dummy/public/422.html +6 -6
- data/test/dummy/public/500.html +6 -6
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/test/fixtures/silos.yml +9 -0
- data/test/dummy/test/models/silo_test.rb +7 -0
- data/test/test_helper.rb +7 -8
- metadata +52 -72
- data/test/dummy/app/models/producto.rb +0 -47
- data/test/dummy/app/models/tipo.rb +0 -18
- data/test/dummy/db/migrate/20160608024807_create_productos.rb +0 -16
- data/test/dummy/db/migrate/20170817015810_create_tipos.rb +0 -9
@@ -1,251 +1,262 @@
|
|
1
|
-
require_relative 'base_type.rb'
|
2
|
-
|
3
|
-
module DataTypes
|
4
|
-
|
5
|
-
class Int8 < BaseType
|
6
|
-
def initialize(options = {})
|
7
|
-
super options.merge :bit_length => 8, :sign => :signed
|
8
|
-
end
|
9
|
-
|
10
|
-
def dump(value=nil)
|
11
|
-
before_dump( value )
|
12
|
-
@raw_value = @value
|
13
|
-
end
|
14
|
-
|
15
|
-
def load(raw_value)
|
16
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('c*')
|
17
|
-
after_load
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class Int16 < BaseType
|
22
|
-
def initialize(options = {})
|
23
|
-
super options.merge :bit_length => 16, :sign => :signed
|
24
|
-
end
|
25
|
-
|
26
|
-
def dump(value=nil)
|
27
|
-
before_dump( value )
|
28
|
-
if @endianess == :big
|
29
|
-
@raw_value = @value.pack('s>*').unpack('C*')
|
30
|
-
else
|
31
|
-
@raw_value = @value.pack('s<*').unpack('C*')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def load(raw_value)
|
36
|
-
if @endianess == :big
|
37
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('s>*')
|
38
|
-
else
|
39
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('s<*')
|
40
|
-
end
|
41
|
-
after_load
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class Int32 < BaseType
|
46
|
-
def initialize(options = {})
|
47
|
-
super options.merge :bit_length => 32, :sign => :signed
|
48
|
-
end
|
49
|
-
|
50
|
-
def dump(value=nil)
|
51
|
-
before_dump( value )
|
52
|
-
if @endianess == :big
|
53
|
-
@raw_value = @value.pack('l>*').unpack('C*')
|
54
|
-
else
|
55
|
-
@raw_value = @value.pack('l<*').unpack('C*')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def load(raw_value)
|
60
|
-
if @endianess == :big
|
61
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('l>*') if !value.nil?
|
62
|
-
else
|
63
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('l<*') if !value.nil?
|
64
|
-
end
|
65
|
-
after_load
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class UInt16 < BaseType
|
70
|
-
def initialize(options = {})
|
71
|
-
super options.merge :bit_length => 16, :sign => :unsigned
|
72
|
-
end
|
73
|
-
|
74
|
-
def dump(value=nil)
|
75
|
-
before_dump( value )
|
76
|
-
if @endianess == :big
|
77
|
-
@raw_value = @value.pack('S>*').unpack('C*')
|
78
|
-
else
|
79
|
-
@raw_value = @value.pack('S<*').unpack('C*')
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def load(raw_value)
|
84
|
-
@raw_value = check_raw_value(raw_value)
|
85
|
-
if @endianess == :big
|
86
|
-
self.value = @raw_value.pack('C*').unpack('S>*')
|
87
|
-
else
|
88
|
-
self.value = @raw_value.pack('C*').unpack('S<*')
|
89
|
-
end
|
90
|
-
after_load
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
class UInt32 < BaseType
|
95
|
-
def initialize(options = {})
|
96
|
-
super options.merge :bit_length => 32, :sign => :unsigned
|
97
|
-
end
|
98
|
-
|
99
|
-
def dump(value=nil)
|
100
|
-
before_dump( value )
|
101
|
-
if @endianess == :big
|
102
|
-
@raw_value = @value.pack('L>*').unpack('C*')
|
103
|
-
else
|
104
|
-
@raw_value = @value.pack('L<*').unpack('C*')
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def load(raw_value)
|
109
|
-
if @endianess == :big
|
110
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('L>*') if !value.nil?
|
111
|
-
else
|
112
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('L<*') if !value.nil?
|
113
|
-
end
|
114
|
-
after_load
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
class UInt8 < BaseType
|
119
|
-
def initialize(options = {})
|
120
|
-
super options.merge :bit_length => 8, :sign => :unsigned
|
121
|
-
end
|
122
|
-
|
123
|
-
def dump(value=nil)
|
124
|
-
before_dump( value )
|
125
|
-
@raw_value = @value
|
126
|
-
end
|
127
|
-
|
128
|
-
def load(raw_value)
|
129
|
-
self.value = check_raw_value(raw_value)
|
130
|
-
after_load
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
class BitField < BaseType
|
135
|
-
def initialize(options = {})
|
136
|
-
length = options[:bin_length].blank? ? 1 : (options[:bin_length] > 32 ? 32 : options[:bin_length])
|
137
|
-
super options.merge :bit_length => length, :sign => :unsigned
|
138
|
-
end
|
139
|
-
|
140
|
-
def format
|
141
|
-
if bit_length <= 8 # 8 bits
|
142
|
-
'C*'
|
143
|
-
elsif bit_length <= 16 # 16 bits
|
144
|
-
'v*'
|
145
|
-
else # 32 bits
|
146
|
-
'l*'
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def word_length
|
151
|
-
if bit_length <= 8 # 8 bits
|
152
|
-
8
|
153
|
-
elsif bit_length <= 16 # 16 bits
|
154
|
-
16
|
155
|
-
else # 32 bits
|
156
|
-
32
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def dump(value=nil)
|
161
|
-
before_dump( value )
|
162
|
-
data = @value.pack(format).unpack('b*').first.chars.each_slice(word_length).map(&:join).map{|n| n.slice(0,bit_length)}
|
163
|
-
@raw_value = [data.join].pack('b*').unpack('C*')
|
164
|
-
end
|
165
|
-
|
166
|
-
def load(raw_value)
|
167
|
-
self.value = check_raw_value(raw_value).pack('C*').unpack('b*').first.chars.slice(0,@bit_length*@count).each_slice(bit_length).map(&:join).map{|n| [n].pack('b*').unpack('C*').first}
|
168
|
-
after_load
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
class Char < BaseType
|
173
|
-
def initialize(options = {})
|
174
|
-
super options.merge :bit_length => 8, :sign => nil, :default_value => "\x0"
|
175
|
-
end
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
def
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
def
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
1
|
+
require_relative 'base_type.rb'
|
2
|
+
|
3
|
+
module DataTypes
|
4
|
+
|
5
|
+
class Int8 < BaseType
|
6
|
+
def initialize(options = {})
|
7
|
+
super options.merge :bit_length => 8, :sign => :signed
|
8
|
+
end
|
9
|
+
|
10
|
+
def dump(value=nil)
|
11
|
+
before_dump( value )
|
12
|
+
@raw_value = @value.pack('c*').unpack('C*')
|
13
|
+
end
|
14
|
+
|
15
|
+
def load(raw_value)
|
16
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('c*')
|
17
|
+
after_load
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Int16 < BaseType
|
22
|
+
def initialize(options = {})
|
23
|
+
super options.merge :bit_length => 16, :sign => :signed
|
24
|
+
end
|
25
|
+
|
26
|
+
def dump(value=nil)
|
27
|
+
before_dump( value )
|
28
|
+
if @endianess == :big
|
29
|
+
@raw_value = @value.pack('s>*').unpack('C*')
|
30
|
+
else
|
31
|
+
@raw_value = @value.pack('s<*').unpack('C*')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def load(raw_value)
|
36
|
+
if @endianess == :big
|
37
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('s>*')
|
38
|
+
else
|
39
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('s<*')
|
40
|
+
end
|
41
|
+
after_load
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Int32 < BaseType
|
46
|
+
def initialize(options = {})
|
47
|
+
super options.merge :bit_length => 32, :sign => :signed
|
48
|
+
end
|
49
|
+
|
50
|
+
def dump(value=nil)
|
51
|
+
before_dump( value )
|
52
|
+
if @endianess == :big
|
53
|
+
@raw_value = @value.pack('l>*').unpack('C*')
|
54
|
+
else
|
55
|
+
@raw_value = @value.pack('l<*').unpack('C*')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def load(raw_value)
|
60
|
+
if @endianess == :big
|
61
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('l>*') if !value.nil?
|
62
|
+
else
|
63
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('l<*') if !value.nil?
|
64
|
+
end
|
65
|
+
after_load
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class UInt16 < BaseType
|
70
|
+
def initialize(options = {})
|
71
|
+
super options.merge :bit_length => 16, :sign => :unsigned
|
72
|
+
end
|
73
|
+
|
74
|
+
def dump(value=nil)
|
75
|
+
before_dump( value )
|
76
|
+
if @endianess == :big
|
77
|
+
@raw_value = @value.pack('S>*').unpack('C*')
|
78
|
+
else
|
79
|
+
@raw_value = @value.pack('S<*').unpack('C*')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def load(raw_value)
|
84
|
+
@raw_value = check_raw_value(raw_value)
|
85
|
+
if @endianess == :big
|
86
|
+
self.value = @raw_value.pack('C*').unpack('S>*')
|
87
|
+
else
|
88
|
+
self.value = @raw_value.pack('C*').unpack('S<*')
|
89
|
+
end
|
90
|
+
after_load
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class UInt32 < BaseType
|
95
|
+
def initialize(options = {})
|
96
|
+
super options.merge :bit_length => 32, :sign => :unsigned
|
97
|
+
end
|
98
|
+
|
99
|
+
def dump(value=nil)
|
100
|
+
before_dump( value )
|
101
|
+
if @endianess == :big
|
102
|
+
@raw_value = @value.pack('L>*').unpack('C*')
|
103
|
+
else
|
104
|
+
@raw_value = @value.pack('L<*').unpack('C*')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def load(raw_value)
|
109
|
+
if @endianess == :big
|
110
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('L>*') if !value.nil?
|
111
|
+
else
|
112
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('L<*') if !value.nil?
|
113
|
+
end
|
114
|
+
after_load
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class UInt8 < BaseType
|
119
|
+
def initialize(options = {})
|
120
|
+
super options.merge :bit_length => 8, :sign => :unsigned
|
121
|
+
end
|
122
|
+
|
123
|
+
def dump(value=nil)
|
124
|
+
before_dump( value )
|
125
|
+
@raw_value = @value
|
126
|
+
end
|
127
|
+
|
128
|
+
def load(raw_value)
|
129
|
+
self.value = check_raw_value(raw_value)
|
130
|
+
after_load
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class BitField < BaseType
|
135
|
+
def initialize(options = {})
|
136
|
+
length = options[:bin_length].blank? ? 1 : (options[:bin_length] > 32 ? 32 : options[:bin_length])
|
137
|
+
super options.merge :bit_length => length, :sign => :unsigned
|
138
|
+
end
|
139
|
+
|
140
|
+
def format
|
141
|
+
if bit_length <= 8 # 8 bits
|
142
|
+
'C*'
|
143
|
+
elsif bit_length <= 16 # 16 bits
|
144
|
+
'v*'
|
145
|
+
else # 32 bits
|
146
|
+
'l*'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def word_length
|
151
|
+
if bit_length <= 8 # 8 bits
|
152
|
+
8
|
153
|
+
elsif bit_length <= 16 # 16 bits
|
154
|
+
16
|
155
|
+
else # 32 bits
|
156
|
+
32
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def dump(value=nil)
|
161
|
+
before_dump( value )
|
162
|
+
data = @value.pack(format).unpack('b*').first.chars.each_slice(word_length).map(&:join).map{|n| n.slice(0,bit_length)}
|
163
|
+
@raw_value = [data.join].pack('b*').unpack('C*')
|
164
|
+
end
|
165
|
+
|
166
|
+
def load(raw_value)
|
167
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('b*').first.chars.slice(0,@bit_length*@count).each_slice(bit_length).map(&:join).map{|n| [n].pack('b*').unpack('C*').first}
|
168
|
+
after_load
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class Char < BaseType
|
173
|
+
def initialize(options = {})
|
174
|
+
super options.merge :bit_length => 8, :sign => nil, :default_value => "\x0"
|
175
|
+
end
|
176
|
+
|
177
|
+
EXTENDED_CHARACTERS = ["Ç","ü","é","â","ä","à","å","ç","ê","ë","è","ï","î","ì","Ä","Å","É","æ","Æ","ô","ö","ò","û","ù","ÿ","Ö","Ü","ø","£","Ø","×","ƒ","á","í","ó","ú","ñ","Ñ","ª","º","¿","®","¬","½","¼","¡","«","»","░","▒","▓","│","┤","Á","Â","À","©","╣","║","╗","╝","¢","¥","┐","└","┴","┬","├","─","┼","ã","Ã","╚","╔","╩","╦","╠","═","╬","¤","ð","Ð","Ê","Ë","È","ı","Í","Î","Ï","┘","┌","█","▄","¦","Ì","▀","Ó","ß","Ô","Ò","õ","Õ","µ","þ","Þ","Ú","Û","Ù","ý","Ý","¯","´","≡","±","‗","¾","¶","§","÷","¸","°","¨","·","¹","³","²","■"," "]
|
178
|
+
ASCII_TO_UTF8=["",('?'*31).split(''),(32..126).to_a.pack("U*").split(''),"?", EXTENDED_CHARACTERS].flatten
|
179
|
+
|
180
|
+
def dump(value=nil) # to bytes
|
181
|
+
before_dump( value )
|
182
|
+
@raw_value = @value.map{|v| v.ljust(@length, @default_value).slice(0,@length)}.first.split("").map{|x| x=="\u0000" ? 0 : ASCII_TO_UTF8.index(x)}
|
183
|
+
@raw_value
|
184
|
+
end
|
185
|
+
|
186
|
+
def load(raw_value) # from bytes
|
187
|
+
if !value.nil?
|
188
|
+
characters = []
|
189
|
+
check_raw_value(raw_value).each do |x|
|
190
|
+
break if x == 0
|
191
|
+
characters << ASCII_TO_UTF8[x]
|
192
|
+
end
|
193
|
+
self.value = characters.empty? ? "" : characters.join[0...@length]
|
194
|
+
end
|
195
|
+
after_load
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
class Bool < BaseType
|
200
|
+
def initialize(options = {})
|
201
|
+
super options.merge :bit_length => 1, :default_value => false
|
202
|
+
end
|
203
|
+
|
204
|
+
def dump(value=nil)
|
205
|
+
before_dump( value )
|
206
|
+
@raw_value = Array(@value.map{|v| v ? 1 : 0}.join).pack('b*').unpack('C*')
|
207
|
+
end
|
208
|
+
|
209
|
+
def load(raw_value)
|
210
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('b*').first.slice(0,size*8).split('').map(&:to_i) if !value.nil?
|
211
|
+
after_load
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
class Float32 < BaseType
|
216
|
+
def initialize(options = {})
|
217
|
+
super options.merge :bit_length => 32, :sign => nil, :default_value => 0.0
|
218
|
+
end
|
219
|
+
|
220
|
+
def dump(value=nil)
|
221
|
+
before_dump( value )
|
222
|
+
if @endianess == :big
|
223
|
+
@raw_value = @value.pack('g*').unpack('C*')
|
224
|
+
else
|
225
|
+
@raw_value = @value.pack('e*').unpack('C*')
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def load(raw_value)
|
230
|
+
if @endianess == :big
|
231
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('g*') if !value.nil?
|
232
|
+
else
|
233
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('e*') if !value.nil?
|
234
|
+
end
|
235
|
+
after_load
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
class Float64 < BaseType
|
240
|
+
def initialize(options = {})
|
241
|
+
super options.merge :bit_length => 64, :sign => nil, :default_value => 0.0
|
242
|
+
end
|
243
|
+
|
244
|
+
def dump(value=nil)
|
245
|
+
before_dump( value )
|
246
|
+
if @endianess == :big
|
247
|
+
@raw_value = @value.pack('G*').unpack('C*')
|
248
|
+
else
|
249
|
+
@raw_value = @value.pack('E*').unpack('C*')
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def load(raw_value)
|
254
|
+
if @endianess == :big
|
255
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('G*') if !value.nil?
|
256
|
+
else
|
257
|
+
self.value = check_raw_value(raw_value).pack('C*').unpack('E*') if !value.nil?
|
258
|
+
end
|
259
|
+
after_load
|
260
|
+
end
|
261
|
+
end
|
251
262
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class ActiveModelSerializersBinaryTest < ActiveSupport::TestCase
|
4
|
-
test "
|
5
|
-
|
4
|
+
test "it has a version number" do
|
5
|
+
assert ActiveModelSerializersBinary::VERSION
|
6
6
|
end
|
7
7
|
end
|
data/test/dummy/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
2
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
3
|
|
4
|
-
|
4
|
+
require_relative "config/application"
|
5
5
|
|
6
6
|
Rails.application.load_tasks
|
@@ -1,15 +1 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
1
|
+
/* Application styles */
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Product
|
2
|
+
include ActiveModel::Serializers::Binary
|
3
|
+
include ActiveModel::Model # This must not be included when serializing ActiveRecord classes
|
4
|
+
|
5
|
+
endianess :big
|
6
|
+
align :dword
|
7
|
+
|
8
|
+
int8 :int8
|
9
|
+
int16 :int16
|
10
|
+
int16le :int16le
|
11
|
+
int16be :int16be
|
12
|
+
int32 :int32
|
13
|
+
int32le :int32le
|
14
|
+
int32be :int32be
|
15
|
+
uint8 :uint8
|
16
|
+
uint16 :uint16
|
17
|
+
uint16le :uint16le
|
18
|
+
uint16be :uint16be
|
19
|
+
uint32 :uint32
|
20
|
+
uint32le :uint32le
|
21
|
+
uint32be :uint32be
|
22
|
+
bitfield :bitfield
|
23
|
+
float32 :float32
|
24
|
+
float64 :float64
|
25
|
+
char :char
|
26
|
+
bool :bool
|
27
|
+
#nest :type, coder: Type
|
28
|
+
end
|