mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
695 B
33 lines
695 B
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/gob"
|
|
)
|
|
|
|
// PackData uses gob to encode the given data in sequence
|
|
func PackData(data ...any) ([]byte, error) {
|
|
var buf bytes.Buffer
|
|
enc := gob.NewEncoder(&buf)
|
|
for _, datum := range data {
|
|
if err := enc.Encode(datum); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return buf.Bytes(), nil
|
|
}
|
|
|
|
// UnpackData uses gob to decode the given data in sequence
|
|
func UnpackData(buf []byte, data ...any) error {
|
|
r := bytes.NewReader(buf)
|
|
enc := gob.NewDecoder(r)
|
|
for _, datum := range data {
|
|
if err := enc.Decode(datum); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|