github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/store/byteArrayDataOutput.go (about) 1 package store 2 3 import ( 4 "github.com/balzaczyy/golucene/core/util" 5 ) 6 7 type ByteArrayDataOutput struct { 8 *util.DataOutputImpl 9 data []byte 10 pos int 11 limit int 12 } 13 14 func NewByteArrayDataOutput(data []byte) *ByteArrayDataOutput { 15 ans := &ByteArrayDataOutput{} 16 ans.DataOutputImpl = util.NewDataOutput(ans) 17 ans.reset(data) 18 return ans 19 } 20 21 func (o *ByteArrayDataOutput) reset(data []byte) { 22 o.data = data 23 o.pos = 0 24 o.limit = len(data) 25 } 26 27 func (o *ByteArrayDataOutput) Position() int { 28 return o.pos 29 } 30 31 func (o *ByteArrayDataOutput) WriteByte(b byte) error { 32 assert(o.pos < o.limit) 33 o.data[o.pos] = b 34 o.pos++ 35 return nil 36 } 37 38 func (o *ByteArrayDataOutput) WriteBytes(b []byte) error { 39 assert(o.pos+len(b) <= o.limit) 40 copy(o.data[o.pos:], b) 41 o.pos += len(b) 42 return nil 43 }