1// Licensed to the Apache Software Foundation (ASF) under one 2// or more contributor license agreements. See the NOTICE file 3// distributed with this work for additional information 4// regarding copyright ownership. The ASF licenses this file 5// to you under the Apache License, Version 2.0 (the 6// "License"); you may not use this file except in compliance 7// with the License. You may obtain a copy of the License at 8// 9// http://www.apache.org/licenses/LICENSE-2.0 10// 11// Unless required by applicable law or agreed to in writing, software 12// distributed under the License is distributed on an "AS IS" BASIS, 13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14// See the License for the specific language governing permissions and 15// limitations under the License. 16 17package array 18 19import ( 20 "github.com/apache/arrow/go/v6/arrow" 21 "github.com/apache/arrow/go/v6/arrow/bitutil" 22 "github.com/apache/arrow/go/v6/arrow/memory" 23) 24 25{{range .In}} 26{{$TypeNamePrefix := .name}} 27{{if .Opt.BufferBuilder}} 28type {{$TypeNamePrefix}}BufferBuilder struct { 29 bufferBuilder 30} 31 32func new{{.Name}}BufferBuilder(mem memory.Allocator) *{{$TypeNamePrefix}}BufferBuilder { 33 return &{{$TypeNamePrefix}}BufferBuilder{bufferBuilder:bufferBuilder{refCount: 1, mem:mem}} 34} 35 36// AppendValues appends the contents of v to the buffer, growing the buffer as needed. 37func (b *{{$TypeNamePrefix}}BufferBuilder) AppendValues(v []{{.Type}}) { b.Append(arrow.{{.Name}}Traits.CastToBytes(v)) } 38 39// Values returns a slice of length b.Len(). 40// The slice is only valid for use until the next buffer modification. That is, until the next call 41// to Advance, Reset, Finish or any Append function. The slice aliases the buffer content at least until the next 42// buffer modification. 43func (b *{{$TypeNamePrefix}}BufferBuilder) Values() []{{.Type}} { return arrow.{{.Name}}Traits.CastFromBytes(b.Bytes()) } 44 45// Value returns the {{.Type}} element at the index i. Value will panic if i is negative or ≥ Len. 46func (b *{{$TypeNamePrefix}}BufferBuilder) Value(i int) {{.Type}} { return b.Values()[i] } 47 48// Len returns the number of {{.Type}} elements in the buffer. 49func (b *{{$TypeNamePrefix}}BufferBuilder) Len() int { return b.length/arrow.{{.Name}}SizeBytes } 50 51// AppendValue appends v to the buffer, growing the buffer as needed. 52func (b *{{$TypeNamePrefix}}BufferBuilder) AppendValue(v {{.Type}}) { 53 if b.capacity < b.length+arrow.{{.Name}}SizeBytes { 54 newCapacity := bitutil.NextPowerOf2(b.length + arrow.{{.Name}}SizeBytes) 55 b.resize(newCapacity) 56 } 57 arrow.{{.Name}}Traits.PutValue(b.bytes[b.length:], v) 58 b.length+=arrow.{{.Name}}SizeBytes 59} 60{{end}} 61{{end}} 62