// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package array

import (
	
	
	
	

	
	
)

// A type which represents an immutable sequence of fixed-length binary strings.
type FixedSizeBinary struct {
	array

	valueBytes []byte
	bytewidth  int32
}

// NewFixedSizeBinaryData constructs a new fixed-size binary array from data.
func ( arrow.ArrayData) *FixedSizeBinary {
	 := &FixedSizeBinary{bytewidth: int32(.DataType().(arrow.FixedWidthDataType).BitWidth() / 8)}
	.refCount.Add(1)
	.setData(.(*Data))
	return 
}

// Value returns the fixed-size slice at index i. This value should not be mutated.
func ( *FixedSizeBinary) ( int) []byte {
	 += .data.offset
	var (
		  = int(.bytewidth)
		 =  * 
		 = ( + 1) * 
	)
	return .valueBytes[:]
}

func ( *FixedSizeBinary) ( int) string {
	if .IsNull() {
		return NullValueStr
	}
	return base64.StdEncoding.EncodeToString(.Value())
}

func ( *FixedSizeBinary) () string {
	 := new(strings.Builder)
	.WriteString("[")
	for  := 0;  < .Len(); ++ {
		if  > 0 {
			.WriteString(" ")
		}
		switch {
		case .IsNull():
			.WriteString(NullValueStr)
		default:
			fmt.Fprintf(, "%q", .Value())
		}
	}
	.WriteString("]")
	return .String()
}

func ( *FixedSizeBinary) ( *Data) {
	.array.setData()
	 := .buffers[1]
	if  != nil {
		.valueBytes = .Bytes()
	}
}

func ( *FixedSizeBinary) ( int) interface{} {
	if .IsNull() {
		return nil
	}

	return .Value()
}

func ( *FixedSizeBinary) () ([]byte, error) {
	 := make([]interface{}, .Len())
	for  := 0;  < .Len(); ++ {
		if .IsValid() {
			[] = .Value()
		} else {
			[] = nil
		}
	}
	return json.Marshal()
}

func arrayEqualFixedSizeBinary(,  *FixedSizeBinary) bool {
	for  := 0;  < .Len(); ++ {
		if .IsNull() {
			continue
		}
		if !bytes.Equal(.Value(), .Value()) {
			return false
		}
	}
	return true
}

var _ arrow.Array = (*FixedSizeBinary)(nil)