diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..20d5f35 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: gomod + directory: "/" + schedule: + interval: daily + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..49e2b0e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,17 @@ +name: build + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '0 0 * * 0' # run "At 00:00 on Sunday" + +# See https://github.com/cristalhq/.github/.github/workflows +jobs: + build: + uses: cristalhq/.github/.github/workflows/build.yml@v0.5.0 + + vuln: + uses: cristalhq/.github/.github/workflows/vuln.yml@v0.5.0 diff --git a/README.md b/README.md index 58bfd46..bd7104c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ # bson -BSON for Go + +[![build-img]][build-url] +[![pkg-img]][pkg-url] +[![version-img]][version-url] + +BSON for Go. + +## Features + +* Simple API. +* Dependency-free. +* Clean and tested code. + +See [docs][pkg-url] for more details. + +## Install + +Go version 1.18+ + +``` +go get github.com/cristalhq/bson +``` + +## Example + +```go +TODO +``` + +See examples: [example_test.go](example_test.go). + +## License + +[MIT License](LICENSE). + +[build-img]: https://github.com/cristalhq/bson/workflows/build/badge.svg +[build-url]: https://github.com/cristalhq/bson/actions +[pkg-img]: https://pkg.go.dev/badge/cristalhq/bson +[pkg-url]: https://pkg.go.dev/github.com/cristalhq/bson +[version-img]: https://img.shields.io/github/v/release/cristalhq/bson +[version-url]: https://github.com/cristalhq/bson/releases diff --git a/bson.go b/bson.go new file mode 100644 index 0000000..7663e02 --- /dev/null +++ b/bson.go @@ -0,0 +1,16 @@ +package bson + +// Marshaler is the interface implemented by types that +// can marshal themselves into valid BSON. +type Marshaler interface { + MarshalBSON() ([]byte, error) +} + +// Unmarshaler is the interface implemented by types that +// can unmarshal a BSON representation of themselves. +// +// The input can be assumed to be a valid encoding of a BSON. +// UnmarshalBSON must copy the BSON data if it wishes to retain the data after returning. +type Unmarshaler interface { + UnmarshalBSON([]byte) error +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1aa38a8 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module bson + +go 1.18 diff --git a/type.go b/type.go new file mode 100644 index 0000000..dd379da --- /dev/null +++ b/type.go @@ -0,0 +1,29 @@ +package bson + +// Type represents a BSON type. +type Type byte + +// BSON element types as described in https://bsonspec.org/spec.html. +const ( + TypeDouble Type = 0x01 + TypeString Type = 0x02 + TypeDocument Type = 0x03 + TypeArray Type = 0x04 + TypeBinary Type = 0x05 + TypeUndefined Type = 0x06 + TypeObjectID Type = 0x07 + TypeBool Type = 0x08 + TypeDateTime Type = 0x09 + TypeNull Type = 0x0a + TypeRegex Type = 0x0b + TypeDBPointer Type = 0x0c + TypeCodeWithScope Type = 0x0d + TypeSymbol Type = 0x0e + TypeJavaScriptScope Type = 0x0f + TypeInt32 Type = 0x10 + TypeTimestamp Type = 0x11 + TypeInt64 Type = 0x12 + TypeDecimal Type = 0x13 + TypeMinKey Type = 0xff + TypeMaxKey Type = 0x7f +)