├── APACHE-2.0.txt
├── README.md
├── SConstruct
├── build
├── fromcsv
│ └── fromcsv.vcxproj
├── fromjson
│ ├── fromjson.sln
│ ├── fromjson.vcxproj
│ └── fromjson.vcxproj.filters
└── hex
│ └── hex.vcxproj
├── doc
├── bson.md
├── fromxml.md
└── hex.md
├── src
├── bsontools
│ ├── binary.h
│ ├── bsonmain.cpp
│ ├── cmdline.h
│ ├── fromcsv.cpp
│ ├── fromjson.cpp
│ ├── fromxml.cpp
│ ├── hex.cpp
│ ├── parse_types.h
│ └── stdin.h
└── util
│ └── str.h
└── test
└── test.xml
/APACHE-2.0.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | These are simple utilities for manipulation of bson documents.
2 |
3 | * bson - main utility. Try bson --help
4 | * fromjson - convert JSON to BSON
5 | * fromcsv - convert CSV to BSON
6 | * fromxml - convert XML to BSON
7 | * hex - hex dump of any input, with a tiny bit of bson format awareness.
8 | also provided as a convenience for any OS where 'hexdump' is not already present.
9 |
10 | Note: Many of these utilities expect input from stdin, to facilitate piping. Use -h to get help.
11 |
12 | ## Documentation
13 |
14 | See the [doc/](doc) folder.
15 |
16 | ## Building
17 |
18 | You will need the [bson-cxx](https://github.com/dwight/bson-cxx) library (a dependancy) to build the tools. It is available on github.
19 |
20 | Place it as a peer level directory on disk with bsontools. (That is you will see lines such as `#include "../../../bson-cxx/"` in the source code of these tools...)
21 |
22 | To build with scons, assuming it is installed, just type "scons".
23 |
24 | With Visual Studio, start by opening build/fromjson/fronjson.sln. The tools have been built and tested with Visual Studio 2013.
25 |
26 | As written, these tools lightly use C++11. This is mainly to avoid any external dependencies; for
27 | example unique_ptr is used from C++11. The usage is light enough you should not need a very new compiler. It would not be hard to adapt back to C++03. Use `-std=c++0x` on the command line, which the SConscript file does for you...
28 |
29 | ### Prebuilt binaries
30 |
31 | Some can be found at [https://github.com/dwight/binaries](https://github.com/dwight/binaries).
32 |
33 | ## Licence
34 |
35 | Apache 2.0.
36 |
37 | ## Contributions
38 |
39 | Send a pull request on github, thanks. We'll pull in things that we think fit although the goal is to keep things tidy and small. Of course you can always fork if you want to create something different.
40 |
41 | Some automated tests would be real helpful for example...
42 |
43 | ## Support
44 |
45 | For help try posting to the [BSON Google Groups forum](https://groups.google.com/forum/#!forum/bson).
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/SConstruct:
--------------------------------------------------------------------------------
1 | env = Environment()
2 |
3 | env.Append(CCFLAGS='-std=c++0x')
4 |
5 | # env.Program(target = 'hex', source = ["src/bsontools/hex.cpp"])
6 |
7 | env.Program(target = 'hex', source = ["src/bsontools/hex.cpp"])
8 |
9 | dep1 = [
10 | "../bson-cxx/src/bson/time_support.cpp",
11 | "../bson-cxx/src/bson/bson.cpp",
12 | "../bson-cxx/src/bson/parse_number.cpp" ]
13 |
14 | dep2 = [
15 | "../bson-cxx/src/bson/json.cpp",
16 | "../bson-cxx/src/bson/base64.cpp"
17 | ]
18 |
19 | env.Program(target = 'fromcsv', source = ["src/bsontools/fromcsv.cpp"] + dep1)
20 |
21 | env.Program(target = 'fromjson', source = ["src/bsontools/fromjson.cpp"] + dep1 + dep2)
22 |
23 | env.Program(target = 'fromxml', source = ["src/bsontools/fromxml.cpp"] + dep1)
24 |
25 | env.Program(target = 'bson', source = ["src/bsontools/bsonmain.cpp"] + dep1 + dep2)
26 |
--------------------------------------------------------------------------------
/build/fromcsv/fromcsv.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {8A26B3AF-95B8-44C0-8AEE-1C3108102466}
15 | Win32Proj
16 | fromcsv
17 |
18 |
19 |
20 | Application
21 | true
22 | v120
23 | Unicode
24 |
25 |
26 | Application
27 | false
28 | v120
29 | true
30 | Unicode
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 |
45 |
46 | false
47 |
48 |
49 |
50 |
51 |
52 | Level3
53 | Disabled
54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
55 | true
56 |
57 |
58 | Console
59 | true
60 |
61 |
62 |
63 |
64 | Level3
65 |
66 |
67 | MaxSpeed
68 | true
69 | true
70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
71 | true
72 |
73 |
74 | Console
75 | true
76 | true
77 | true
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/build/fromjson/fromjson.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30501.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fromjson", "fromjson.vcxproj", "{B3EB1C1F-AB6D-40D1-91B4-942CBC0C2B68}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hex", "..\hex\hex.vcxproj", "{611CB369-3FF0-4F24-956F-C76E07856CE9}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9A3B428C-5FB4-4023-AF79-7CA8EE07214C}"
11 | ProjectSection(SolutionItems) = preProject
12 | ..\..\README.md = ..\..\README.md
13 | EndProjectSection
14 | EndProject
15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bson", "..\bson\bson.vcxproj", "{E0893BE6-2391-4890-BBD3-5AD4B9ED1C15}"
16 | EndProject
17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fromcsv", "..\fromcsv\fromcsv.vcxproj", "{8A26B3AF-95B8-44C0-8AEE-1C3108102466}"
18 | EndProject
19 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fromxml", "..\fromxml\fromxml.vcxproj", "{9AC09F80-F7ED-45B4-BAB1-48B75F4616F7}"
20 | EndProject
21 | Global
22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
23 | Debug|Win32 = Debug|Win32
24 | Release|Win32 = Release|Win32
25 | EndGlobalSection
26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
27 | {B3EB1C1F-AB6D-40D1-91B4-942CBC0C2B68}.Debug|Win32.ActiveCfg = Debug|Win32
28 | {B3EB1C1F-AB6D-40D1-91B4-942CBC0C2B68}.Debug|Win32.Build.0 = Debug|Win32
29 | {B3EB1C1F-AB6D-40D1-91B4-942CBC0C2B68}.Release|Win32.ActiveCfg = Release|Win32
30 | {B3EB1C1F-AB6D-40D1-91B4-942CBC0C2B68}.Release|Win32.Build.0 = Release|Win32
31 | {611CB369-3FF0-4F24-956F-C76E07856CE9}.Debug|Win32.ActiveCfg = Debug|Win32
32 | {611CB369-3FF0-4F24-956F-C76E07856CE9}.Debug|Win32.Build.0 = Debug|Win32
33 | {611CB369-3FF0-4F24-956F-C76E07856CE9}.Release|Win32.ActiveCfg = Release|Win32
34 | {611CB369-3FF0-4F24-956F-C76E07856CE9}.Release|Win32.Build.0 = Release|Win32
35 | {E0893BE6-2391-4890-BBD3-5AD4B9ED1C15}.Debug|Win32.ActiveCfg = Debug|Win32
36 | {E0893BE6-2391-4890-BBD3-5AD4B9ED1C15}.Debug|Win32.Build.0 = Debug|Win32
37 | {E0893BE6-2391-4890-BBD3-5AD4B9ED1C15}.Release|Win32.ActiveCfg = Release|Win32
38 | {E0893BE6-2391-4890-BBD3-5AD4B9ED1C15}.Release|Win32.Build.0 = Release|Win32
39 | {8A26B3AF-95B8-44C0-8AEE-1C3108102466}.Debug|Win32.ActiveCfg = Debug|Win32
40 | {8A26B3AF-95B8-44C0-8AEE-1C3108102466}.Debug|Win32.Build.0 = Debug|Win32
41 | {8A26B3AF-95B8-44C0-8AEE-1C3108102466}.Release|Win32.ActiveCfg = Release|Win32
42 | {8A26B3AF-95B8-44C0-8AEE-1C3108102466}.Release|Win32.Build.0 = Release|Win32
43 | {9AC09F80-F7ED-45B4-BAB1-48B75F4616F7}.Debug|Win32.ActiveCfg = Debug|Win32
44 | {9AC09F80-F7ED-45B4-BAB1-48B75F4616F7}.Debug|Win32.Build.0 = Debug|Win32
45 | {9AC09F80-F7ED-45B4-BAB1-48B75F4616F7}.Release|Win32.ActiveCfg = Release|Win32
46 | {9AC09F80-F7ED-45B4-BAB1-48B75F4616F7}.Release|Win32.Build.0 = Release|Win32
47 | EndGlobalSection
48 | GlobalSection(SolutionProperties) = preSolution
49 | HideSolutionNode = FALSE
50 | EndGlobalSection
51 | EndGlobal
52 |
--------------------------------------------------------------------------------
/build/fromjson/fromjson.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | {B3EB1C1F-AB6D-40D1-91B4-942CBC0C2B68}
49 | Win32Proj
50 | fromjson
51 |
52 |
53 |
54 | Application
55 | true
56 | v120
57 | MultiByte
58 |
59 |
60 | Application
61 | false
62 | v120
63 | true
64 | MultiByte
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | true
78 |
79 |
80 | false
81 |
82 |
83 |
84 |
85 |
86 | Level3
87 | Disabled
88 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
89 | true
90 |
91 |
92 | Console
93 | true
94 |
95 |
96 |
97 |
98 | Level3
99 |
100 |
101 | MaxSpeed
102 | true
103 | true
104 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
105 | true
106 |
107 |
108 | Console
109 | true
110 | true
111 | true
112 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/build/fromjson/fromjson.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {65756162-fdb6-40ea-a7b2-5105fb9bfbfe}
18 |
19 |
20 |
21 |
22 | Source Files
23 |
24 |
25 | bson
26 |
27 |
28 | bson
29 |
30 |
31 | bson
32 |
33 |
34 | bson
35 |
36 |
37 | bson
38 |
39 |
40 | bson
41 |
42 |
43 |
44 |
45 | Header Files
46 |
47 |
48 | Header Files
49 |
50 |
51 | Header Files
52 |
53 |
54 | Header Files
55 |
56 |
57 | Header Files
58 |
59 |
60 | Header Files
61 |
62 |
63 | Header Files
64 |
65 |
66 | Header Files
67 |
68 |
69 | Header Files
70 |
71 |
72 | Header Files
73 |
74 |
75 | Header Files
76 |
77 |
78 | Header Files
79 |
80 |
81 | Header Files
82 |
83 |
84 | Header Files
85 |
86 |
87 | Header Files
88 |
89 |
90 | Header Files
91 |
92 |
93 | Header Files
94 |
95 |
96 | Header Files
97 |
98 |
99 | Header Files
100 |
101 |
102 | Header Files
103 |
104 |
105 | Header Files
106 |
107 |
108 | Header Files
109 |
110 |
111 | Header Files
112 |
113 |
114 |
--------------------------------------------------------------------------------
/build/hex/hex.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {611CB369-3FF0-4F24-956F-C76E07856CE9}
15 | Win32Proj
16 | hex
17 |
18 |
19 |
20 | Application
21 | true
22 | v120
23 | Unicode
24 |
25 |
26 | Application
27 | false
28 | v120
29 | true
30 | Unicode
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 |
45 |
46 | false
47 |
48 |
49 |
50 |
51 |
52 | Level3
53 | Disabled
54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
55 | true
56 |
57 |
58 | Console
59 | true
60 |
61 |
62 |
63 |
64 | Level3
65 |
66 |
67 | MaxSpeed
68 | true
69 | true
70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)
71 | true
72 |
73 |
74 | Console
75 | true
76 | true
77 | true
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/doc/bson.md:
--------------------------------------------------------------------------------
1 | The "bson" utility program.
2 |
3 | ## Usage
4 |
5 | bson \ \ \
6 |
7 | Options:
8 |
9 | -h for help
10 | -# emit document number instead of the document's
11 | bson content
12 | -N emit the null value rather than omitting a
13 | missing field, when applicable
14 | (e.g. with the pull command)
15 |
16 |
17 | The bson utility performs many different operations; these are specified by the \
18 | parameter. Typically, the utility takes a stream of BSON from stdin, and writes BSON to
19 | stdout. However, in some cases, it outputs text, for example, the print verb/command does
20 | that.
21 |
22 | ## Commands
23 |
24 | ### count
25 |
26 | Count number of documents in the BSON file. Also prints out the size of the largest document.
27 |
28 | $ bson count < file.bson
29 | 302 12800
30 |
31 | ### del \
32 |
33 | Delete a top level field and then reoutput the stream.
34 |
35 | $ bson del card_number < records.bson > redacted.bson
36 |
37 | ### demote \
38 |
39 | Wrap each document inside a field named , then output.
40 |
41 | For example, suppose we have a set of JSON documents of the form:
42 |
43 | { street:..., city:..., province:..., country:... }
44 | ...
45 |
46 | If we wanted this to be in a larger document we might use the demote command to "wrap" these
47 | values:
48 |
49 | bson demote addr < in.bson > out.bson
50 |
51 | If we then inspected:
52 |
53 | bson print < out.bson
54 |
55 | we would see something like:
56 |
57 | { addr : { street:..., city:..., province:..., country:... } }
58 | ...
59 |
60 | And this output could be used then with say, a merge operation.
61 |
62 | ### grep \
63 |
64 | Search for a pattern within each documents. Field values, and not the field names, are checked
65 | for a match. All matching documents are output (as BSON).
66 |
67 | $ bson grep foo < file.bson > out.bson
68 |
69 | Note: at the time of this writing, pattern can only be a simple text pattern, regular
70 | expressions are NOT yet supported (but hopefully coming).
71 |
72 | ### head [-n \] [-s \]
73 |
74 | Output the first N documents in the file. Output is BSON format.
75 |
76 | -s option: start at the specified document number (base zero).
77 |
78 | ### infer
79 |
80 | The infer command will take a stream of BSON from stdin and infer its "schema"; that is, it
81 | will report what fields are present in documents read from the stream, and the types of those
82 | fields. If a field is not always present, infer will report the percentage of the time it
83 | occurs. If a field's values have different types in different documents, infer will report
84 | this too. The output from infer is a text report.
85 |
86 | Example:
87 |
88 | $ bson infer < x.bson
89 | {
90 | a : int32
91 | b : bool 50%
92 | c : bool 50%, null 50%
93 | d : string 50%
94 | e : object {
95 | valid : bool
96 | until : date
97 | }
98 | }
99 |
100 | ### merge \
101 |
102 | Merge bson stream stdin with bson file on cmd line. Must be same number of documents in
103 | each input file.
104 |
105 | ### print
106 |
107 | $ bson print < mydata.bson
108 | *json output is displayed...*
109 |
110 | $ bson print pretty < mydata.bson
111 | *json output is displayed with indentation and line feeds...*
112 |
113 | ### project \
114 |
115 | Do projection on the input BSON, outputing the result. Only top level field names may be
116 | specified in the current implementation.
117 |
118 | $ bson project "last name","first_name",phone < customers.bson > phonelist.bson
119 |
120 | ### promote \
121 |
122 | Pull out the subobject specified by and output it (only). If the field is missing
123 | or not an object nothing will be output for that document.
124 |
125 | $ bson promote associate.address < things.bson > addresses.bson
126 |
127 | ### pull [-N] \
128 |
129 | Extract a single field as a singleton element and output.
130 |
131 | -N option: emit null rather than nothing, when applicable.
132 |
133 | Example:
134 |
135 | $ bson print < t.bson
136 | { a: 3, b: true, c: { x: 3, y: 4 } }
137 | { a: 2, c: { x: 2, y: 9 } }
138 | { c: null }
139 | { a: 1 }
140 |
141 | $ bson pull a < t.bson | bson print
142 | { a: 3 }
143 | { a: 2 }
144 | {}
145 | { a: 1 }
146 |
147 | bson pull c < t.bson | bson print
148 | { c: { x: 3, y: 4 } }
149 | { c: { x: 2, y: 9 } }
150 | { c: null }
151 | {}
152 |
153 | pull c.y < t.bson | bson print
154 | { y: 4 }
155 | { y: 9 }
156 | {}
157 | {}
158 |
159 | ### sample -\
160 |
161 | sample outputs every Nth document in the file for sampling purposes. Output is bson format.
162 |
163 | $ bson sample -n 100 < bigfile.bson > sample.bson
164 |
165 | ### tail [-n ]
166 |
167 | Output the last N documents.
168 |
169 | Note: the implementation of tail is currently not very fast.
170 |
171 | ### text
172 |
173 | Extract and output the text of each BSON document (perhaps for use then with text utilities etc.)
174 |
175 | The text from each document is output one line per document, with the text of each field tab
176 | delimited. Field names are not output. Numbers are output in their text representation.
177 |
178 | $ # how many docs contain the text "Joseph"?
179 | $ bson text < docs.bson | grep Joseph | wc
180 |
181 | ### unwind [-N] \
182 |
183 | Unwind an array of elements. This is similar to the MongoDB $unwind operator.
184 |
185 | `-N` option: emit null rather than nothing, when applicable.
186 |
187 | Example:
188 |
189 | $ fromjson > a.bson
190 | { a : 3, b : [1,2,7,8,"zzz"] }
191 | { b : [4,7] }
192 | ^Z
193 |
194 | $ bson print < a.bson
195 | { a: 3, b: [ 1, 2, 7, 8, "zzz" ] }
196 | { b: [ 4, 7 ] }
197 |
198 | $ bson unwind b < a.bson | bson print
199 | { b: 1 }
200 | { b: 2 }
201 | { b: 7 }
202 | { b: 8 }
203 | { b: "zzz" }
204 | { b: 4 }
205 | { b: 7 }
206 |
207 | ## Other Options
208 |
209 | `-#` option: tells the utility to output document numbers rather than the actual document as
210 | output. Simply used for troubleshooting; say, if you are getting an error mid-file and want
211 | to track it down.
212 |
213 | ## Other Notes
214 |
215 | * You can use the regular Unix 'cat' utility to concatenate BSON files, as it simply concatenates streams of bytes.
216 |
217 |
--------------------------------------------------------------------------------
/doc/fromxml.md:
--------------------------------------------------------------------------------
1 | fromxml utility -- converts XML to BSON.
2 |
3 | NOTE: PRELIMINARY IMPLEMENTATION (at time of this writing).
4 |
5 | ## Usage
6 |
7 | fromxml < infile.xml > outfile.bson
8 |
9 | Run fromxml -h for options.
10 |
11 | ### Interpretation of structure
12 |
13 | (Note this may evolve, but this version...)
14 |
15 | asdf
16 |
17 | becomes:
18 |
19 | { foo: "asdf" }
20 |
21 | asdf becomes:
22 |
23 | { foo: { x: "33.3", foo: "asdf" } }
24 |
25 | 3asdf becomes:
26 |
27 | { a: { b: "3", c: "asdf" } }
28 |
29 | ### Numerics
30 |
31 | Use -t or -f =options to set rules for interpretation of datatypes.
32 |
33 | 3
34 |
35 | would by default yield: { x : "3" }
36 |
37 | with "-t n": { x : 3 } (where the 3 is an int32)
38 |
39 | with "-t f": { x : 3.0 }
40 |
41 | That is to say the 'n' option uses the smallest type that makes sense.
42 |
43 | More data types will be done later hopefully.
44 |
--------------------------------------------------------------------------------
/doc/hex.md:
--------------------------------------------------------------------------------
1 | hex - BSON-friendly hex dump utility.
2 |
3 | ## Usage
4 |
5 | hex < infile.bson
6 |
7 | Options:
8 |
9 | * -h help
10 | * -v verbose style dump
11 | * -raw raw hex dump with no 'bson awareness'
12 |
13 | ## Purpose
14 |
15 | This is a very simple hex dump utility which could be used
16 | with any binary file. However, adds a tiny amount of BSON
17 | awareness, which can be useful when dumping larger BSON files.
18 |
19 | Specifically, it is aware that the first four bytes of a BSON
20 | document indicate its size. It will output the dump of those bytes
21 | on a line by itself, then, the rest of that document, then, a blank
22 | separator line. Thus it makes it easy to find the point of demarcation
23 | for each BSON document in the dump. Trivial but very useful.
24 |
25 | ## Example
26 |
27 | ~/bsontools $ ./fromjson > out.bson
28 | {"hello": "world"}
29 | {"BSON": ["awesome", 5.05, 1986]}
30 |
31 | ~/bsontools $ ./hex < out.bson
32 | 16 00 00 00
33 | 02 68 65 6C 6C 6F 00 06 00 00 00 77 6F 72 6C 64
34 | 00 00
35 |
36 | 31 00 00 00
37 | 04 42 53 4F 4E 00 26 00 00 00 02 30 00 08 00 00
38 | 00 61 77 65 73 6F 6D 65 00 01 31 00 33 33 33 33
39 | 33 33 14 40 10 32 00 C2 07 00 00 00 00
40 |
41 | ~/bsontools $ ./hex -v < out.bson
42 | 16 00 00 00 22
43 | 02 68 65 6C 6C 6F 00 06 00 00 00 77 6F 72 6C 64 .hello.....world
44 | 00 00 ..
45 |
46 | 31 00 00 00 49
47 | 04 42 53 4F 4E 00 26 00 00 00 02 30 00 08 00 00 .BSON.&....0....
48 | 00 61 77 65 73 6F 6D 65 00 01 31 00 33 33 33 33 .awesome..1.3333
49 | 33 33 14 40 10 32 00 C2 07 00 00 00 00 33.@.2.......
50 |
51 | ~/bsontools $ ./hex -raw < out.bson
52 | 16 00 00 00 02 68 65 6C 6C 6F 00 06 00 00 00 77
53 | 6F 72 6C 64 00 00 31 00 00 00 04 42 53 4F 4E 00
54 | 26 00 00 00 02 30 00 08 00 00 00 61 77 65 73 6F
55 | 6D 65 00 01 31 00 33 33 33 33 33 33 14 40 10 32
56 | 00 C2 07 00 00 00 00
57 |
58 | ~/bsontools $
59 |
--------------------------------------------------------------------------------
/src/bsontools/binary.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "fcntl.h"
4 | #if defined(_WIN32)
5 | #include "io.h"
6 | #endif
7 | #include
8 |
9 | inline void binaryStdIn() {
10 | #if !defined(_WIN32)
11 | freopen(NULL, "rb", stdin);
12 | #else
13 | _setmode(_fileno(stdin), _O_BINARY);
14 | #endif
15 | }
16 |
17 | inline void binaryStdOut() {
18 | #if !defined(_WIN32)
19 | freopen(NULL, "wb", stdout);
20 | #else
21 | _setmode(_fileno(stdout), _O_BINARY);
22 | #endif
23 | }
24 |
25 | class bsontool_error : public std::exception {
26 | std::string msg;
27 | public:
28 | virtual ~bsontool_error() throw() {}
29 | bsontool_error(const char *p) : msg(p) { }
30 | virtual const char* what() const throw() { return msg.c_str(); }
31 | };
32 |
33 |
--------------------------------------------------------------------------------
/src/bsontools/bsonmain.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "binary.h"
4 | #include "../../../bson-cxx/src/bson/bsonobj.h"
5 | #include "../../../bson-cxx/src/bson/bsonobjiterator.h"
6 | #include "../../../bson-cxx/src/bson/bsonobjbuilder.h"
7 | #include "cmdline.h"
8 | #include
9 | #include