fs = require 'fs'
Loggable = (require './Loggable.coffee').Loggable

class RandomAccessLoggable extends Loggable
  # @private
  address: undefined
  # @private
  type: undefined
  # @private
  headerLength: undefined
  # @private
  length_: undefined
  # @private
  data: undefined
  # @private
  structureId: undefined

  # Constructor.
  #
  # @param address
  # @param type
  # @param length
  # @param data
  # @param dataLength
  # @param structureId
  @create$Addr64$int$int$RandomAccessByteIterable$int$int: (address, type, length, data, dataLength, structureId, o) ->
    if !o? then o = new RandomAccessLoggable
    o.address = address
    o.type = type
    o.headerLength = length - dataLength
    o.length_ = length
    o.data = data
    o.structureId = structureId
    return o

  # Constructor.
  #
  # @param prototype another random access loggable that this one will be
  # copied from.
  @create$RandomAccessLoggable: (prototype) ->
    o = new RandomAccessLoggable
    o.address = prototype.address
    o.type = prototype.type
    o.headerLength = prototype.headerLength
    o.length_ = prototype.length_
    o.data = prototype.getData().clone(0)
    o.structureId = prototype.structureId
    return o

  getAddress: () ->
    return @address

  getType: () ->
    return @type

  length: () ->
    return @length_

  getData: () ->
    return @data

  getDataLength: () ->
    return @length_ - @headerLength

  getStructureId: () ->
    return @structureId

exports.RandomAccessLoggable = RandomAccessLoggable
