// NewSUBACKFromBytes creates a SUBACK Packet
// from the byte data and returns it.
344546
func NewSUBACKFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
	// Validate the byte data.
	if err := validateSUBACKBytes(fixedHeader, remaining); err != nil {
		return nil, err
	}

	// Extract the variable header.
	variableHeader := remaining[0:lenSUBACKVariableHeader]

	// Extract the payload.
	payload := remaining[lenSUBACKVariableHeader:]

	// Decode the Packet Identifier.
	// No error occur because of the precedent validation and
	// the returned error is not be taken care of.
	packetID, _ := decodeUint16(variableHeader)

	// Create a PUBACK Packet.
	p := &SUBACK{
		PacketID:    packetID,
		ReturnCodes: payload,
	}

	// Set the fixed header to the Packet.
	p.fixedHeader = fixedHeader

	// Set the variable header to the Packet.
	p.variableHeader = variableHeader

	// Set the payload to the Packet.
	p.payload = payload

	// Return the Packet.
	return p, nil
}
169081
func (ss *SQLSubStore) getOrCreateAcksPending(subid, seqno uint64) *sqlSubAcksPending {
	if !ss.cache.needsFlush {
		ss.cache.needsFlush = true
		ss.sqlStore.scheduleSubStoreFlush(ss)
	}
	ap := ss.cache.subs[subid]
	if ap == nil {
		ap = &sqlSubAcksPending{
			msgToRow: make(map[uint64]*sqlSubsPendingRow),
			ackToRow: make(map[uint64]*sqlSubsPendingRow),
			msgs:     make(map[uint64]struct{}),
			acks:     make(map[uint64]struct{}),
		}
		ss.cache.subs[subid] = ap
	}
	if seqno > ap.lastSent {
		ap.lastSent = seqno
	}
	return ap
}
1305832
func NewSfFbInviteType(Description string) *SfFbInviteType {
	s := new(SfFbInviteType)
	s.Description = Description
	return s
}
1138672
func NewPayloadsBuffer(next uint64) PayloadsBuffer {
	return &PayloadsBufferImpl{
		buf:       make(map[uint64]*proto.Payload),
		readyChan: make(chan struct{}, 1),
		next:      next,
		logger:    util.GetLogger(util.StateLogger, ""),
	}
}
491540
func NewStatsdBuffer(interval time.Duration, client Statsd) *StatsdBuffer {
	sb := &StatsdBuffer{
		flushInterval: interval,
		statsd:        client,
		eventChannel:  make(chan event.Event, 100),
		events:        make(map[string]event.Event),
		closeChannel:  make(chan closeRequest),
		Logger:        log.New(os.Stdout, "[BufferedStatsdClient] ", log.Ldate|log.Ltime),
		Verbose:       true,
	}
	go sb.collector()
	return sb
}
865005
func (rb *Bitmap) ReadFromMsgpack(stream io.Reader) (int64, error) {
	return 0, rb.highlowcontainer.readFromMsgpack(stream)
}
10297
func ParsePacket(q []byte) (*Packet, error) {
	var pkt Packet
	if err := (&pkt).UnmarshalBinary(q); err != nil {
		return nil, err
	}
	return &pkt, nil
}
917551
func NewPUBACKFromBytes(fixedHeader FixedHeader, variableHeader []byte) (Packet, error) {
	// Validate the byte data.
	if err := validatePUBACKBytes(fixedHeader, variableHeader); err != nil {
		return nil, err
	}

	// Decode the Packet Identifier.
	// No error occur because of the precedent validation and
	// the returned error is not be taken care of.
	packetID, _ := decodeUint16(variableHeader)

	// Create a PUBACK Packet.
	p := &PUBACK{
		PacketID: packetID,
	}

	// Set the fixed header to the Packet.
	p.fixedHeader = fixedHeader

	// Set the variable header to the Packet.
	p.variableHeader = variableHeader

	// Return the Packet.
	return p, nil
}
608045
func (v *VersioningTestV2) GetNewbyte() (o int8) {
	if v != nil && v.Newbyte != nil {
		return *v.Newbyte
	}

	return
}
779463
func NewFromBytes(fixedHeader FixedHeader, remaining []byte) (Packet, error) {
	// Extract the MQTT Control Packet type from the fixed header.
	ptype, err := fixedHeader.ptype()
	if err != nil {
		return nil, err
	}

	// Create and return a Packet.
	switch ptype {
	case TypeCONNACK:
		return NewCONNACKFromBytes(fixedHeader, remaining)
	case TypePUBLISH:
		return NewPUBLISHFromBytes(fixedHeader, remaining)
	case TypePUBACK:
		return NewPUBACKFromBytes(fixedHeader, remaining)
	case TypePUBREC:
		return NewPUBRECFromBytes(fixedHeader, remaining)
	case TypePUBREL:
		return NewPUBRELFromBytes(fixedHeader, remaining)
	case TypePUBCOMP:
		return NewPUBCOMPFromBytes(fixedHeader, remaining)
	case TypeSUBACK:
		return NewSUBACKFromBytes(fixedHeader, remaining)
	case TypeUNSUBACK:
		return NewUNSUBACKFromBytes(fixedHeader, remaining)
	case TypePINGRESP:
		return NewPINGRESPFromBytes(fixedHeader, remaining)
	default:
		return nil, ErrInvalidPacketType
	}
}
768345
func newStorageDBWrapper(db *mgo.Database, metaColl, modelUUID string) *storageDBWrapper {
	session := db.Session.Copy()
	db = db.With(session)

	coll := db.C(metaColl)
	txnRunner := jujutxn.NewRunner(jujutxn.RunnerParams{
		Database:               db,
		ServerSideTransactions: false,
	})
	dbWrap := storageDBWrapper{
		session:   session,
		db:        db,
		metaColl:  coll,
		txnRunner: txnRunner,
		modelUUID: modelUUID,
	}
	return &dbWrap
}
442888
func NewSchemaFromFile(filename string) (schema *Schema, err error) {
	file, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	}
	var info yaml.MapSlice
	err = yaml.Unmarshal(file, &info)
	if err != nil {
		return nil, err
	}
	return NewSchemaFromObject(info), nil
}
329264
func NewSubteamID(public bool) keybase1.TeamID {
	var useSuffix byte = keybase1.SUB_TEAMID_PRIVATE_SUFFIX
	if public {
		useSuffix = keybase1.SUB_TEAMID_PUBLIC_SUFFIX
	}
	idBytes, err := libkb.RandBytesWithSuffix(16, useSuffix)
	if err != nil {
		panic("RandBytes failed: " + err.Error())
	}
	return keybase1.TeamID(hex.EncodeToString(idBytes))
}
1177225
func (p *Packet) ConvertAcktoFinAck() error {
	var tcpFlags uint8

	tcpFlags = tcpFlags | TCPFinMask
	tcpFlags = tcpFlags | TCPAckMask

	p.updateTCPFlags(tcpFlags)
	p.tcpHdr.tcpFlags = tcpFlags

	if err := p.TCPDataDetach(0); err != nil {
		return fmt.Errorf("ack packet in wrong format")
	}
	p.DropTCPDetachedBytes()
	return nil
}
1374461
func (d *Decoder) nextValueBytes() (bs []byte) {
	d.d.uncacheRead()
	d.r.track()
	d.swallow()
	bs = d.r.stopTrack()
	return
}
1350000
func UnmarshalConfigUpdateFromPayload(payload *cb.Payload) (*cb.ConfigUpdate, error) {
	configEnv, err := UnmarshalConfigEnvelope(payload.Data)
	if err != nil {
		return nil, err
	}
	configUpdateEnv, err := utils.EnvelopeToConfigUpdate(configEnv.LastUpdate)
	if err != nil {
		return nil, err
	}

	return UnmarshalConfigUpdate(configUpdateEnv.ConfigUpdate)
}
238211
func NewSaltpackDecrypt(arg *SaltpackDecryptArg, pnymResolver saltpack.SymmetricKeyResolver) *SaltpackDecrypt {
	return &SaltpackDecrypt{
		arg:          arg,
		pnymResolver: pnymResolver,
	}
}