func (d *device) String() string {
	return string(d.id)
}
String returns the JSON representation of this device
package device
import (
	"bytes"
	"encoding/json"
	"fmt"
	"sync/atomic"
	"time"
	"github.com/xmidt-org/webpa-common/v2/convey"
	"github.com/xmidt-org/webpa-common/v2/convey/conveymetric"
	"github.com/go-kit/kit/log"
	"github.com/xmidt-org/webpa-common/v2/logging"
)
const (
	stateOpen int32 = iota
	stateClosed
)
type envelope struct {
	request  *Request
	complete chan<- error
}
type Interface interface {
	fmt.Stringer
	json.Marshaler
	ID() ID
	Pending() int
	Closed() bool
	Send(*Request) (*Response, error)
	Statistics() Statistics
	Convey() convey.Interface
	ConveyCompliance() convey.Compliance
	Metadata() *Metadata
	CloseReason() CloseReason
}
type device struct {
	id ID
	errorLog log.Logger
	infoLog  log.Logger
	debugLog log.Logger
	statistics Statistics
	state int32
	shutdown     chan struct{}
	messages     chan *envelope
	transactions *Transactions
	c             convey.Interface
	compliance    convey.Compliance
	conveyClosure conveymetric.Closure
	metadata *Metadata
	closeReason atomic.Value
}
type deviceOptions struct {
	ID          ID
	C           convey.Interface
	Compliance  convey.Compliance
	QueueSize   int
	ConnectedAt time.Time
	Logger      log.Logger
	Metadata    *Metadata
}
func newDevice(o deviceOptions) *device {
	if o.ConnectedAt.IsZero() {
		o.ConnectedAt = time.Now()
	}
	if o.Logger == nil {
		o.Logger = logging.DefaultLogger()
	}
	if o.QueueSize < 1 {
		o.QueueSize = DefaultDeviceMessageQueueSize
	}
	return &device{
		id:           o.ID,
		errorLog:     logging.Error(o.Logger, "id", o.ID),
		infoLog:      logging.Info(o.Logger, "id", o.ID),
		debugLog:     logging.Debug(o.Logger, "id", o.ID),
		statistics:   NewStatistics(nil, o.ConnectedAt),
		c:            o.C,
		compliance:   o.Compliance,
		state:        stateOpen,
		shutdown:     make(chan struct{}),
		messages:     make(chan *envelope, o.QueueSize),
		transactions: NewTransactions(),
		metadata:     o.Metadata,
	}
}