1//  Copyright (c) 2017 Couchbase, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// 		http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package vellum_test
16
17import (
18	"bytes"
19	"fmt"
20	"log"
21
22	"github.com/couchbase/vellum"
23)
24
25func Example() {
26
27	var buf bytes.Buffer
28	builder, err := vellum.New(&buf, nil)
29	if err != nil {
30		log.Fatal(err)
31	}
32
33	err = builder.Insert([]byte("cat"), 1)
34	if err != nil {
35		log.Fatal(err)
36	}
37
38	err = builder.Insert([]byte("dog"), 2)
39	if err != nil {
40		log.Fatal(err)
41	}
42
43	err = builder.Insert([]byte("fish"), 3)
44	if err != nil {
45		log.Fatal(err)
46	}
47
48	err = builder.Close()
49	if err != nil {
50		log.Fatal(err)
51	}
52
53	fst, err := vellum.Load(buf.Bytes())
54	if err != nil {
55		log.Fatal(err)
56	}
57
58	val, exists, err := fst.Get([]byte("cat"))
59	if err != nil {
60		log.Fatal(err)
61	}
62	if exists {
63		fmt.Println(val)
64	}
65
66	val, exists, err = fst.Get([]byte("dog"))
67	if err != nil {
68		log.Fatal(err)
69	}
70	if exists {
71		fmt.Println(val)
72	}
73
74	val, exists, err = fst.Get([]byte("fish"))
75	if err != nil {
76		log.Fatal(err)
77	}
78	if exists {
79		fmt.Println(val)
80	}
81
82	// Output: 1
83	// 2
84	// 3
85}
86