func (i *info) SetClient(c hrpc.RegionClient) {
	i.m.Lock()
	i.client = c
	i.m.Unlock()
}
SetClient sets region client
package region
import (
	"bytes"
	"context"
	"encoding/binary"
	"fmt"
	"sync"
	"github.com/tsuna/gohbase/hrpc"
	"github.com/tsuna/gohbase/pb"
	"google.golang.org/protobuf/proto"
)
var defaultNamespace = []byte("default")
type OfflineRegionError struct {
	n string
}
func (e OfflineRegionError) Error() string {
	return fmt.Sprintf("region %s is offline", e.n)
}
type info struct {
	id        uint64  
	namespace []byte
	table     []byte
	name      []byte
	startKey  []byte
	stopKey   []byte
	ctx       context.Context
	cancel    context.CancelFunc
	m sync.RWMutex
	client hrpc.RegionClient
	available chan struct{}
}
func NewInfo(id uint64, namespace, table, name, startKey, stopKey []byte) hrpc.RegionInfo {
	ctx, cancel := context.WithCancel(context.Background())
	return &info{
		id:        id,
		ctx:       ctx,
		cancel:    cancel,
		namespace: namespace,
		table:     table,
		name:      name,
		startKey:  startKey,
		stopKey:   stopKey,
	}
}
func infoFromCell(cell *hrpc.Cell) (hrpc.RegionInfo, error) {
	value := cell.Value
	if len(value) == 0 {
		return nil, fmt.Errorf("empty value in %q", cell)
	} else if value[0] != 'P' {
		return nil, fmt.Errorf("unsupported region info version %d in %q", value[0], cell)
	}
	const pbufMagic = 1346524486  
	magic := binary.BigEndian.Uint32(value[:4])
	if magic != pbufMagic {
		return nil, fmt.Errorf("invalid magic number in %q", cell)
	}
	var regInfo pb.RegionInfo
	err := proto.Unmarshal(value[4:], &regInfo)
	if err != nil {
		return nil, fmt.Errorf("failed to decode %q: %s", cell, err)
	}
	if regInfo.GetOffline() {
		return nil, OfflineRegionError{n: string(cell.Row)}
	}
	var namespace []byte
	if !bytes.Equal(regInfo.TableName.Namespace, defaultNamespace) {
		namespace = regInfo.TableName.Namespace
	}
	return NewInfo(
		regInfo.GetRegionId(),
		namespace,
		regInfo.TableName.Qualifier,
		cell.Row,
		regInfo.StartKey,
		regInfo.EndKey,
	), nil
}
func ParseRegionInfo(metaRow *hrpc.Result) (hrpc.RegionInfo, string, error) {
	var reg hrpc.RegionInfo
	var addr string
	for _, cell := range metaRow.Cells {
		switch string(cell.Qualifier) {
		case "regioninfo":
			var err error
			reg, err = infoFromCell(cell)
			if err != nil {
				return nil, "", err
			}
		case "server":
			value := cell.Value
			if len(value) == 0 {
				continue  
			}
			addr = string(value)
		default:
		}
	}
	if reg == nil {
		return nil, "", fmt.Errorf("meta seems to be broken, there was no region in %v", metaRow)
	}
	if len(addr) == 0 {
		return nil, "", fmt.Errorf("meta doesn't have a server location in %v", metaRow)
	}
	return reg, addr, nil
}
func (i *info) IsUnavailable() bool {
	i.m.RLock()
	res := i.available != nil
	i.m.RUnlock()
	return res
}
func (i *info) AvailabilityChan() <-chan struct{} {
	i.m.RLock()
	ch := i.available
	i.m.RUnlock()
	return ch
}
func (i *info) MarkUnavailable() bool {
	created := false
	i.m.Lock()
	if i.available == nil {
		i.available = make(chan struct{})
		created = true
	}
	i.m.Unlock()
	return created
}
func (i *info) MarkAvailable() {
	i.m.Lock()
	ch := i.available
	i.available = nil
	close(ch)
	i.m.Unlock()
}
func (i *info) MarkDead() {
	i.cancel()
}
func (i *info) Context() context.Context {
	return i.ctx
}
func (i *info) String() string {
	return fmt.Sprintf(
		"RegionInfo{Name: %q, ID: %d, Namespace: %q, Table: %q, StartKey: %q, StopKey: %q}",
		i.name, i.id, i.namespace, i.table, i.startKey, i.stopKey)
}
func (i *info) ID() uint64 {
	return i.id
}
func (i *info) Name() []byte {
	return i.name
}
func (i *info) StopKey() []byte {
	return i.stopKey
}
func (i *info) StartKey() []byte {
	return i.startKey
}
func (i *info) Namespace() []byte {
	return i.namespace
}
func (i *info) Table() []byte {
	return i.table
}
func (i *info) Client() hrpc.RegionClient {
	i.m.RLock()
	c := i.client
	i.m.RUnlock()
	return c
}