Skip to content

Commit 7f0d731

Browse files
committed
0.0.3 release
1 parent f453d9c commit 7f0d731

17 files changed

Lines changed: 143 additions & 57 deletions

File tree

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ go:
88

99
os:
1010
- linux
11-
- osx
11+
#- osx
1212

1313
matrix:
1414
allow_failures:
1515
- go: tip
1616
fast_finish: true
1717

18+
install:
19+
- go get -u github.com/alecthomas/gometalinter
20+
- gometalinter --install
21+
1822
script:
23+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./gss/
24+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./plugins/gss/
25+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./cmd/gss/
26+
- gometalinter --misspell-locale=US --disable-all --enable=misspell --enable=vet ./cmd/gss.js/
1927
- cd gss
2028
- go fmt
2129
- cd ./../cmd/gss

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/spatialcurrent/go-simple-serializer.svg)](https://travis-ci.org/spatialcurrent/go-simple-serializer) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-simple-serializer?status.svg)](https://godoc.org/github.com/spatialcurrent/go-simple-serializer)
1+
[![Build Status](https://travis-ci.org/spatialcurrent/go-simple-serializer.svg)](https://travis-ci.org/spatialcurrent/go-simple-serializer) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/go-simple-serializer)](https://goreportcard.com/report/spatialcurrent/go-simple-serializer) [![GoDoc](https://godoc.org/github.com/spatialcurrent/go-simple-serializer?status.svg)](https://godoc.org/github.com/spatialcurrent/go-simple-serializer) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/spatialcurrent/go-simple-serializer/blob/master/LICENSE)
22

33
# go-simple-serializer
44

@@ -56,6 +56,8 @@ The `Convert`, `Deserialize`, and `Serialize` functions are the core functions t
5656
...
5757
```
5858

59+
See [gss](https://godoc.org/github.com/spatialcurrent/go-simple-serializer/gss) in GoDoc for information on how to use Go API.
60+
5961
**JavaScript**
6062

6163
```html
@@ -102,7 +104,7 @@ The Go function definition defined in `plugins/gss/main.go` uses `*C.char` for a
102104
func Convert(input_string *C.char, input_format *C.char, input_header *C.char, input_comment *C.char, output_format *C.char, output_string **C.char) *C.char
103105
```
104106

105-
For complete patterns for `C`, `C++`, and `Python`, see the `examples`.
107+
For complete patterns for `C`, `C++`, and `Python`, see the `go-simpler-serializer/examples` folder.
106108

107109
# Releases
108110

@@ -140,6 +142,10 @@ The `build_android.sh` script is used to build an [Android Archive](https://deve
140142

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

145+
**Changing Destination**
146+
147+
The default destination for build artifacts is `go-simple-serializer/bin`, but you can change the destination with a CLI argument. For building on a Chromebook consider saving the artifacts in `/usr/local/go/bin`, e.g., `bash scripts/build_cli.sh /usr/local/go/bin`
148+
143149
# Contributing
144150

145151
[Spatial Current, Inc.](https://spatialcurrent.io) is currently accepting pull requests for this repository. We'd love to have your contributions! Please see [Contributing.md](https://github.com/spatialcurrent/go-simple-serializer/blob/master/CONTRIBUTING.md) for how to get started.

cmd/gss.js/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ import (
2222
"honnef.co/go/js/console"
2323
)
2424

25-
var GO_GSS_VERSION = "0.0.2"
26-
2725
func main() {
2826
js.Global.Set("gss", map[string]interface{}{
29-
"version": GO_GSS_VERSION,
27+
"version": gss.VERSION,
3028
"convert": Convert,
3129
})
3230
}

cmd/gss/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/spatialcurrent/go-simple-serializer/gss"
2424
)
2525

26-
var GO_GSS_VERSION = "0.0.2"
2726
var GO_GSS_FORMATS = []string{"csv", "tsv", "hcl", "hcl2", "json", "jsonl", "properties", "toml", "yaml"}
2827

2928
func printUsage() {
@@ -67,7 +66,7 @@ func main() {
6766
}
6867

6968
if version {
70-
fmt.Println(GO_GSS_VERSION)
69+
fmt.Println(gss.VERSION)
7170
os.Exit(0)
7271
}
7372

examples/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
build_so:
99
go build -o gss.so -buildmode=c-shared github.com/spatialcurrent/go-simple-serializer/plugins/gss
1010
build_c:
11-
mkdir bin && gcc -o bin/gss_test_c test.c -L. -l:gss.so
11+
mkdir -p bin && gcc -o bin/gss_test_c test.c -L. -l:gss.so
1212
build: build_so build_c
1313
run:
1414
LD_LIBRARY_PATH=. bin/gss_test_c

examples/c/gss_test_c

-8.3 KB
Binary file not shown.

examples/python/test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# =================================================================
2+
#
3+
# Copyright (C) 2018 Spatial Current, Inc. - All Rights Reserved
4+
# Released as open source under the MIT License. See LICENSE file.
5+
#
6+
# =================================================================
7+
18
from ctypes import *
29
import sys
310

gss/Convert.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import (
1414
// Convert converts an input_string from the input_format to the output_format and returns an error, if any.
1515
func Convert(input_string string, input_format string, input_header []string, input_comment string, output_format string) (string, error) {
1616

17-
object := NewObject(input_string, input_format)
17+
object, err := NewObject(input_string, input_format)
18+
if err != nil {
19+
return "", errors.Wrap(err, "error creating new object for format "+input_format)
20+
}
1821

1922
if input_format == "bson" || input_format == "json" || input_format == "hcl" || input_format == "hcl2" || input_format == "properties" || input_format == "toml" || input_format == "yaml" {
2023
if output_format == "bson" || output_format == "json" || input_format == "hcl" || input_format == "hcl2" || output_format == "properties" || output_format == "toml" || output_format == "yaml" {

gss/Deserialize.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,26 @@ func Deserialize(input string, format string, input_header []string, input_comme
148148
} else if format == "json" {
149149
return json.Unmarshal([]byte(input), output)
150150
} else if format == "jsonl" {
151-
switch output.(type) {
151+
152+
//s.Interface()(type)
153+
// reflect.TypeOf(s).Elem()
154+
155+
/*s := reflect.ValueOf(output)
156+
if s.Kind() == reflect.Ptr {
157+
fmt.Println("s.Interface():", s.Interface())
158+
s = reflect.Indirect(s).Elem()
159+
if s.Kind() != reflect.Slice {
160+
return errors.New("Output is not of kind slice.")
161+
}
162+
} else if s.Kind() != reflect.Slice {
163+
return errors.New("Output is not of kind slice.")
164+
}*/
165+
166+
//fmt.Println("reflect.TypeOf(output)", reflect.TypeOf(output))
167+
168+
switch output_slice := output.(type) {
152169
case *[]map[string]string:
153-
output_slice := output.(*[]map[string]string)
170+
//output_slice := s.Interface().(*[]map[string]string)
154171
scanner := bufio.NewScanner(strings.NewReader(input))
155172
scanner.Split(bufio.ScanLines)
156173
for scanner.Scan() {
@@ -165,7 +182,7 @@ func Deserialize(input string, format string, input_header []string, input_comme
165182
}
166183
}
167184
case *[]map[string]interface{}:
168-
output_slice := output.(*[]map[string]interface{})
185+
//output_slice := s.Interface().(*[]map[string]interface{})
169186
scanner := bufio.NewScanner(strings.NewReader(input))
170187
scanner.Split(bufio.ScanLines)
171188
for scanner.Scan() {
@@ -179,8 +196,23 @@ func Deserialize(input string, format string, input_header []string, input_comme
179196
*output_slice = append(*output_slice, obj)
180197
}
181198
}
199+
case []map[string]interface{}:
200+
//output_slice := s.Interface().([]map[string]interface{})
201+
scanner := bufio.NewScanner(strings.NewReader(input))
202+
scanner.Split(bufio.ScanLines)
203+
for scanner.Scan() {
204+
line := strings.TrimSpace(scanner.Text())
205+
if len(input_comment) == 0 || !strings.HasPrefix(line, input_comment) {
206+
obj := map[string]interface{}{}
207+
err := json.Unmarshal([]byte(line), &obj)
208+
if err != nil {
209+
return errors.Wrap(err, "Error reading object from JSON line")
210+
}
211+
output_slice = append(output_slice, obj)
212+
}
213+
}
182214
default:
183-
return errors.New("Cannot deserialize to type " + fmt.Sprint(reflect.ValueOf(output)))
215+
return errors.New("Cannot deserialize to type " + fmt.Sprint(reflect.TypeOf(output).String()))
184216
}
185217
} else if format == "hcl" {
186218
obj, err := hcl.Parse(input)
@@ -202,5 +234,6 @@ func Deserialize(input string, format string, input_header []string, input_comme
202234
} else if format == "yaml" {
203235
return yaml.Unmarshal([]byte(input), output)
204236
}
237+
205238
return nil
206239
}

gss/NewObject.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1+
// =================================================================
2+
//
3+
// Copyright (C) 2018 Spatial Current, Inc. - All Rights Reserved
4+
// Released as open source under the MIT License. See LICENSE file.
5+
//
6+
// =================================================================
7+
18
package gss
29

310
import (
411
"strings"
512
"unicode"
613
)
714

8-
func NewObject(content string, format string) interface{} {
15+
func NewObject(content string, format string) (interface{}, error) {
16+
917
if format == "json" {
1018
content = strings.TrimLeftFunc(content, unicode.IsSpace)
1119
if len(content) > 0 && content[0] == '[' {
12-
return []map[string]interface{}{}
20+
return []map[string]interface{}{}, nil
1321
}
14-
return map[string]interface{}{}
22+
return map[string]interface{}{}, nil
1523
} else if format == "yaml" {
1624
content = strings.TrimLeftFunc(content, unicode.IsSpace)
1725
if len(content) > 0 && content[0] == '-' {
18-
return []map[string]interface{}{}
26+
return []map[string]interface{}{}, nil
1927
}
20-
return map[string]interface{}{}
28+
return map[string]interface{}{}, nil
2129
} else if format == "bson" || format == "hcl" || format == "hcl2" || format == "properties" || format == "toml" {
22-
return map[string]interface{}{}
30+
return map[string]interface{}{}, nil
31+
} else if format == "jsonl" || format == "csv" || format == "tsv" {
32+
return []map[string]interface{}{}, nil
2333
}
2434

25-
return nil
35+
return nil, nil
2636
}

0 commit comments

Comments
 (0)