Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Aug 10, 2023
1 parent b1cd23f commit 8237093
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
17 changes: 17 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

vuln:
uses: cristalhq/.github/.github/workflows/[email protected]
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions bson.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module bson

go 1.18
29 changes: 29 additions & 0 deletions type.go
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 8237093

Please sign in to comment.