bjdata 0.5.0__tar.gz → 0.5.1__tar.gz
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.
- {bjdata-0.5.0 → bjdata-0.5.1}/Binary_JData_Specification.md +88 -31
- bjdata-0.5.1/CHANGELOG +18 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/PKG-INFO +17 -3
- {bjdata-0.5.0 → bjdata-0.5.1}/README.md +1 -1
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata/__init__.py +14 -4
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata/__main__.py +20 -17
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata/compat.py +14 -9
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata/decoder.py +418 -161
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata/encoder.py +246 -79
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata/markers.py +27 -27
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata.egg-info/PKG-INFO +17 -3
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata.egg-info/SOURCES.txt +1 -0
- bjdata-0.5.1/setup.py +140 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/src/_bjdata.c +46 -41
- {bjdata-0.5.0 → bjdata-0.5.1}/src/common.h +10 -10
- {bjdata-0.5.0 → bjdata-0.5.1}/src/decoder.c +382 -257
- {bjdata-0.5.0 → bjdata-0.5.1}/src/decoder.h +10 -10
- {bjdata-0.5.0 → bjdata-0.5.1}/src/encoder.c +188 -136
- {bjdata-0.5.0 → bjdata-0.5.1}/src/encoder.h +9 -9
- {bjdata-0.5.0 → bjdata-0.5.1}/src/markers.h +1 -1
- bjdata-0.5.1/src/numpyapi.h +84 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/src/python_funcs.c +84 -77
- {bjdata-0.5.0 → bjdata-0.5.1}/src/python_funcs.h +4 -4
- bjdata-0.5.1/test/test.py +1250 -0
- bjdata-0.5.0/CHANGELOG +0 -8
- bjdata-0.5.0/setup.py +0 -124
- bjdata-0.5.0/test/test.py +0 -805
- {bjdata-0.5.0 → bjdata-0.5.1}/LICENSE +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/MANIFEST.in +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/NOTICE +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/UBJSON-Specification.md +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata.egg-info/dependency_links.txt +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata.egg-info/not-zip-safe +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata.egg-info/requires.txt +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/bjdata.egg-info/top_level.txt +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/ez_setup.py +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/pyproject.toml +0 -0
- {bjdata-0.5.0 → bjdata-0.5.1}/setup.cfg +0 -0
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
Binary JData: A portable interchange format for complex binary data
|
|
2
2
|
============================================================
|
|
3
3
|
|
|
4
|
-
- **Status of this document**: Request for comments
|
|
5
4
|
- **Maintainer**: Qianqian Fang <q.fang at neu.edu>
|
|
6
5
|
- **License**: Apache License, Version 2.0
|
|
7
|
-
- **Version**: 1 (Draft
|
|
8
|
-
- **
|
|
6
|
+
- **Version**: 1 (Draft 3)
|
|
7
|
+
- **URL**: https://neurojson.org/bjdata/draft3
|
|
8
|
+
- **Status**: Frozen on March 23, 2025. For future updates, please see the Development URL below
|
|
9
|
+
- **Development**: https://github.com/NeuroJSON/bjdata
|
|
10
|
+
- **Acknowledgement**: This project is supported by US National Institute of Health (NIH)
|
|
11
|
+
grant [U24-NS124027 (NeuroJSON)](https://neurojson.org)
|
|
9
12
|
- **Abstract**:
|
|
10
13
|
|
|
11
14
|
> The Binary JData (BJData) Specification defines an efficient serialization
|
|
12
15
|
protocol for unambiguously storing complex and strongly-typed binary data found
|
|
13
16
|
in diverse applications. The BJData specification is the binary counterpart
|
|
14
17
|
to the JSON format, both of which are used to serialize complex data structures
|
|
15
|
-
supported by the JData specification (
|
|
16
|
-
derived and extended from the Universal Binary JSON (UBJSON,
|
|
18
|
+
supported by the JData specification (https://neurojson.org/jdata). The BJData spec is
|
|
19
|
+
derived and extended from the Universal Binary JSON (UBJSON, https://ubjson.org)
|
|
17
20
|
specification (Draft 12). It adds supports for N-dimensional packed arrays and
|
|
18
21
|
extended binary data types.
|
|
19
22
|
|
|
@@ -45,31 +48,32 @@ backends, medical imaging, and scientific data storage.
|
|
|
45
48
|
The lack of support for strongly-typed and binary data has been one of the main
|
|
46
49
|
barriers towards widespread adoption of JSON in these domains. In recent years,
|
|
47
50
|
efforts to address these limitation have resulted in an array of versatile binary
|
|
48
|
-
JSON formats, such as BSON (Binary JSON,
|
|
49
|
-
JSON,
|
|
51
|
+
JSON formats, such as BSON (Binary JSON, https://bson.org), UBJSON (Universal Binary
|
|
52
|
+
JSON, https://ubjson.org), MessagePack (https://msgpack.org), CBOR (Concise Binary
|
|
50
53
|
Object Representation, [RFC 7049], https://cbor.io) etc. These binary JSON
|
|
51
54
|
counterparts are broadly used in speed-sensitive data processing applications and
|
|
52
55
|
address various needs from a diverse range of applications.
|
|
53
56
|
|
|
54
57
|
To better champion findable, accessible, interoperable, and reusable
|
|
55
58
|
([FAIR principle](https://www.nature.com/articles/sdata201618)) data in
|
|
56
|
-
scientific data storage and management, we have created the **
|
|
57
|
-
(
|
|
59
|
+
scientific data storage and management, we have created the **NeuroJSON Project**
|
|
60
|
+
(https://neurojson.org) to develop a set of open-standards for portable, human-readable
|
|
58
61
|
and high-performance data annotation and serialization aimed towards enabling
|
|
59
|
-
scientific researchers, IT engineers, as well as general
|
|
60
|
-
annotate and store complex data structures arising
|
|
62
|
+
neuroimaging researchers, scientific researchers, IT engineers, as well as general
|
|
63
|
+
data users to efficiently annotate and store complex data structures arising
|
|
64
|
+
from diverse applications.
|
|
61
65
|
|
|
62
|
-
The
|
|
66
|
+
The NeuroJSON data sharing framework first converts complex data structures, such as N-D
|
|
63
67
|
arrays, trees, tables and graphs, into easy-to-serialize, portable data annotations
|
|
64
68
|
via the **JData Specification** (https://github.com/NeuroJSON/jdata) and then serializes
|
|
65
69
|
and stores the annotated JData constructs using widely-supported data formats.
|
|
66
|
-
To balance data portability, readability and efficiency,
|
|
70
|
+
To balance data portability, readability and efficiency, NeuroJSON defines a
|
|
67
71
|
**dual-interface**: a text-based format **syntactically compatible with JSON**,
|
|
68
72
|
and a binary-JSON format to achieve significantly smaller file sizes and faster
|
|
69
73
|
encoding/decoding.
|
|
70
74
|
|
|
71
75
|
The Binary JData (BJData) format is the **official binary interface** for the JData
|
|
72
|
-
|
|
76
|
+
Specification. It is derived from the widely supported UBJSON Specification
|
|
73
77
|
Draft 12 (https://github.com/ubjson/universal-binary-json), and adds native
|
|
74
78
|
support for **N-dimensional packed arrays** - an essential data structure for
|
|
75
79
|
scientific applications - as well as extended binary data types, including unsigned
|
|
@@ -95,7 +99,7 @@ License
|
|
|
95
99
|
------------------------------
|
|
96
100
|
|
|
97
101
|
The Binary JData Specification is licensed under the
|
|
98
|
-
[Apache 2.0 License](
|
|
102
|
+
[Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.html).
|
|
99
103
|
|
|
100
104
|
|
|
101
105
|
Format Specification
|
|
@@ -116,7 +120,7 @@ the data following it.
|
|
|
116
120
|
`uint16`, `int16`, `uint32`, `int32`, `uint64` or `int64`) specifying the length
|
|
117
121
|
of the following data payload.
|
|
118
122
|
|
|
119
|
-
- **data** (_optional_) - A contiguous byte-stream containing serialized binary
|
|
123
|
+
- **data** (_optional_) - A contiguous byte-stream containing serialized binary
|
|
120
124
|
data representing the actual binary data for this type of value.
|
|
121
125
|
|
|
122
126
|
### Notes
|
|
@@ -170,6 +174,7 @@ Type | Total size | ASCII Marker(s) | Length required | Data (payload)
|
|
|
170
174
|
[float64/double](#value_numeric) | 9 bytes | *D* | No | Yes
|
|
171
175
|
[high-precision number](#value_numeric) | 1 byte + int num val + string byte len | *H* | Yes | Yes
|
|
172
176
|
[char](#value_char) | 2 bytes | *C* | No | Yes
|
|
177
|
+
[byte](#value_byte) | 2 bytes | *B* | No | Yes
|
|
173
178
|
[string](#value_string) | 1 byte + int num val + string byte len | *S* | Yes | Yes (if not empty)
|
|
174
179
|
[array](#container_array) | 2+ bytes | *\[* and *\]* | Optional | Yes (if not empty)
|
|
175
180
|
[object](#container_object) | 2+ bytes | *{* and *}* | Optional | Yes (if not empty)
|
|
@@ -246,8 +251,8 @@ uint32| Yes | 0 | 4,294,967,295
|
|
|
246
251
|
int64 | No | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807
|
|
247
252
|
uint64| Yes | 0 | 18,446,744,073,709,551,615
|
|
248
253
|
float16/half | Yes | See [IEEE 754 Spec](https://en.wikipedia.org/wiki/IEEE_754-2008_revision) | See [IEEE 754 Spec](https://en.wikipedia.org/wiki/IEEE_754-2008_revision)
|
|
249
|
-
float32/single | Yes | See [IEEE 754 Spec](
|
|
250
|
-
float64/double | Yes | See [IEEE 754 Spec](
|
|
254
|
+
float32/single | Yes | See [IEEE 754 Spec](https://en.wikipedia.org/wiki/IEEE_754-1985) | See [IEEE 754 Spec](https://en.wikipedia.org/wiki/IEEE_754-1985)
|
|
255
|
+
float64/double | Yes | See [IEEE 754 Spec](https://en.wikipedia.org/wiki/IEEE_754-1985) | See [IEEE 754 Spec](https://en.wikipedia.org/wiki/IEEE_754-1985)
|
|
251
256
|
high-precision number | Yes | Infinite | Infinite
|
|
252
257
|
|
|
253
258
|
**Notes**:
|
|
@@ -263,7 +268,7 @@ integers are written in Big-Endian order).
|
|
|
263
268
|
|
|
264
269
|
#### Float
|
|
265
270
|
All float types (`half`, `single`, `double` are written in **Little-Endian order**
|
|
266
|
-
(this is different from UBJSON which does not specify the
|
|
271
|
+
(this is different from UBJSON which does not specify the Endianness of floats).
|
|
267
272
|
|
|
268
273
|
- `float16` or half-precision values are written in [IEEE 754 half precision floating point
|
|
269
274
|
format](https://en.wikipedia.org/wiki/IEEE_754-2008_revision), which has the following
|
|
@@ -273,14 +278,14 @@ structure:
|
|
|
273
278
|
- Bit 9-0 (10 bits) - fraction (significant)
|
|
274
279
|
|
|
275
280
|
- `float32` or single-precision values are written in [IEEE 754 single precision floating point
|
|
276
|
-
format](
|
|
281
|
+
format](https://en.wikipedia.org/wiki/IEEE_754-1985), which has the following
|
|
277
282
|
structure:
|
|
278
283
|
- Bit 31 (1 bit) - sign
|
|
279
284
|
- Bit 30-23 (8 bits) - exponent
|
|
280
285
|
- Bit 22-0 (23 bits) - fraction (significant)
|
|
281
286
|
|
|
282
287
|
- `float64` or double-precision values are written in [IEEE 754 double precision floating point
|
|
283
|
-
format](
|
|
288
|
+
format](https://en.wikipedia.org/wiki/IEEE_754-1985), which has the following
|
|
284
289
|
structure:
|
|
285
290
|
- Bit 63 (1 bit) - sign
|
|
286
291
|
- Bit 62-52 (11 bits) - exponent
|
|
@@ -290,7 +295,7 @@ structure:
|
|
|
290
295
|
#### High-Precision
|
|
291
296
|
These are encoded as a string and thus are only limited by the maximum string
|
|
292
297
|
size. Values **must** be written out in accordance with the original [JSON
|
|
293
|
-
number type specification](
|
|
298
|
+
number type specification](https://json.org).
|
|
294
299
|
|
|
295
300
|
#### Examples
|
|
296
301
|
Numeric values in JSON:
|
|
@@ -353,6 +358,33 @@ BJData (using block-notation):
|
|
|
353
358
|
[}]
|
|
354
359
|
```
|
|
355
360
|
|
|
361
|
+
---
|
|
362
|
+
### <a name="value_byte"/>Byte
|
|
363
|
+
The `byte` type in BJData is functionally identical to the `uint8` type,
|
|
364
|
+
but semantically is meant to represent a byte and not a numeric value. In
|
|
365
|
+
particular, when used as the strong type of an array container it provides
|
|
366
|
+
a hint to the parser that an optimized data storage format may be used as
|
|
367
|
+
opposed to a generic array of integers.
|
|
368
|
+
|
|
369
|
+
See also [optimized format](#container_optimized) below.
|
|
370
|
+
|
|
371
|
+
#### Example
|
|
372
|
+
Byte values in JSON:
|
|
373
|
+
```json
|
|
374
|
+
{
|
|
375
|
+
"binary": [222, 173, 190, 239]
|
|
376
|
+
"val": 123,
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
BJData (using block-notation):
|
|
381
|
+
```
|
|
382
|
+
[{]
|
|
383
|
+
[i][6][binary] [[] [$][B] [#][i][4] [222][173][190][239]
|
|
384
|
+
[i][3][val][B][123]
|
|
385
|
+
[}]
|
|
386
|
+
```
|
|
387
|
+
|
|
356
388
|
---
|
|
357
389
|
### <a name="value_string"/>String
|
|
358
390
|
The `string` type in BJData is equivalent to the `string` type from the JSON
|
|
@@ -457,17 +489,17 @@ thought of as providing the ability to create a strongly-typed container in BJDa
|
|
|
457
489
|
|
|
458
490
|
A major different between BJData and UBJSON is that the _type_ in a BJData
|
|
459
491
|
strongly-typed container is limited to **non-zero-fixed-length data types**, therefore,
|
|
460
|
-
only integers (`i,U,I,u,l,m,L,M`), floating-point numbers (`h,d,D`)
|
|
492
|
+
only integers (`i,U,I,u,l,m,L,M`), floating-point numbers (`h,d,D`), char (`C`) and byte (`B`)
|
|
461
493
|
are qualified. All zero-length types (`T,F,Z,N`), variable-length types(`S, H`)
|
|
462
494
|
and container types (`[,{`) shall not be used in an optimized _type_ header.
|
|
463
495
|
This restriction is set to reduce the security risks due to potentials of
|
|
464
496
|
buffer-overflow attacks using [zero-length markers](https://github.com/nlohmann/json/issues/2793),
|
|
465
|
-
hampered readability and
|
|
497
|
+
hampered readability and diminished benefit using variable/container
|
|
466
498
|
types in an optimized format.
|
|
467
499
|
|
|
468
500
|
The requirements for _type_ are
|
|
469
501
|
|
|
470
|
-
- If a _type_ is specified, it **must** be one of `i,U,I,u,l,m,L,M,h,d,D,C`.
|
|
502
|
+
- If a _type_ is specified, it **must** be one of `i,U,I,u,l,m,L,M,h,d,D,C,B`.
|
|
471
503
|
- If a _type_ is specified, it **must** be done so before a _count_.
|
|
472
504
|
- If a _type_ is specified, a _count_ **must** be specified as well. (Otherwise
|
|
473
505
|
it is impossible to tell when a container is ending, e.g. did you just parse
|
|
@@ -493,6 +525,14 @@ bytes while parsing.
|
|
|
493
525
|
[#][i][64]
|
|
494
526
|
```
|
|
495
527
|
|
|
528
|
+
### Optimized binary array
|
|
529
|
+
When an array of _type_ `B` is specified the parser shall use an optimized data storage
|
|
530
|
+
format to represent binary data where applicable, as opposed to a generic array of integers.
|
|
531
|
+
Similarly, explicit binary data should be serialized as such to allow for parsers to
|
|
532
|
+
make use of the optimization.
|
|
533
|
+
|
|
534
|
+
If such a data storage format is not available, an array of integers shall be used.
|
|
535
|
+
|
|
496
536
|
### Optimized N-dimensional array of uniform type
|
|
497
537
|
When both _type_ and _count_ are specified and the _count_ marker `#` is followed
|
|
498
538
|
by `[`, the parser should expect the following sequence to be a 1-D `array` with
|
|
@@ -514,6 +554,19 @@ all non-negative numbers specifying the dimensions of the N-dimensional array.
|
|
|
514
554
|
The binary data of the N-dimensional array is then serialized into a 1-D vector
|
|
515
555
|
in the **row-major** element order (similar to C, C++, Javascript or Python) .
|
|
516
556
|
|
|
557
|
+
To store an N-dimensional array that is serialized using the **column-major** element
|
|
558
|
+
order (as used in MATLAB and FORTRAN), the _count_ marker `#` should be followed by
|
|
559
|
+
an array of a single element, which must be a 1-D array of integer type as the
|
|
560
|
+
dimensional vector above. Either of the arrays can be in optimized or non-optimized
|
|
561
|
+
form. For example, either of the following
|
|
562
|
+
|
|
563
|
+
```
|
|
564
|
+
[[] [$] [type] [#] [[] [[] [$] [Nx type] [#] [Ndim type] [Ndim] [Nx Ny Nz ...] []] [a11 a21 a31 ... a21 a22 ...]
|
|
565
|
+
or
|
|
566
|
+
[[] [$] [type] [#] [[] [[] [Nx type] [nx] [Ny type] [Ny] [Nz type] [Nz] ... []] []] [a11 a21 a31 ... a21 a22 ...]
|
|
567
|
+
```
|
|
568
|
+
represents the same column-major N-dimensional array of `type` and size `[Nx, Ny, Nz, ...]`.
|
|
569
|
+
|
|
517
570
|
|
|
518
571
|
#### Example (a 2x3x4 `uint8` array):
|
|
519
572
|
The following 2x3x4 3-D `uint8` array
|
|
@@ -531,22 +584,26 @@ The following 2x3x4 3-D `uint8` array
|
|
|
531
584
|
]
|
|
532
585
|
]
|
|
533
586
|
```
|
|
534
|
-
shall be stored as
|
|
587
|
+
shall be stored using **row-major** serialized form as
|
|
535
588
|
```
|
|
536
589
|
[[] [$][U] [#][[] [$][U][#][3] [2][3][4]
|
|
537
590
|
[1][9][6][0] [2][9][3][1] [8][0][9][6] [6][4][2][7] [8][5][1][2] [3][3][2][6]
|
|
538
591
|
```
|
|
539
|
-
|
|
592
|
+
or **column-major** serialized form as
|
|
593
|
+
```
|
|
594
|
+
[[] [$][U] [#][[] [[] [$][U][#][3] [2][3][4] []]
|
|
595
|
+
[1][6][2][8] [8][3][9][4] [9][5][0][3] [6][2][3][1] [9][2][0][7] [1][2][6][6]
|
|
596
|
+
```
|
|
540
597
|
|
|
541
598
|
### Additional rules
|
|
542
599
|
- A _count_ **must** be >= 0.
|
|
543
|
-
- A _count_ can be specified
|
|
600
|
+
- A _count_ can be specified alone.
|
|
544
601
|
- If a _count_ is specified, the container **must not** specify an end-marker.
|
|
545
602
|
- A container that specifies a _count_ **must** contain the specified number of
|
|
546
603
|
child elements.
|
|
547
604
|
- If a _type_ is specified, it **must** be done so before _count_.
|
|
548
605
|
- If a _type_ is specified, a _count_ **must** also be specified. A _type_
|
|
549
|
-
cannot be specified
|
|
606
|
+
cannot be specified alone.
|
|
550
607
|
- A container that specifies a _type_ **must not** contain any additional
|
|
551
608
|
_type_ markers for any contained value.
|
|
552
609
|
|
|
@@ -601,13 +658,13 @@ The MIME type for a Binary JData document is **`"application/jdata-binary"`**
|
|
|
601
658
|
Acknowledgement
|
|
602
659
|
------------------------------
|
|
603
660
|
|
|
604
|
-
The BJData spec is derived from the Universal Binary JSON (UBJSON,
|
|
661
|
+
The BJData spec is derived from the Universal Binary JSON (UBJSON, https://ubjson.org)
|
|
605
662
|
specification (Draft 12) developed by Riyad Kalla and other UBJSON contributors.
|
|
606
663
|
|
|
607
664
|
The initial version of this MarkDown-formatted specification was derived from the
|
|
608
665
|
documentation included in the [Py-UBJSON](https://github.com/Iotic-Labs/py-ubjson/blob/dev-contrib/UBJSON-Specification.md)
|
|
609
666
|
repository (Commit 5ce1fe7).
|
|
610
667
|
|
|
611
|
-
This specification was developed as part of the NeuroJSON project (
|
|
668
|
+
This specification was developed as part of the NeuroJSON project (https://neurojson.org)
|
|
612
669
|
with funding support from the US National Institute of Health (NIH) under
|
|
613
670
|
grant [U24-NS124027](https://reporter.nih.gov/project-details/10308329).
|
bjdata-0.5.1/CHANGELOG
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
0.5.0
|
|
2
|
+
- 2025-07-26 support BJData Spec Draft 3 (PR #5, thanks to Nebojsa Cvetkovic)
|
|
3
|
+
- 2025-07-27 compatible with numpy 2.x, fully reformat C and python code with formatter
|
|
4
|
+
|
|
5
|
+
0.4.1
|
|
6
|
+
- 2023-10-25 fix numpy 1d array length encoding bug, fix #4
|
|
7
|
+
|
|
8
|
+
0.4.0
|
|
9
|
+
- 2022-09-04 add numpy ndarray/scalar encoding/decoding, fix pip ext compilation error, thanks to @termanis
|
|
10
|
+
|
|
11
|
+
0.3.0
|
|
12
|
+
- 2022-04-01 support BJData Spec Draft 2, change to little-endian for numbers
|
|
13
|
+
|
|
14
|
+
0.2.6
|
|
15
|
+
- 2020-07-23 debian packaging
|
|
16
|
+
|
|
17
|
+
0.2.5
|
|
18
|
+
- 2020-07-12 initial release of pybj based on py-ubjson version 0.16.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: bjdata
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Binary JData and UBJSON encoder/decoder
|
|
5
5
|
Home-page: https://github.com/NeuroJSON/pybj
|
|
6
6
|
Author: Qianqian Fang
|
|
@@ -32,6 +32,20 @@ Requires-Dist: numpy>=1.8.0
|
|
|
32
32
|
Provides-Extra: dev
|
|
33
33
|
Requires-Dist: Pympler<0.8,>=0.7; extra == "dev"
|
|
34
34
|
Requires-Dist: coverage<4.6,>=4.5.3; extra == "dev"
|
|
35
|
+
Dynamic: author
|
|
36
|
+
Dynamic: author-email
|
|
37
|
+
Dynamic: classifier
|
|
38
|
+
Dynamic: description
|
|
39
|
+
Dynamic: description-content-type
|
|
40
|
+
Dynamic: home-page
|
|
41
|
+
Dynamic: keywords
|
|
42
|
+
Dynamic: license
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
Dynamic: maintainer
|
|
45
|
+
Dynamic: maintainer-email
|
|
46
|
+
Dynamic: provides-extra
|
|
47
|
+
Dynamic: requires-dist
|
|
48
|
+
Dynamic: summary
|
|
35
49
|
|
|
36
50
|

|
|
37
51
|
|
|
@@ -40,7 +54,7 @@ Requires-Dist: coverage<4.6,>=4.5.3; extra == "dev"
|
|
|
40
54
|
- Copyright: (C) Qianqian Fang (2020-2025) <q.fang at neu.edu>
|
|
41
55
|
- Copyright: (C) Iotic Labs Ltd. (2016-2019) <vilnis.termanis at iotic-labs.com>
|
|
42
56
|
- License: Apache License, Version 2.0
|
|
43
|
-
- Version: 0.5.
|
|
57
|
+
- Version: 0.5.1
|
|
44
58
|
- URL: https://pypi.org/project/bjdata/
|
|
45
59
|
- Github: https://github.com/NeuroJSON/pybj
|
|
46
60
|
- BJData Spec Version: [V1 Draft 3](https://neurojson.org/bjdata/draft3)
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- Copyright: (C) Qianqian Fang (2020-2025) <q.fang at neu.edu>
|
|
6
6
|
- Copyright: (C) Iotic Labs Ltd. (2016-2019) <vilnis.termanis at iotic-labs.com>
|
|
7
7
|
- License: Apache License, Version 2.0
|
|
8
|
-
- Version: 0.5.
|
|
8
|
+
- Version: 0.5.1
|
|
9
9
|
- URL: https://pypi.org/project/bjdata/
|
|
10
10
|
- Github: https://github.com/NeuroJSON/pybj
|
|
11
11
|
- BJData Spec Version: [V1 Draft 3](https://neurojson.org/bjdata/draft3)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (c) 2020-
|
|
1
|
+
# Copyright (c) 2020-2025 Qianqian Fang <q.fang at neu.edu>. All rights reserved.
|
|
2
2
|
# Copyright (c) 2016-2019 Iotic Labs Ltd. All rights reserved.
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -29,15 +29,25 @@ To use a file-like object as input/output, use dump() & load() methods instead.
|
|
|
29
29
|
|
|
30
30
|
try:
|
|
31
31
|
from _bjdata import dump, dumpb, load, loadb
|
|
32
|
+
|
|
32
33
|
EXTENSION_ENABLED = True
|
|
33
34
|
except ImportError: # pragma: no cover
|
|
34
35
|
from .encoder import dump, dumpb
|
|
35
36
|
from .decoder import load, loadb
|
|
37
|
+
|
|
36
38
|
EXTENSION_ENABLED = False
|
|
37
39
|
|
|
38
40
|
from .encoder import EncoderException
|
|
39
41
|
from .decoder import DecoderException
|
|
40
42
|
|
|
41
|
-
__version__ =
|
|
42
|
-
|
|
43
|
-
__all__ = (
|
|
43
|
+
__version__ = "0.5.1"
|
|
44
|
+
|
|
45
|
+
__all__ = (
|
|
46
|
+
"EXTENSION_ENABLED",
|
|
47
|
+
"dump",
|
|
48
|
+
"dumpb",
|
|
49
|
+
"EncoderException",
|
|
50
|
+
"load",
|
|
51
|
+
"loadb",
|
|
52
|
+
"DecoderException",
|
|
53
|
+
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (c) 2020-
|
|
1
|
+
# Copyright (c) 2020-2025 Qianqian Fang <q.fang at neu.edu>. All rights reserved.
|
|
2
2
|
# Copyright (c) 2016-2019 Iotic Labs Ltd. All rights reserved.
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -33,67 +33,70 @@ def from_json(in_stream, out_stream):
|
|
|
33
33
|
try:
|
|
34
34
|
obj = jload(in_stream, object_pairs_hook=OrderedDict)
|
|
35
35
|
except ValueError as ex:
|
|
36
|
-
__error(
|
|
36
|
+
__error("Failed to decode json: %s" % ex)
|
|
37
37
|
return 8
|
|
38
38
|
try:
|
|
39
39
|
bjdump(obj, out_stream, sort_keys=False)
|
|
40
40
|
except EncoderException as ex:
|
|
41
|
-
__error(
|
|
41
|
+
__error("Failed to encode to bjdata: %s" % ex)
|
|
42
42
|
return 16
|
|
43
43
|
return 0
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def to_json(in_stream, out_stream):
|
|
47
47
|
try:
|
|
48
|
-
obj = bjload(in_stream, intern_object_keys=True,object_pairs_hook=OrderedDict)
|
|
48
|
+
obj = bjload(in_stream, intern_object_keys=True, object_pairs_hook=OrderedDict)
|
|
49
49
|
except DecoderException as ex:
|
|
50
|
-
__error(
|
|
50
|
+
__error("Failed to decode bjdata: %s" % ex)
|
|
51
51
|
return 8
|
|
52
52
|
try:
|
|
53
|
-
jdump(obj, out_stream, sort_keys=False, separators=(
|
|
53
|
+
jdump(obj, out_stream, sort_keys=False, separators=(",", ":"))
|
|
54
54
|
except TypeError as ex:
|
|
55
|
-
__error(
|
|
55
|
+
__error("Failed to encode to json: %s" % ex)
|
|
56
56
|
return 16
|
|
57
57
|
return 0
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
__ACTION = frozenset((
|
|
60
|
+
__ACTION = frozenset(("fromjson", "tojson"))
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
def main():
|
|
64
64
|
if not (3 <= len(argv) <= 4 and argv[1] in __ACTION):
|
|
65
|
-
print(
|
|
65
|
+
print(
|
|
66
|
+
"""USAGE: bjdata (fromjson|tojson) (INFILE|-) [OUTFILE]
|
|
66
67
|
|
|
67
68
|
Converts an objects between json and bjdata formats. Input is read from INFILE
|
|
68
69
|
unless set to '-', in which case stdin is used. If OUTFILE is not
|
|
69
|
-
specified, output goes to stdout.""",
|
|
70
|
+
specified, output goes to stdout.""",
|
|
71
|
+
file=stderr,
|
|
72
|
+
)
|
|
70
73
|
return 1
|
|
71
74
|
|
|
72
|
-
do_from_json =
|
|
75
|
+
do_from_json = argv[1] == "fromjson"
|
|
73
76
|
in_file = out_file = None
|
|
74
77
|
try:
|
|
75
78
|
# input
|
|
76
|
-
if argv[2] ==
|
|
79
|
+
if argv[2] == "-":
|
|
77
80
|
in_stream = stdin if do_from_json else STDIN_RAW
|
|
78
81
|
else:
|
|
79
82
|
try:
|
|
80
|
-
in_stream = in_file = open(argv[2],
|
|
83
|
+
in_stream = in_file = open(argv[2], "r" if do_from_json else "rb")
|
|
81
84
|
except IOError as ex:
|
|
82
|
-
__error(
|
|
85
|
+
__error("Failed to open input file for reading: %s" % ex)
|
|
83
86
|
return 2
|
|
84
87
|
# output
|
|
85
88
|
if len(argv) == 3:
|
|
86
89
|
out_stream = STDOUT_RAW if do_from_json else stdout
|
|
87
90
|
else:
|
|
88
91
|
try:
|
|
89
|
-
out_stream = out_file = open(argv[3],
|
|
92
|
+
out_stream = out_file = open(argv[3], "wb" if do_from_json else "w")
|
|
90
93
|
except IOError as ex:
|
|
91
|
-
__error(
|
|
94
|
+
__error("Failed to open output file for writing: %s" % ex)
|
|
92
95
|
return 4
|
|
93
96
|
|
|
94
97
|
return (from_json if do_from_json else to_json)(in_stream, out_stream)
|
|
95
98
|
except IOError as ex:
|
|
96
|
-
__error(
|
|
99
|
+
__error("I/O failure: %s" % ex)
|
|
97
100
|
finally:
|
|
98
101
|
if in_file:
|
|
99
102
|
in_file.close()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (c) 2020-
|
|
1
|
+
# Copyright (c) 2020-2025 Qianqian Fang <q.fang at neu.edu>. All rights reserved.
|
|
2
2
|
# Copyright (c) 2016-2019 Iotic Labs Ltd. All rights reserved.
|
|
3
3
|
#
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|
from sys import stderr, stdout, stdin, version_info
|
|
45
45
|
|
|
46
|
-
PY2 =
|
|
46
|
+
PY2 = version_info[0] == 2
|
|
47
47
|
|
|
48
48
|
if PY2:
|
|
49
49
|
# pylint: disable=undefined-variable
|
|
@@ -66,9 +66,9 @@ else:
|
|
|
66
66
|
TEXT_TYPES = (str,)
|
|
67
67
|
BYTES_TYPES = (bytes, bytearray)
|
|
68
68
|
|
|
69
|
-
STDIN_RAW = getattr(stdin,
|
|
70
|
-
STDOUT_RAW = getattr(stdout,
|
|
71
|
-
STDERR_RAW = getattr(stderr,
|
|
69
|
+
STDIN_RAW = getattr(stdin, "buffer", stdin)
|
|
70
|
+
STDOUT_RAW = getattr(stdout, "buffer", stdout)
|
|
71
|
+
STDERR_RAW = getattr(stderr, "buffer", stderr)
|
|
72
72
|
from sys import intern as intern_unicode # noqa: F401
|
|
73
73
|
|
|
74
74
|
try:
|
|
@@ -80,16 +80,21 @@ except ImportError:
|
|
|
80
80
|
|
|
81
81
|
if version_info[:2] == (3, 2):
|
|
82
82
|
# pylint: disable=exec-used
|
|
83
|
-
exec(
|
|
83
|
+
exec(
|
|
84
|
+
"""def raise_from(value, from_value):
|
|
84
85
|
if from_value is None:
|
|
85
86
|
raise value
|
|
86
87
|
raise value from from_value
|
|
87
|
-
"""
|
|
88
|
+
"""
|
|
89
|
+
)
|
|
88
90
|
elif version_info[:2] > (3, 2):
|
|
89
91
|
# pylint: disable=exec-used
|
|
90
|
-
exec(
|
|
92
|
+
exec(
|
|
93
|
+
"""def raise_from(value, from_value):
|
|
91
94
|
raise value from from_value
|
|
92
|
-
"""
|
|
95
|
+
"""
|
|
96
|
+
)
|
|
93
97
|
else:
|
|
98
|
+
|
|
94
99
|
def raise_from(value, _):
|
|
95
100
|
raise value
|