mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-23 14:32:32 +00:00

* [NOD-1223] Move all network stuff into a new network package. * [NOD-1223] Delete the unused package testutil. * [NOD-1223] Move infrastructure stuff into a new instrastructure package. * [NOD-1223] Move domain stuff into a new domain package.
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package ff
|
|
|
|
import "github.com/pkg/errors"
|
|
|
|
// flatFileLocationSerializedSize is the size in bytes of a serialized flat
|
|
// file location. See serializeLocation for further details.
|
|
const flatFileLocationSerializedSize = 12
|
|
|
|
// flatFileLocation identifies a particular flat file location.
|
|
type flatFileLocation struct {
|
|
fileNumber uint32
|
|
fileOffset uint32
|
|
dataLength uint32
|
|
}
|
|
|
|
// serializeLocation returns the serialization of the passed flat file location
|
|
// of certain data. This to later on be used for retrieval of said data.
|
|
// The serialized location format is:
|
|
//
|
|
// [0:4] File Number (4 bytes)
|
|
// [4:8] File offset (4 bytes)
|
|
// [8:12] Data length (4 bytes)
|
|
func serializeLocation(location *flatFileLocation) []byte {
|
|
var serializedLocation [flatFileLocationSerializedSize]byte
|
|
byteOrder.PutUint32(serializedLocation[0:4], location.fileNumber)
|
|
byteOrder.PutUint32(serializedLocation[4:8], location.fileOffset)
|
|
byteOrder.PutUint32(serializedLocation[8:12], location.dataLength)
|
|
return serializedLocation[:]
|
|
}
|
|
|
|
// deserializeLocation deserializes the passed serialized flat file location.
|
|
// See serializeLocation for further details.
|
|
func deserializeLocation(serializedLocation []byte) (*flatFileLocation, error) {
|
|
if len(serializedLocation) != flatFileLocationSerializedSize {
|
|
return nil, errors.Errorf("unexpected serializedLocation length: %d",
|
|
len(serializedLocation))
|
|
}
|
|
location := &flatFileLocation{
|
|
fileNumber: byteOrder.Uint32(serializedLocation[0:4]),
|
|
fileOffset: byteOrder.Uint32(serializedLocation[4:8]),
|
|
dataLength: byteOrder.Uint32(serializedLocation[8:12]),
|
|
}
|
|
return location, nil
|
|
}
|