1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/common/commonspace/object/tree/treestorage/helpers.go
2022-12-25 20:27:37 +01:00

34 lines
568 B
Go

package treestorage
import (
"bytes"
"strings"
)
func ParseHeads(headsPayload []byte) []string {
return strings.Split(string(headsPayload), "/")
}
func CreateHeadsPayload(heads []string) []byte {
return JoinStringsToBytes(heads...)
}
func JoinStringsToBytes(strs ...string) []byte {
var (
b bytes.Buffer
totalLen int
)
for _, s := range strs {
totalLen += len(s)
}
// adding separators
totalLen += len(strs) - 1
b.Grow(totalLen)
for idx, s := range strs {
if idx > 0 {
b.WriteString("/")
}
b.WriteString(s)
}
return b.Bytes()
}