Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Package store holds GnoRadio's string codecs: records (fields behind a length header, read and changed without decodi...

Overview

Package store holds GnoRadio's string codecs: records (fields behind a length header, read and changed without decoding), packed id lists (9 bytes per id, sorted, JSON-ready), base-64 fixed-width numbers, the 8-digit keys and page rows of the data realm, and the Ops builder of data.Batch. It keeps no state: every realm stores these strings in the data realm.

Constants 4

const OpSet, OpDel

1const (
2	OpSet = "set"
3	OpDel = "del"
4)
source

Batch op names: an op is four strings (name, collection, key, value).

const Digits

1const Digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_"
source

Digits are the base-64 digits of record headers and of Num and Fixed, ordered so that fixed-width numbers sort as their values do.

const MaxField

1const MaxField = 1<<18 - 1
source

MaxField is the longest field a record holds (3 base-64 digits).

const W

1const W = 9
source

W is the width of one id in a list (ids up to 99,999,999). The padding is spaces and the separator a comma, so "[" + list without its last comma + "]" is already a JSON array: exporting a list costs no per-id work.

Functions 23

func Add

1func Add(sorted string, id int) (string, bool)
source

Add inserts id into a sorted list; false if already there.

func Append

1func Append(rec, v string) string
source

Append returns rec with v added as its last field, without decoding the record ("" is a record of no fields).

func AppendFixed

1func AppendFixed(b []byte, v int64, w int) []byte
source

AppendFixed appends v in w base-64 digits to b (one append for the usual widths). It panics when v does not fit.

func At

1func At(list string, i int) int
source

At returns the i-th id of a list.

func Count

1func Count(list string) int
source

Count is the number of ids in a list.

func Enc

1func Enc(id int) string
source

Enc writes one id of a list.

func Field

1func Field(rec string, i int) string
source

Field returns field i of a record ("" past the last field).

func Fields

1func Fields(rec string) []string
source

Fields unpacks a record.

func Fixed

1func Fixed(v int64, w int) string
source

Fixed writes v in w base-64 digits.

func Ints

1func Ints(list string) []int
source

Ints decodes a list.

func JSON

1func JSON(list string) string
source

JSON returns a list as a JSON array.

func Limit

1func Limit(n, max int) int
source

Limit is a page size: n, or max when n is out of 1..max.

func Num

1func Num(s string, at, w int) int64
source

Num reads the w-digit base-64 number at position at of s (one expression for the usual widths: every VM step costs gas).

func Pack

1func Pack(ids []int) string
source

Pack encodes ids in their order.

func Pad

1func Pad(n int) string
source

Pad writes a number as an 8-digit key, so keys sort as numbers do.

func Page

1func Page(list string, offset, limit int, desc bool) []int
source

Page returns up to limit ids from offset, from the end when desc.

func Rec

1func Rec(fs ...string) string
source

Rec packs fields into a record (at most 63 fields).

func Remove

1func Remove(sorted string, id int) (string, bool)
source

Remove deletes id from a sorted list; false if absent.

func Row

1func Row(k, v string) string
source

Row encodes one key and value of a page: "len:key" + "len:value".

func Rows

1func Rows(page string) (keys, values []string)
source

Rows decodes a page of Row strings into its keys and values.

func Slot

1func Slot(id, size int) (string, int)
source

Slot is where record id (from 1) of a chunked collection lives: the key of its chunk of size records and its index there.

func TimeKey

1func TimeKey(t int64) string
source

TimeKey writes a unix time as a 12-digit key, so keys sort as times do.

func With

1func With(rec string, i int, v string) string
source

With returns rec with field i replaced by v, without decoding the record.

Types 1

type Ops

slice
1type Ops []string
source

Ops builds the argument of data.Batch: ops = ops.Set(c, k, v).

Methods on Ops

func Del

method on Ops
1func (o Ops) Del(c, k string) Ops
source

Del adds a removal of key k of collection c.

func Set

method on Ops
1func (o Ops) Set(c, k, v string) Ops
source

Set adds a write of v at key k of collection c.

Imports 1

  • strconv stdlib

Source Files 2