Documentation ¶
Overview ¶
quip is a package of quick ipld patterns.
Most quip functions take a pointer to an error as their first argument. This has two purposes: if there's an error there, the quip function will do nothing; and if the quip function does something and creates an error, it puts it there. The effect of this is that most logic can be written very linearly.
quip functions can be used to increase brevity without worrying about performance costs. None of the quip functions cause additional allocations in the course of their work. Benchmarks indicate no measurable speed penalties versus longhand manual error checking.
Several functions perform comparable operations but with different arguments, and so these function names follow a pattern:
- `Build*` functions take a NodePrototype and return a Node.
- `Assemble*` functions take a NodeAssembler and feed data into it.
- There is no analog of `NodeAssembler.Begin*` functions (we simply always use callbacks for structuring, because this is reasonably optimal).
- `Assign*` functions handle values of the scalar kinds (these of course also never need callbacks, since there's no possible recursion).
The `Assemble*` functions are used recursively. The `Build*` functions can be used instead of `Assemble*` at the top of a tree in order to save on writing a few additional lines of NodeBuilder setup and usage. (The `Assemble*` functions can also be used at the top of a tree if you wish to control the NodeBuilder yourself. This may be desirable for being able to reset and reuse the NodeBuilder when performance is critical, for example.)
The usual IPLD NodeAssembler, MapAssembler, and ListAssembler interfaces are still available while using quip functions, should you wish to interact with them directly, or compose the use of quip functions with other styles of data manipulation.
Example ¶
var err error n := quip.BuildMap(&err, basicnode.Prototype.Any, 4, func(ma ipld.MapAssembler) { quip.AssignMapEntryString(&err, ma, "some key", "some value") quip.AssignMapEntryString(&err, ma, "another key", "another value") quip.AssembleMapEntry(&err, ma, "nested map", func(na ipld.NodeAssembler) { quip.AssembleMap(&err, na, 2, func(ma ipld.MapAssembler) { quip.AssignMapEntryString(&err, ma, "deeper entries", "deeper values") quip.AssignMapEntryString(&err, ma, "more deeper entries", "more deeper values") }) }) quip.AssembleMapEntry(&err, ma, "nested list", func(na ipld.NodeAssembler) { quip.AssembleList(&err, na, 2, func(la ipld.ListAssembler) { quip.AssignListEntryInt(&err, la, 1) quip.AssignListEntryInt(&err, la, 2) }) }) }) if err != nil { panic(err) } dagjson.Encoder(n, os.Stdout)
Output: { "some key": "some value", "another key": "another value", "nested map": { "deeper entries": "deeper values", "more deeper entries": "more deeper values" }, "nested list": [ 1, 2 ] }
Index ¶
- func AbsorbError(e *error, err error)
- func AssembleList(e *error, na ipld.NodeAssembler, sizeHint int64, ...)
- func AssembleListEntry(e *error, la ipld.ListAssembler, fn func(va ipld.NodeAssembler))
- func AssembleMap(e *error, na ipld.NodeAssembler, sizeHint int64, fn func(ma ipld.MapAssembler))
- func AssembleMapEntry(e *error, ma ipld.MapAssembler, k string, fn func(va ipld.NodeAssembler))
- func Assign(e *error, na ipld.NodeAssembler, x interface{})
- func AssignBool(e *error, na ipld.NodeAssembler, x bool)
- func AssignBytes(e *error, na ipld.NodeAssembler, x []byte)
- func AssignFloat(e *error, na ipld.NodeAssembler, x float64)
- func AssignInt(e *error, na ipld.NodeAssembler, x int64)
- func AssignLink(e *error, na ipld.NodeAssembler, x ipld.Link)
- func AssignListEntry(e *error, la ipld.ListAssembler, x interface{})
- func AssignListEntryBool(e *error, la ipld.ListAssembler, v bool)
- func AssignListEntryBytes(e *error, la ipld.ListAssembler, v []byte)
- func AssignListEntryFloat(e *error, la ipld.ListAssembler, v float64)
- func AssignListEntryInt(e *error, la ipld.ListAssembler, v int64)
- func AssignListEntryLink(e *error, la ipld.ListAssembler, v ipld.Link)
- func AssignListEntryNode(e *error, la ipld.ListAssembler, v ipld.Node)
- func AssignListEntryNull(e *error, la ipld.ListAssembler)
- func AssignListEntryString(e *error, la ipld.ListAssembler, v string)
- func AssignMapEntry(e *error, ma ipld.MapAssembler, k string, x interface{})
- func AssignMapEntryBool(e *error, ma ipld.MapAssembler, k string, v bool)
- func AssignMapEntryBytes(e *error, ma ipld.MapAssembler, k string, v []byte)
- func AssignMapEntryFloat(e *error, ma ipld.MapAssembler, k string, v float64)
- func AssignMapEntryInt(e *error, ma ipld.MapAssembler, k string, v int64)
- func AssignMapEntryLink(e *error, ma ipld.MapAssembler, k string, v ipld.Link)
- func AssignMapEntryNode(e *error, ma ipld.MapAssembler, k string, v ipld.Node)
- func AssignMapEntryNull(e *error, ma ipld.MapAssembler, k string)
- func AssignMapEntryString(e *error, ma ipld.MapAssembler, k string, v string)
- func AssignNode(e *error, na ipld.NodeAssembler, x ipld.Node)
- func AssignNull(e *error, na ipld.NodeAssembler)
- func AssignString(e *error, na ipld.NodeAssembler, x string)
- func BuildList(e *error, np ipld.NodePrototype, sizeHint int64, ...) ipld.Node
- func BuildMap(e *error, np ipld.NodePrototype, sizeHint int64, fn func(ma ipld.MapAssembler)) ipld.Node
- func CopyRange(e *error, la ipld.ListAssembler, src ipld.Node, start, end int64)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsorbError ¶
func AssembleList ¶
func AssembleListEntry ¶
func AssembleListEntry(e *error, la ipld.ListAssembler, fn func(va ipld.NodeAssembler))
func AssembleMap ¶
func AssembleMapEntry ¶
func Assign ¶
func Assign(e *error, na ipld.NodeAssembler, x interface{})
Assign takes any value and attempts to turn it into something we can reparse as Node-like, using the same logic as fluent.Reflect. It's not particularly performant, so use it only when convenience matters more than performance.
func AssignBool ¶
func AssignBytes ¶
func AssignFloat ¶
func AssignLink ¶
func AssignLink(e *error, na ipld.NodeAssembler, x ipld.Link)
func AssignListEntry ¶
func AssignListEntry(e *error, la ipld.ListAssembler, x interface{})
AssignListEntry takes any value and attempts to turn it into something we can reparse as Node-like, using the same logic as fluent.Reflect. It's not particularly performant, so use it only when convenience matters more than performance.
func AssignListEntryBool ¶
func AssignListEntryBytes ¶
func AssignListEntryFloat ¶
func AssignListEntryInt ¶
func AssignListEntryLink ¶
func AssignListEntryLink(e *error, la ipld.ListAssembler, v ipld.Link)
func AssignListEntryNode ¶
func AssignListEntryNode(e *error, la ipld.ListAssembler, v ipld.Node)
func AssignListEntryNull ¶
func AssignListEntryNull(e *error, la ipld.ListAssembler)
func AssignListEntryString ¶
func AssignMapEntry ¶
AssignMapEntry takes any value and attempts to turn it into something we can reparse as Node-like, using the same logic as fluent.Reflect. It's not particularly performant, so use it only when convenience matters more than performance.
func AssignMapEntryBool ¶
func AssignMapEntryBytes ¶
func AssignMapEntryFloat ¶
func AssignMapEntryInt ¶
func AssignMapEntryLink ¶
func AssignMapEntryNode ¶
func AssignMapEntryNull ¶
func AssignMapEntryString ¶
func AssignNode ¶
func AssignNode(e *error, na ipld.NodeAssembler, x ipld.Node)
func AssignNull ¶
func AssignNull(e *error, na ipld.NodeAssembler)
func AssignString ¶
Types ¶
This section is empty.