Commit 68f80523 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 461b9ef4
...@@ -172,54 +172,48 @@ func (txnh *TxnHeader) Load(r io.ReaderAt, pos int64) error { ...@@ -172,54 +172,48 @@ func (txnh *TxnHeader) Load(r io.ReaderAt, pos int64) error {
txnh.Description = work[luser:luser:ldesc] txnh.Description = work[luser:luser:ldesc]
txnh.Extension = work[luser+ldesc:luser+ldesc:lext] txnh.Extension = work[luser+ldesc:luser+ldesc:lext]
// XXX make loading strings optional // XXX make strings loading optional
txnh.loadString() txnh.loadString()
return txnHeaderFixSize + lstr, nil return txnHeaderFixSize + lstr, nil
} }
// loadStrings makes sure strings that are part of transaction header are loaded
func (txnh *TxnHeader) loadStrings(r io.ReaderAt) error { func (txnh *TxnHeader) loadStrings(r io.ReaderAt) error {
// XXX make it no-op if strings are already loaded?
// we rely on Load leaving len(workMem) = sum of all strings length ... // we rely on Load leaving len(workMem) = sum of all strings length ...
nstr, err = r.ReadAt(txnh.workMem, txnh.Pos + txnHeaderFixSize) nstr, err = r.ReadAt(txnh.workMem, txnh.Pos + txnHeaderFixSize)
if err != nil { if err != nil {
return 0, &ErrTxnRecord{txnh.Pos, "read", noEof(err)} return 0, &ErrTxnRecord{txnh.Pos, "read", noEof(err)} // XXX -> "read strings" ?
} }
// ... and presetting x to point to appropriate places in .workMem . // ... and presetting x to point to appropriate places in .workMem .
// so set len(x) = cap(x) to indicate strings are now loaded. // so set len(x) = cap(x) to indicate strings are now loaded.
txnh.User = txnh.User[:cap(txnh.User)] txnh.User = txnh.User[:cap(txnh.User)]
txnh.Description = txnh.User[:cap(txnh.Description)] txnh.Description = txnh.Description[:cap(txnh.Description)]
txnh.Extension = txnh.User[:cap(txnh.Extension)] txnh.Extension = txnh.Extension[:cap(txnh.Extension)]
} }
// loadPrev reads and decodes previous transaction record header from a readerAt // loadPrev reads and decodes previous transaction record header from a readerAt
// txnh should be already initialized by previous call to load() // txnh should be already initialized by previous call to load()
func (txnh *TxnHeader) loadPrev(r io.ReaderAt, tmpBuf *[txnXHeaderFixSize]byte) error { func (txnh *TxnHeader) LoadPrev(r io.ReaderAt) error {
if txnh.PrevLen == 0 { if txnh.PrevLen == 0 {
return io.EOF return io.EOF
} }
return txnh.load(r, txnh.Pos - txnh.PrevLen, tmpBuf) return txnh.Load(r, txnh.Pos - txnh.PrevLen)
} }
// loadNext reads and decodes next transaction record header from a readerAt // loadNext reads and decodes next transaction record header from a readerAt
// txnh should be already initialized by previous call to load() // txnh should be already initialized by previous call to load()
func (txnh *TxnHeader) loadNext(r io.ReaderAt, tmpBuf *[txnXHeaderFixSize]byte) error { func (txnh *TxnHeader) LoadNext(r io.ReaderAt) error {
return txnh.load(r, txnh.Pos + txnh.Len, tmpBuf) return txnh.Load(r, txnh.Pos + txnh.Len)
} }
// XXX do we need Decode when decode() is there?
func (th *TxnHeader) Decode(r io.ReaderAt, pos int64) (n int, err error) {
var tmpBuf [txnXHeaderFixSize]byte
return th.decode(r, pos, &tmpBuf)
}
func (th *TxnHeader) DecodePrev(r io.ReaderAt, pos int64) (posPrev int64, n int, err error) {
var tmpBuf [txnXHeaderFixSize]byte
return th.decodePrev(r, pos, &tmpBuf)
}
// XXX -> Load ?
// decode reads and decodes data record header from a readerAt // decode reads and decodes data record header from a readerAt
// XXX io.ReaderAt -> *os.File (if iface conv costly) // XXX io.ReaderAt -> *os.File (if iface conv costly)
func (dh *DataHeader) decode(r io.ReaderAt, pos int64, tmpBuf *[dataHeaderSize]byte) error { func (dh *DataHeader) decode(r io.ReaderAt, pos int64, tmpBuf *[dataHeaderSize]byte) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment