scon 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48fda0e6cfb2a5bbf2946502c85a14e920dc81b4
4
- data.tar.gz: 41a8ca03de33493ab66f872207c3eb00e8167379
3
+ metadata.gz: 1c2d9ac985fa59d6375f9315587cb79a1a21f65e
4
+ data.tar.gz: ab452a608097d43291f47abaa819c83f7c27693d
5
5
  SHA512:
6
- metadata.gz: 1fb72472a5244f9867551508f66aae66f0329827145ab900dc58aa87721268357317234d16046844766554737ceaf4ccf192ec238a5e08fc4e48bac2da791c66
7
- data.tar.gz: c0bf18290842b6cb162fee48dba7a56312352f0191732064afcc6123eeff6a0b96c90333c9b931ecc76bd58405fcff6876c3d6205d8b020f8e462986613dda5a
6
+ metadata.gz: 5d4f49d939c0d02488a28975a19f0d89211ef3fcd8136875ec26ff7954273fc079d9381f6a55bfb08459983cd28289b5499a4e7387a3c2f05d04343e30e73210
7
+ data.tar.gz: 2889b3ca49a2358eb7360d6f0ab92aa434f4cd04b81cb2e4a9aaa8d91acace3fd43497e8ce082fbb3a10a01c26af314f64852f55ca0e2ac2a3d8bcaeb62f68d2
@@ -17,7 +17,8 @@ module SCON
17
17
  :obj_start => 0xFA,
18
18
  :obj_end => 0xFB,
19
19
  :arr_start => 0xFC,
20
- :arr_end => 0xFD
20
+ :arr_end => 0xFD,
21
+ :arr_padding => 0xFE
21
22
  }
22
23
  end
23
24
  end
@@ -75,19 +75,39 @@ private
75
75
  encode_value k, v, :hash
76
76
  end
77
77
  elsif object.is_a? Array
78
- counter = 0
79
- object.each_with_index do |v, i|
80
- encode_value i, v, :array, counter
81
- counter += 1
78
+ encode_array object
79
+ end
80
+ end
81
+
82
+ def encode_array object
83
+ is_nil = false
84
+ nilcount = 0
85
+ object.each_with_index do |v, i|
86
+ if v.nil?
87
+ is_nil = true
88
+ nilcount += 1
89
+ else
90
+ if is_nil
91
+ if nilcount > 2
92
+ @body_bytes << Constants::DATA[:arr_padding]
93
+ @body_bytes << auto_number(nilcount)
94
+ else
95
+ nilcount.times { @body_bytes << Constants::DATA[:nil] }
96
+ end
97
+ end
98
+ is_nil = false
99
+ nilcount = 0
100
+
101
+ encode_value i, v, :array
82
102
  end
83
103
  end
84
104
  end
85
105
 
86
- def encode_value key, value, parent_type, array_counter=0
106
+ def encode_value key, value, parent_type
87
107
  instruct, serial = 0, nil
88
108
  if value.is_a? Hash
89
109
  @body_bytes << Constants::DATA[:obj_start]
90
- encode_key key, parent_type, array_counter
110
+ encode_key key, parent_type
91
111
  value.each do |k, v|
92
112
  encode_value k, v, :hash
93
113
  end
@@ -95,12 +115,8 @@ private
95
115
  return
96
116
  elsif value.is_a? Array
97
117
  @body_bytes << Constants::DATA[:arr_start]
98
- encode_key key, parent_type, array_counter
99
- counter = 0
100
- value.each_with_index do |v, i|
101
- encode_value i, v, :array, counter
102
- counter += 1
103
- end
118
+ encode_key key, parent_type
119
+ encode_array value
104
120
  @body_bytes << Constants::DATA[:arr_end]
105
121
  return
106
122
  elsif value.is_a?(Fixnum) || value.is_a?(Bignum)
@@ -121,11 +137,11 @@ private
121
137
  end
122
138
 
123
139
  @body_bytes << instruct
124
- encode_key key, parent_type, array_counter
140
+ encode_key key, parent_type
125
141
  @body_bytes << serial unless serial.nil?
126
142
  end
127
143
 
128
- def encode_key key, parent_type, array_counter
144
+ def encode_key key, parent_type
129
145
  if parent_type == :hash
130
146
  keys = key.to_s
131
147
  encode_key_hash keys
data/lib/scon/parser.rb CHANGED
@@ -122,6 +122,11 @@ private
122
122
  closed = true
123
123
  next
124
124
  end
125
+ if data_type == Constants::DATA[:arr_padding]
126
+ count = parse_value @data.shift
127
+ count.times { parent << nil }
128
+ data_type = @data.shift
129
+ end
125
130
  data_value = parse_value data_type
126
131
  parent << data_value
127
132
 
data/lib/scon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SCON
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JacisNonsense