stasatdaglabs d14809694f
[NOD-1223] Reorganize directory structure (#874)
* [NOD-1223] Delete unused files/packages.

* [NOD-1223] Move signal and limits to the os package.

* [NOD-1223] Put database and dbaccess into the db package.

* [NOD-1223] Fold the logs package into the logger package.

* [NOD-1223] Rename domainmessage to appmessage.

* [NOD-1223] Rename to/from DomainMessage to AppMessage.

* [NOD-1223] Move appmessage to the app packge.

* [NOD-1223] Move protocol to the app packge.

* [NOD-1223] Move the network package to the infrastructure packge.

* [NOD-1223] Rename cmd to executables.

* [NOD-1223] Fix go.doc in the logger package.
2020-08-18 10:26:39 +03:00

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
}