https://github.com/tidwall/sds
simple data streams for go
https://github.com/tidwall/sds
Last synced: 6 months ago
JSON representation
simple data streams for go
- Host: GitHub
- URL: https://github.com/tidwall/sds
- Owner: tidwall
- License: mit
- Created: 2020-03-06T22:06:42.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-25T18:44:41.000Z (over 3 years ago)
- Last Synced: 2025-04-27T20:38:21.238Z (9 months ago)
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 31
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `sds`
[](https://godoc.org/github.com/tidwall/sds)
This package provides a fast and simple way for reading and writing custom
data streams in Go.
Supports reading and writing most basic types including:
`int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `uint32`, `uint64`,
`byte`, `bool`, `float32`, `float64`, `[]byte`, `string`.
Also `uvarint` and `varint`.
## Usage
### Installing
To start using `sds`, install Go and run `go get`:
```sh
$ go get -u github.com/tidwall/sds
```
### Basic operations
```go
// create a writer
var bb bytes.Buffer
w := sds.NewWriter(&bb)
// write some stuff
err = w.WriteString("Hello Jello")
err = w.WriteBytes(someBinary)
err = w.WriteUvarint(8589869056)
err = w.WriteVarint(-119290019)
err = w.WriteUint16(-119290019)
// close the reader when done
w.Flush()
// create a reader
r := sds.NewReader(&bb)
// read some stuff
s, err = w.ReadString()
b, err = w.ReadBytes()
x, err = w.ReadUvarint()
x, err = w.ReadVarint()
x, err = w.ReadUint16()
```
*Now isn't that nice.*
## License
`sds` source code is available under the MIT License.