]> git.giacomolli.uk - onechat/blobdiff - records.go
Separate multiline Go statements
[onechat] / records.go
index abd88a897a99e63c07f3955cc0f4b96a1c41b0cb..52824cb505787e95a8645bb2a55cbf8964442336 100644 (file)
@@ -11,6 +11,16 @@ import (
 // positionBytes is the size of an encoded position.
 const positionBytes = 16
 
+// Records is a file of fixed-size Records, numbered from 0. Record n starts at
+// byte n*size. A record that was never written reads as zeros. An index is data
+// that the day files can give again, so Records cuts a partial record at the
+// end of the file.
+type Records struct {
+       file  *os.File
+       size  int
+       count int
+}
+
 // openRecords opens or creates the record file at path with records of size
 // bytes.
 func openRecords(path string, size int) (*Records, error) {
@@ -40,32 +50,6 @@ func openRecords(path string, size int) (*Records, error) {
        return r, nil
 }
 
-// encodePosition writes place into the first positionBytes bytes of record.
-func encodePosition(record []byte, place Position) {
-       binary.LittleEndian.PutUint32(record[0:], place.day)
-       binary.LittleEndian.PutUint32(record[4:], place.length)
-       binary.LittleEndian.PutUint64(record[8:], place.offset)
-}
-
-// decodePosition reads a position from the first positionBytes bytes of record.
-func decodePosition(record []byte) Position {
-       return Position{
-               day:    binary.LittleEndian.Uint32(record[0:]),
-               length: binary.LittleEndian.Uint32(record[4:]),
-               offset: binary.LittleEndian.Uint64(record[8:]),
-       }
-}
-
-// Records is a file of fixed-size Records, numbered from 0. Record n starts at
-// byte n*size. A record that was never written reads as zeros. An index is data
-// that the day files can give again, so Records cuts a partial record at the
-// end of the file.
-type Records struct {
-       file  *os.File
-       size  int
-       count int
-}
-
 // Read returns record n, or false when the file does not reach it.
 func (r *Records) Read(n int) ([]byte, bool, error) {
        if n >= r.count {
@@ -102,3 +86,19 @@ func (r *Records) Append(record []byte) error {
 func (r *Records) Close() error {
        return r.file.Close()
 }
+
+// encodePosition writes place into the first positionBytes bytes of record.
+func encodePosition(record []byte, place Position) {
+       binary.LittleEndian.PutUint32(record[0:], place.day)
+       binary.LittleEndian.PutUint32(record[4:], place.length)
+       binary.LittleEndian.PutUint64(record[8:], place.offset)
+}
+
+// decodePosition reads a position from the first positionBytes bytes of record.
+func decodePosition(record []byte) Position {
+       return Position{
+               day:    binary.LittleEndian.Uint32(record[0:]),
+               length: binary.LittleEndian.Uint32(record[4:]),
+               offset: binary.LittleEndian.Uint64(record[8:]),
+       }
+}