MCPcopy
hub / github.com/canopy-network/canopy / JoinLenPrefix

Function JoinLenPrefix

lib/util.go:775–800  ·  view source on GitHub ↗

JoinLenPrefix() appends the items together separated by a single byte to represent the length of the segment

(toAppend ...[]byte)

Source from the content-addressed store, hash-verified

773
774// JoinLenPrefix() appends the items together separated by a single byte to represent the length of the segment
775func JoinLenPrefix(toAppend ...[]byte) []byte {
776 // calculate total length first
777 totalLen := 0
778 for _, item := range toAppend {
779 // if the item isn't empty, calculate the size
780 if item != nil {
781 // 1 byte for length + item length
782 totalLen += 1 + len(item)
783 }
784 }
785 // make the proper size buffer
786 res := make([]byte, 0, totalLen)
787 // iterate through each 'segment' and append it
788 for _, item := range toAppend {
789 // if item is empty, skip
790 if item == nil {
791 continue
792 }
793 // length
794 res = append(res, byte(len(item)))
795 // item
796 res = append(res, item...)
797 }
798 // return the result
799 return res
800}
801
802// DecodeLengthPrefixed() decodes a key that is delimited by the length of the segment in a single byte
803func DecodeLengthPrefixed(key []byte) (segments [][]byte) {

Callers 15

TestNewSMTFunction · 0.92
store.goFile · 0.92
commitIDKeyMethod · 0.92
setNodeMethod · 0.92
delNodeMethod · 0.92
getNodeMethod · 0.92
testDBSetFunction · 0.92
testDBDeleteFunction · 0.92
testDBGetFunction · 0.92
testCompareIteratorsFunction · 0.92
TestStoreSetGetDeleteFunction · 0.92
TestIteratorCommitBasicFunction · 0.92

Calls

no outgoing calls

Tested by 15

TestNewSMTFunction · 0.74
testDBSetFunction · 0.74
testDBDeleteFunction · 0.74
testDBGetFunction · 0.74
testCompareIteratorsFunction · 0.74
TestStoreSetGetDeleteFunction · 0.74
TestIteratorCommitBasicFunction · 0.74
TestDoublyNestedTxnFunction · 0.74
validateIteratorsFunction · 0.74
bulkSetPrefixedKVFunction · 0.74
TestNestedTxnFunction · 0.74