Skip to content

Commit 7c91e13

Browse files
committed
upgrade to Julia 1.0
1 parent adbb560 commit 7c91e13

File tree

8 files changed

+226
-292
lines changed

8 files changed

+226
-292
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ os:
33
- linux
44
- osx
55
julia:
6-
- 0.4
7-
- 0.5
8-
- 0.6
6+
- 1.0
7+
- nightly
8+
99
# - nightly
1010
notifications:
1111
email: false

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ are encoded as CBOR `Type 4`
127127

128128
#### Maps
129129

130-
An `Associative` type is encoded as CBOR `Type 5`
130+
An `AbstractDict` type is encoded as CBOR `Type 5`
131131

132132
```julia
133133
> d = Dict()
@@ -265,7 +265,7 @@ function cubes(ch::Channel)
265265
end
266266
end
267267

268-
> bytes = encode(Pair(Channel(cubes), Associative))
268+
> bytes = encode(Pair(Channel(cubes), AbstractDict))
269269
34-element Array{UInt8, 1}: 0xbf 0x01 0x01 0x02 0x08 ... 0x0a 0x19 0x03 0xe8 0xff
270270

271271
> decode(bytes)

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
julia 0.4
1+
julia 1.0

appveyor.yml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
5-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
6-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
7-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
8-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
9-
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
10-
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
3+
- julia_version: 1.0
4+
- julia_version: nightly
5+
6+
platform:
7+
- x86 # 32-bit
8+
- x64 # 64-bit
9+
10+
# # Uncomment the following lines to allow failures on nightly julia
11+
# # (tests will run but not make your overall status red)
12+
# matrix:
13+
# allow_failures:
14+
# - julia_version: latest
1115

1216
branches:
1317
only:
@@ -21,19 +25,18 @@ notifications:
2125
on_build_status_changed: false
2226

2327
install:
24-
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
25-
# Download most recent Julia Windows binary
26-
- ps: (new-object net.webclient).DownloadFile(
27-
$env:JULIA_URL,
28-
"C:\projects\julia-binary.exe")
29-
# Run installer silently, output to C:\projects\julia
30-
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
28+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
3129

3230
build_script:
33-
# Need to convert from shallow to complete for Pkg.clone to work
34-
- IF EXIST .git\shallow (git fetch --unshallow)
35-
- C:\projects\julia\bin\julia -e "versioninfo();
36-
Pkg.clone(pwd(), \"CBOR\"); Pkg.build(\"CBOR\")"
31+
- echo "%JL_BUILD_SCRIPT%"
32+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
3733

3834
test_script:
39-
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"CBOR\")"
35+
- echo "%JL_TEST_SCRIPT%"
36+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
37+
38+
# # Uncomment to support code coverage upload. Should only be enabled for packages
39+
# # which would have coverage gaps without running on Windows
40+
# on_success:
41+
# - echo "%JL_CODECOV_SCRIPT%"
42+
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"

src/CBOR.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ THE SOFTWARE.
2222

2323
module CBOR
2424

25+
using Printf
26+
27+
num2hex(n) = string(n, base = 16, pad = sizeof(n) * 2)
28+
num2hex(n::AbstractFloat) = num2hex(reinterpret(Unsigned, n))
29+
hex2num(s) = reinterpret(Float64, parse(UInt64, s, base = 16))
30+
hex(n) = string(n, base = 16)
31+
2532
include("constants.jl")
2633
include("encoding-common.jl")
2734
include("decoding-common.jl")
@@ -36,7 +43,7 @@ function decode(cbor_bytes::Array{UInt8, 1})
3643
end
3744

3845
function decode_with_iana(cbor_bytes::Array{UInt8, 1})
39-
warn("Results from decode_with_iana may change in the future.")
46+
@warn("Results from decode_with_iana may change in the future.")
4047
data, _ = decode_next(1, cbor_bytes, true)
4148
return data
4249
end

src/decoding-common.jl

Lines changed: 113 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -106,135 +106,140 @@ function decode_next(start_idx, bytes::Array{UInt8, 1}, with_iana::Bool)
106106
first_byte = bytes[start_idx]
107107
typ = first_byte & TYPE_BITS_MASK
108108

109-
if typ == TYPE_0
110-
data, bytes_consumed = decode_unsigned(start_idx, bytes)
109+
if typ == TYPE_0
110+
data, bytes_consumed = decode_unsigned(start_idx, bytes)
111+
112+
elseif typ == TYPE_1
113+
data, bytes_consumed = decode_unsigned(start_idx, bytes)
114+
if (i = Int128(data) + 1) > typemax(Int64)
115+
data = -i
116+
else
117+
data = -(Signed(data) + 1)
118+
end
111119

112-
elseif typ == TYPE_1
113-
data, bytes_consumed = decode_unsigned(start_idx, bytes)
114-
if (i = Int128(data) + 1) > typemax(Int64)
115-
data = -i
116-
else
117-
data = -(Signed(data) + 1)
118-
end
120+
elseif typ == TYPE_6
121+
tag, bytes_consumed = decode_unsigned(start_idx, bytes)
119122

120-
elseif typ == TYPE_6
121-
tag, bytes_consumed = decode_unsigned(start_idx, bytes)
123+
function retrieve_plain_pair()
124+
tagged_data, data_bytes =
125+
decode_next(start_idx + bytes_consumed, bytes,
126+
with_iana)
127+
bytes_consumed += data_bytes
128+
129+
return Pair(tag, tagged_data)
130+
end
122131

123-
function retrieve_plain_pair()
124-
tagged_data, data_bytes =
132+
if with_iana
133+
if tag == POS_BIG_INT_TAG || tag == NEG_BIG_INT_TAG
134+
big_int_bytes, sub_bytes_consumed =
125135
decode_next(start_idx + bytes_consumed, bytes,
126136
with_iana)
127-
bytes_consumed += data_bytes
128-
129-
return Pair(tag, tagged_data)
130-
end
137+
bytes_consumed += sub_bytes_consumed
131138

132-
if with_iana
133-
if tag == POS_BIG_INT_TAG || tag == NEG_BIG_INT_TAG
134-
big_int_bytes, sub_bytes_consumed =
135-
decode_next(start_idx + bytes_consumed, bytes,
136-
with_iana)
137-
bytes_consumed += sub_bytes_consumed
138-
139-
big_int = parse(BigInt, bytes2hex(big_int_bytes),
140-
HEX_BASE)
141-
if tag == NEG_BIG_INT_TAG
142-
big_int = -(big_int + 1)
143-
end
144-
145-
data = big_int
146-
else
147-
data = retrieve_plain_pair()
139+
big_int = parse(
140+
BigInt, bytes2hex(big_int_bytes), base = HEX_BASE
141+
)
142+
if tag == NEG_BIG_INT_TAG
143+
big_int = -(big_int + 1)
148144
end
145+
146+
data = big_int
149147
else
150148
data = retrieve_plain_pair()
151149
end
150+
else
151+
data = retrieve_plain_pair()
152+
end
152153

153-
elseif typ == TYPE_7
154-
addntl_info = first_byte & ADDNTL_INFO_MASK
155-
bytes_consumed = 1
154+
elseif typ == TYPE_7
155+
addntl_info = first_byte & ADDNTL_INFO_MASK
156+
bytes_consumed = 1
156157

157-
if addntl_info < SINGLE_BYTE_SIMPLE_PLUS_ONE + 1
158+
if addntl_info < SINGLE_BYTE_SIMPLE_PLUS_ONE + 1
159+
bytes_consumed += 1
160+
if addntl_info < SINGLE_BYTE_SIMPLE_PLUS_ONE
161+
simple_val = addntl_info
162+
else
158163
bytes_consumed += 1
159-
if addntl_info < SINGLE_BYTE_SIMPLE_PLUS_ONE
160-
simple_val = addntl_info
161-
else
162-
bytes_consumed += 1
163-
simple_val = bytes[start_idx + 1]
164-
end
164+
simple_val = bytes[start_idx + 1]
165+
end
165166

166-
if simple_val == SIMPLE_FALSE
167-
data = false
168-
elseif simple_val == SIMPLE_TRUE
169-
data = true
170-
elseif simple_val == SIMPLE_NULL
171-
data = Null()
172-
elseif simple_val == SIMPLE_UNDEF
173-
data = Undefined()
174-
else
175-
data = Simple(simple_val)
176-
end
167+
if simple_val == SIMPLE_FALSE
168+
data = false
169+
elseif simple_val == SIMPLE_TRUE
170+
data = true
171+
elseif simple_val == SIMPLE_NULL
172+
data = Null()
173+
elseif simple_val == SIMPLE_UNDEF
174+
data = Undefined()
177175
else
178-
if addntl_info == ADDNTL_INFO_FLOAT64
179-
float_byte_len = SIZE_OF_FLOAT64
180-
elseif addntl_info == ADDNTL_INFO_FLOAT32
181-
float_byte_len = SIZE_OF_FLOAT32
182-
elseif addntl_info == ADDNTL_INFO_FLOAT16
183-
error("Decoding 16-bit floats isn't supported.")
184-
end
185-
186-
bytes_consumed += float_byte_len
187-
data = hex2num(bytes2hex(
188-
bytes[(start_idx + 1):(start_idx + float_byte_len)]
189-
))
176+
data = Simple(simple_val)
190177
end
191-
192-
elseif first_byte & ADDNTL_INFO_MASK == ADDNTL_INFO_INDEF
193-
data, bytes_consumed =
194-
decode_next_indef(start_idx, bytes, typ, with_iana)
195-
196-
elseif typ == TYPE_2
197-
byte_string_len, bytes_consumed =
198-
decode_unsigned(start_idx, bytes)
199-
start_idx += bytes_consumed
200-
201-
data =
202-
bytes[start_idx:(start_idx + byte_string_len - 1)]
203-
bytes_consumed += byte_string_len
204-
205-
elseif typ == TYPE_3
206-
string_bytes, bytes_consumed =
207-
decode_unsigned(start_idx, bytes)
208-
start_idx += bytes_consumed
209-
data = (VERSION < v"0.5.0") ?
210-
UTF8String(bytes[start_idx:(start_idx + string_bytes - 1)]) :
211-
String(bytes[start_idx:(start_idx + string_bytes - 1)])
212-
bytes_consumed += string_bytes
213-
214-
elseif typ == TYPE_4
215-
vec_len, bytes_consumed = decode_unsigned(start_idx, bytes)
216-
data = Vector(vec_len)
217-
for i in 1:vec_len
218-
data[i], sub_bytes_consumed =
219-
decode_next(start_idx + bytes_consumed, bytes, with_iana)
220-
bytes_consumed += sub_bytes_consumed
178+
else
179+
180+
if addntl_info == ADDNTL_INFO_FLOAT64
181+
float_byte_len = SIZE_OF_FLOAT64
182+
FloatT = Float64; UintT = UInt64
183+
elseif addntl_info == ADDNTL_INFO_FLOAT32
184+
float_byte_len = SIZE_OF_FLOAT32
185+
FloatT = Float32; UintT = UInt32
186+
elseif addntl_info == ADDNTL_INFO_FLOAT16
187+
float_byte_len = SIZE_OF_FLOAT16
188+
FloatT = Float16; UintT = UInt16
221189
end
222190

223-
elseif typ == TYPE_5
224-
map_len, bytes_consumed = decode_unsigned(start_idx, bytes)
225-
data = Dict()
226-
for i in 1:map_len
227-
key, key_bytes =
228-
decode_next(start_idx + bytes_consumed, bytes, with_iana)
229-
bytes_consumed += key_bytes
191+
bytes_consumed += float_byte_len
192+
hex = bytes2hex(
193+
bytes[(start_idx + 1):(start_idx + float_byte_len)]
194+
)
195+
data = reinterpret(FloatT, parse(UintT, hex, base = 16))
196+
end
230197

231-
value, value_bytes =
232-
decode_next(start_idx + bytes_consumed, bytes, with_iana)
233-
bytes_consumed += value_bytes
198+
elseif first_byte & ADDNTL_INFO_MASK == ADDNTL_INFO_INDEF
199+
data, bytes_consumed =
200+
decode_next_indef(start_idx, bytes, typ, with_iana)
234201

235-
data[key] = value
236-
end
202+
elseif typ == TYPE_2
203+
byte_string_len, bytes_consumed =
204+
decode_unsigned(start_idx, bytes)
205+
start_idx += bytes_consumed
206+
207+
data =
208+
bytes[start_idx:(start_idx + byte_string_len - 1)]
209+
bytes_consumed += byte_string_len
210+
211+
elseif typ == TYPE_3
212+
string_bytes, bytes_consumed =
213+
decode_unsigned(start_idx, bytes)
214+
start_idx += bytes_consumed
215+
data = String(bytes[start_idx:(start_idx + string_bytes - 1)])
216+
217+
bytes_consumed += string_bytes
218+
219+
elseif typ == TYPE_4
220+
vec_len, bytes_consumed = decode_unsigned(start_idx, bytes)
221+
data = Vector(undef, vec_len)
222+
for i in 1:vec_len
223+
data[i], sub_bytes_consumed =
224+
decode_next(start_idx + bytes_consumed, bytes, with_iana)
225+
bytes_consumed += sub_bytes_consumed
237226
end
238227

228+
elseif typ == TYPE_5
229+
map_len, bytes_consumed = decode_unsigned(start_idx, bytes)
230+
data = Dict()
231+
for i in 1:map_len
232+
key, key_bytes =
233+
decode_next(start_idx + bytes_consumed, bytes, with_iana)
234+
bytes_consumed += key_bytes
235+
236+
value, value_bytes =
237+
decode_next(start_idx + bytes_consumed, bytes, with_iana)
238+
bytes_consumed += value_bytes
239+
240+
data[key] = value
241+
end
242+
end
243+
239244
return data, bytes_consumed
240245
end

0 commit comments

Comments
 (0)