SRC_DIR='../../../src/log/'

Log = (require SRC_DIR + 'Log.coffee').Log
LogConfig = (require SRC_DIR + 'LogConfig.coffee').LogConfig
LoggableIterator = (require SRC_DIR + 'LoggableIterator.coffee').LoggableIterator
Addr64 = (require SRC_DIR + 'Addr64.coffee').Addr64

fileSize = 8 * 1024
pageSize = 1024
NPages = 100
path = './db/'

config = LogConfig.create()
config.setDir path
config.setFileSize fileSize
config.setCachePageSize pageSize
config.setCacheOpenFilesCount NPages

log = Log.create$LogConfig config

li = LoggableIterator.create$Log$Addr64 log, (Addr64.create$int$int 0, 0)
N = 0
console.log "Begin of log"

onNext = (loggable) =>
  if loggable.getType() != 0
    console.log "Record", N,
            "addr =", loggable.getAddress().toString(),
            "type =", loggable.getType(),
            "structureId =", loggable.getStructureId(),
            "dataLength =", loggable.getDataLength()
  else
    console.log "Record", N,
            "addr =", loggable.getAddress().toString(),
            "type =", loggable.getType()
  N += 1
  if li.hasNext()
    res = li.next$emit()
    if res?
      onNext res
  else
    console.log "End of Log"
li.on 'next', (res) =>
  onNext res
if li.hasNext()
  res = li.next$emit()
  if res?
    onNext res
else
  console.log "End of Log"
