mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
34 lines
691 B
Go
34 lines
691 B
Go
// Copyright 2026 Hanzo AI, Inc. 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
|
|
}
|