Git Product home page Git Product logo

go-simple-serializer's Introduction

CircleCI Go Report Card GoDoc license

go-simple-serializer

Description

go-simple-serializer (aka GSS) is a simple library to easily convert data between formats that aims to decrease the burden on developers to support multiple serialization formats in their applications. GSS supports a variety of operating systems, architectures, and use cases. A CLI is released for Microsoft Windows, Linux distributions, and Darwin platforms.

Using cross compilers, this library can also be called by other languages, including C, C++, Python, and JavaScript. This library is cross compiled into a Shared Object file (*.so), which can be called by C, C++, and Python on Linux machines. This library is also compiled to pure JavaScript using GopherJS, which can be called by Node.js and loaded in the browser. See the examples folder for patterns that you can use.

Formats

GSS supports many common formats, including CSV, JSON, and YAML. Pull requests to support other formats are welcome! See the Formats.md document for a full list of supported formats.

Packages

The main public api for GSS is in the gss package. However, this library does ship with internal packages under /pkg/... that can be imported and used directly.

Usage

CLI

The command line tool, gss, can be used to easily convert data between formats. We currently support the following platforms.

GOOS GOARCH
darwin amd64
linux amd64
windows amd64
linux arm64

Pull requests to support other platforms are welcome! See the CLI.md document for detailed usage and examples.

Go

You can install the go-simple-serializer packages with.

go get -u -d github.com/spatialcurrent/go-simple-serializer/...

You can then import the main public API with import "github.com/spatialcurrent/go-simple-serializer/pkg/gss" or one of the underlying packages, e.g., import "github.com/spatialcurrent/go-simple-serializer/pkg/tags".

See go-simple-serializer in GoDoc for API documentation and examples.

Node

GSS is built as a module. In modern JavaScript, the module can be imported using destructuring assignment.

const { serialize, deserialize, convert, formats } = require('./dist/gss.mod.min.js');

In legacy JavaScript, you can use the gss.global.js file that simply adds gss to the global scope.

Android

The go-simple-serializer code is available for use in Android applications under com.spatialcurrent.gss. For example,

import com.spatialcurrent.gss.Gss;
...
  String output_format = Gss.convert(input_string, input_format, input_header, input_comment, output_format, verbose);
...

C

A variant of the Convert function is exported in a Shared Object file (*.so), which can be called by C, C++, and Python programs on Linux machines. For complete patterns for C, C++, and Python, see the examples folder in this repo.

Releases

go-simple-serializer is currently in alpha. See releases at https://github.com/spatialcurrent/go-simple-serializer/releases. See the Building section below to build from scratch.

JavaScript

  • gss.global.js, gss.global.js.map - JavaScript global build with source map
  • gss.global.min.js, gss.global.min.js.map - Minified JavaScript global build with source map
  • gss.mod.js, gss.mod.js.map - JavaScript module build with source map
  • gss.mod.min.js, gss.mod.min.js.map - Minified JavaScript module with source map

Darwin

  • gss_darwin_amd64 - CLI for Darwin on amd64 (includes macOS and iOS platforms)

Linux

  • gss_linux_amd64 - CLI for Linux on amd64
  • gss_linux_amd64 - CLI for Linux on arm64
  • gss_linux_amd64.h, gss_linuxamd64.so - Shared Object for Linux on amd64
  • gss_linux_armv7.h, gss_linux_armv7.so - Shared Object for Linux on ARMv7
  • gss_linux_armv8.h, gss_linux_armv8.so - Shared Object for Linux on ARMv8

Windows

  • gss_windows_amd64.exe - CLI for Windows on amd64

Examples

CLI

.gitignore file to jsonl

cat .gitignore | gss -i csv --input-header path -o json

Get language from CircleCI config.

cat .circleci/config.yml | gss -i yaml -o json -c '#' | jq -r .version

Convert list of files to JSON Lines

find . -name '*.go' | gss -i csv --input-header path -o jsonl

Go

See the examples in GoDoc.

C

See the examples/c/main.c file. You can run the example with make run_example_c.

C++

See the examples/cpp/main.cpp file. You can run the example with make run_example_cpp.

Python

See the examples/python/test.py file. You can run the example with make run_example_python.

JavaScript

See the examples/js/index.js file. You can run the example with make run_example_javascript.

Building

Use make help to see help information for each target.

CLI

The make build_cli script is used to build executables for Linux and Windows.

JavaScript

You can compile GSS to pure JavaScript with the make build_javascript script.

Android

The make build_android script is used to build an Android Archive (AAR) file and associated Javadocs.

Shared Object

The make build_so script is used to build a Shared Object (*.go), which can be called by C, C++, and Python on Linux machines.

Changing Destination

The default destination for build artifacts is go-simple-serializer/bin, but you can change the destination with an environment variable. For building on a Chromebook consider saving the artifacts in /usr/local/go/bin, e.g., DEST=/usr/local/go/bin make build_cli

Testing

CLI

To run CLI testes use make test_cli, which uses shUnit2. If you recive a shunit2:FATAL Please declare TMPDIR with path on partition with exec permission. error, you can modify the TMPDIR environment variable in line or with export TMPDIR=<YOUR TEMP DIRECTORY HERE>. For example:

TMPDIR="/usr/local/tmp" make test_cli

Go

To run Go tests use make test_go (or bash scripts/test.sh), which runs unit tests, go vet, go vet with shadow, errcheck, ineffassign, staticcheck, and misspell.

JavaScript

To run JavaScript tests, first install Jest using make deps_javascript, use Yarn, or another method. Then, build the JavaScript module with make build_javascript. To run tests, use make test_javascript. You can also use the scripts in the package.json.

Contributing

Spatial Current, Inc. is currently accepting pull requests for this repository. We'd love to have your contributions! Please see Contributing.md for how to get started.

License

This work is distributed under the MIT License. See LICENSE file.

go-simple-serializer's People

Contributors

pjdufour avatar

Stargazers

Johann Petrak avatar Alfon avatar Serge Bedzhyk avatar Joni Kähärä avatar Hugefiver avatar David Budnick avatar Serge Simard avatar Denis Denisov avatar Antoine GIRARD avatar Paweł Albecki avatar  avatar GAURAV avatar

Watchers

James Cloos avatar  avatar

Forkers

priestd09

go-simple-serializer's Issues

Improve Performance of Escaper

Escaper currently uses strings.Replace(out, e.prefix+str, str, -1) for each substring. Change this to iterating through the string rune by rune.

CLA

I, Patrick Dufour (@pjdufour), agree to the license terms. My contributions to this repo are granted to Spatial Current, Inc. under a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license and/or copyright is transferred.

Support for Table Header

Pass in header with CLI using -input_header A,B,C. This will be used by csv and tsv input when no header is present.

[BUG] [ Iterator returns end of file instead of scanner error]

I got EOF before the real end of my file and reason is that the scanned line exceeded the size of the buffer (bufio.MaxScanTokenSize) So the scanner return false but sets the error into the scanner.Err() return

file pkg/jsonl/iterator.go

In the iterator you don't check if the scanner has an error

//line 92
if it.Scanner.Scan() {
// parse line code
}
// Here you have to check it.Scanner.Err()
// line 122 return nil, io.EOF

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.