Skip to content

Commit 10c80a9

Browse files
committed
[ci] fix uuid and bytes buffer extension tests
1 parent 4f0f668 commit 10c80a9

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

jdataencode.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@
121121

122122
%% -------------------------------------------------------------------------
123123
function newitem = obj2jd(item, opt)
124-
124+
newitem = item;
125125
if (iscell(item))
126126
newitem = cell2jd(item, opt);
127127
elseif (isa(item, 'jdict'))
128-
newitem = obj2jd(item(), opt);
128+
if (isempty(item{'kind'}))
129+
newitem = obj2jd(item(), opt);
130+
end
129131
elseif (isstruct(item))
130132
newitem = struct2jd(item, opt);
131133
elseif (isnumeric(item) || islogical(item) || isa(item, 'timeseries'))
@@ -144,11 +146,9 @@
144146
newitem = graph2jd(item, opt);
145147
elseif (isobject(item))
146148
newitem = matlabobject2jd(item, opt);
147-
else
148-
newitem = item;
149149
end
150150

151-
if (isa(item, 'jdict')) % apply attribute
151+
if (isa(item, 'jdict') && isempty(item{'kind'})) % apply attribute
152152
attrpath = item.getattr();
153153
if (isempty(attrpath))
154154
return

savebj.m

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
end
250250

251251
if (~skippreencode && jsonopt('PreEncode', 1, opt))
252-
obj = jdataencode(obj, 'Base64', 0, 'UseArrayZipSize', opt.messagepack, 'DateTime', 0, opt);
252+
obj = jdataencode(obj, 'Base64', 0, 'UseArrayZipSize', opt.messagepack, 'DateTime', (opt.formatversion < 4), opt);
253253
end
254254

255255
dozip = opt.compression;
@@ -325,8 +325,12 @@
325325
txt = ext2ubjson(name, item, 'datetime', opt);
326326
elseif (isa(item, 'duration'))
327327
txt = ext2ubjson(name, item, 'duration', opt);
328-
elseif (isa(item, 'jdict') && ~isempty(item{'kind'}))
329-
txt = jdict2ubjson(name, item, level, opt);
328+
elseif (isa(item, 'jdict'))
329+
if (~isempty(item{'kind'}))
330+
txt = jdict2ubjson(name, item, level, opt);
331+
else
332+
txt = obj2ubjson(name, item(), level, opt);
333+
end
330334
elseif (ischar(item))
331335
if (numel(item) >= opt.compressstringsize)
332336
txt = mat2ubjson(name, item, level, opt);
@@ -1855,11 +1859,15 @@
18551859
return
18561860
end
18571861
d = item.v();
1858-
shifts = uint64([24 16 8 0 8 0 8 0 8 0 40 32 24 16 8 0]);
1859-
vals = uint64([d.time_low d.time_low d.time_low d.time_low ...
1860-
d.time_mid d.time_mid d.time_high d.time_high ...
1861-
d.clock_seq d.clock_seq d.node d.node d.node d.node d.node d.node]);
1862-
payload = uint8(bitand(bitshift(vals, -shifts), 255));
1862+
payload = uint8([ ...
1863+
bitshift(d.time_low, -24), bitand(bitshift(d.time_low, -16), 255), ...
1864+
bitand(bitshift(d.time_low, -8), 255), bitand(d.time_low, 255), ...
1865+
bitshift(d.time_mid, -8), bitand(d.time_mid, 255), ...
1866+
bitshift(d.time_high, -8), bitand(d.time_high, 255), ...
1867+
bitshift(d.clock_seq, -8), bitand(d.clock_seq, 255), ...
1868+
bitshift(d.node, -40), bitand(bitshift(d.node, -32), 255), ...
1869+
bitand(bitshift(d.node, -24), 255), bitand(bitshift(d.node, -16), 255), ...
1870+
bitand(bitshift(d.node, -8), 255), bitand(d.node, 255)]);
18631871
txt = ['E' I_(uint8(10), opt) I_(uint8(16), opt) char(payload)];
18641872
if ~isempty(name)
18651873
txt = [N_(decodevarname(name, opt.unpackhex), opt) txt];
@@ -1868,8 +1876,9 @@
18681876
% Raw extension bytes
18691877
payload = uint8(item.v());
18701878
typeid = uint32(0);
1871-
if isfield(s, 'exttype')
1872-
typeid = uint32(s.exttype);
1879+
exttype = item{'exttype'};
1880+
if ~isempty(exttype)
1881+
typeid = uint32(exttype);
18731882
end
18741883
txt = ['E' I_(typeid, opt) I_(uint32(length(payload)), opt) char(payload)];
18751884
if ~isempty(name)

test/run_jsonlab_test.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function run_jsonlab_test(tests)
265265
test_jsonlab('heterogeneous cell', @savebj, {{1, {2, 3}}, {4, 5}, {6}; {7}, {8, 9}, {10}}, ...
266266
'[[[U<1>[U<2>U<3>]][U<4>U<5>][U<6>]][[U<7>][U<8>U<9>][U<10>]]]', 'debug', 1);
267267
test_jsonlab('struct array', @savebj, repmat(struct('i', 1.1, 'd', 'str'), [1, 2]), ...
268-
'[{U<1>iD<1.1>U<1>dSU<3>str}{U<1>iD<1.1>U<1>dSU<3>str}]', 'debug', 1);
268+
'[{U<1>iD<1.1>U<1>dSU<3>str}{U<1>iD<1.1>U<1>dSU<3>str}]', 'debug', 1, 'formatversion', 2);
269269
test_jsonlab('encoded fieldnames', @savebj, struct(encodevarname('_i'), 1, encodevarname('i_'), 'str'), ...
270270
'{U<2>_iU<1>U<2>i_SU<3>str}', 'debug', 1);
271271
test_jsonlab('optimized 2D row-major array', @savebj, loadbj(['[$i#[$U#U' char([2 2 3 61 62 65 66 67 68])]), '[$U#[$U#U<2><2><3><61><62><65><66><67><68>', 'debug', 1);
@@ -1270,16 +1270,18 @@ function run_jsonlab_test(tests)
12701270
'{U<11>_ArrayType_SU<6>singleU<11>_ArraySize_[$U#U<2><1><2>U<16>_ArrayIsComplex_TU<11>_ArrayData_[$U#[$U#U<2><2><2><1><3><2><4>}', 'debug', 1);
12711271

12721272
% uuid (type 10): 16 bytes Big-Endian
1273-
test_jsonlab('uuid', @savebj, jdict(struct('time_low', uint64(1427098624), ...
1274-
'time_mid', uint64(58011), ...
1275-
'time_high', uint64(16852), ...
1276-
'clock_seq', uint64(42774), ...
1277-
'node', uint64(75124066492416)), 'kind', 'uuid'), ...
1273+
test_jsonlab('uuid', @savebj, jdict(struct('time_low', uint64(hex2dec('550e8400')), ...
1274+
'time_mid', uint64(hex2dec('e29b')), ...
1275+
'time_high', uint64(hex2dec('41d4')), ...
1276+
'clock_seq', uint64(hex2dec('a716')), ...
1277+
'node', uint64(hex2dec('446655440000'))), 'kind', 'uuid'), ...
12781278
['EU<10>U<16>' char([85 14 132 0 226 155 65 212 167 22 68 102 85 68 0 0])], 'debug', 1);
12791279

12801280
% unknown extension round-trip (type 200)
1281-
test_jsonlab('raw extension', @savebj, struct('x0x5F_ByteData_', uint8([1, 2, 3, 4]), 'x0x5F_ExtType_', int32(200)), ...
1282-
['Em' char([200 0 0 0]) 'm' char([4 0 0 0 1 2 3 4])], 'debug', 1);
1281+
raw = jdict(uint8([1, 2, 3, 4]), 'kind', 'bytes');
1282+
raw{'exttype'} = int32(200);
1283+
test_jsonlab('raw extension', @savebj, raw, ...
1284+
['EU<200>U<4>' char([1 2 3 4])], 'debug', 1);
12831285

12841286
if exist('datetime', 'class')
12851287
% datetime - epoch_s (type 1): uint32 seconds since epoch

0 commit comments

Comments
 (0)