MCPcopy Create free account
hub / github.com/blues/note / processTemplateValue

Method processTemplateValue

lib/bulk.go:1722–2017  ·  view source on GitHub ↗

Get a value

(ctx context.Context, level int, v *fastjson.Value, dok string, dov interface{})

Source from the content-addressed store, hash-verified

1720
1721// Get a value
1722func (tmplContext *BulkTemplateContext) processTemplateValue(ctx context.Context, level int, v *fastjson.Value, dok string, dov interface{}) (err error) {
1723
1724 if debugEncoding {
1725 fmt.Printf("%sprocessTemplateValue key %s tmplType %s valType %T\n", strings.Repeat(" ", level), dok, v.Type(), dov)
1726 }
1727 beforeLen := len(tmplContext.Bin)
1728
1729 switch v.Type() {
1730
1731 case fastjson.TypeTrue:
1732 var dv bool
1733 s, isString := dov.(string)
1734 b, isBool := dov.(bool)
1735 i, isInt := dov.(int)
1736 // Numeric values unmarshalled into json.Number
1737 n, isNumber := dov.(json.Number)
1738
1739 if isBool {
1740 dv = b
1741 } else if isString {
1742 if s == "true" {
1743 dv = true
1744 } else {
1745 i, err := strconv.Atoi(s)
1746 if err == nil && i > 0 {
1747 dv = true
1748 }
1749 }
1750 } else if isInt {
1751 dv = (i > 0)
1752 } else if isNumber {
1753 i, err := n.Int64()
1754 if err == nil {
1755 dv = (i > 0)
1756 }
1757 }
1758
1759 if debugEncoding {
1760 fmt.Printf("%sEMIT BOOL %t\n", strings.Repeat(" ", level), dv)
1761 }
1762 err = tmplContext.binAppendBool(ctx, dv)
1763
1764 case fastjson.TypeString:
1765 newStringBytes, _ := v.StringBytes()
1766 format := string(newStringBytes)
1767 var dv string
1768 dv, _ = dov.(string)
1769 if dok == "_note" {
1770 dv = tmplContext.noteID
1771 }
1772 if debugEncoding {
1773 fmt.Printf("%sEMIT STRING %s format %s\n", strings.Repeat(" ", level), dv, format)
1774 }
1775 err = tmplContext.binAppendString(ctx, dv)
1776
1777 case fastjson.TypeNumber:
1778 format := v.GetFloat64()
1779 var ivalue int64

Callers 2

walkObjectIntoMethod · 0.95
processArrayValueFunction · 0.80

Calls 15

binAppendBoolMethod · 0.95
binAppendStringMethod · 0.95
binAppendReal64Method · 0.95
binAppendReal32Method · 0.95
binAppendReal16Method · 0.95
binAppendInt8Method · 0.95
binAppendInt16Method · 0.95
binAppendInt24Method · 0.95
binAppendInt32Method · 0.95
binAppendInt40Method · 0.95
binAppendInt48Method · 0.95
binAppendInt56Method · 0.95

Tested by

no test coverage detected