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

	// Create a PINGRESP Packet.
	p := &PINGRESP{}

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

	// Return the Packet.
	return p, nil
}
1069308
func NewPacketReader(conn net.Conn, packetHandler PacketHandler) PacketReader {
	return &packetReader{
		id:            conn.RemoteAddr().String(),
		conn:          conn,
		packetHandler: packetHandler,
	}
}
645276
func NewPixbufFromBytes(buffer []byte) (*Pixbuf, *glib.Error) {
	var err *C.GError
	loader := C.gdk_pixbuf_loader_new()
	C.gdk_pixbuf_loader_write(loader, C.to_gucharptr(unsafe.Pointer(&buffer[0])), C.gsize(len(buffer)), &err)
	gpixbuf := C.gdk_pixbuf_loader_get_pixbuf(loader)

	if err != nil {
		return nil, glib.ErrorFromNative(unsafe.Pointer(err))
	}
	return &Pixbuf{
		GdkPixbuf: &GdkPixbuf{gpixbuf},
		GObject:   glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
	}, nil
}
1094387
func NewPCMFloatBuffer(data []float64, format *Format) *PCMBuffer {
	return &PCMBuffer{
		Format:   format,
		DataType: Float,
		Floats:   data,
	}
}
342558
func NewPixbufFromData(pbd PixbufData) *Pixbuf {
	gpixbuf := C.gdk_pixbuf_new_from_data(
		C.to_gucharptr(unsafe.Pointer(&pbd.Data[0])),
		C.GdkColorspace(pbd.Colorspace),
		gbool(pbd.HasAlpha),
		C.int(pbd.BitsPerSample),
		C.int(pbd.Width),
		C.int(pbd.Height),
		C.int(pbd.RowStride),
		nil, nil)
	return &Pixbuf{
		GdkPixbuf: &GdkPixbuf{gpixbuf},
		GObject:   glib.ObjectFromNative(unsafe.Pointer(gpixbuf)),
	}
}
1138408
func NewDigestFromBytes(alg Algorithm, p []byte) Digest {
	return Digest(fmt.Sprintf("%s:%x", alg, p))
}
809563
func NewPacketConn(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*PacketConn, error) {
	// Create UDP endpoint and bind it.
	var wq waiter.Queue
	ep, err := s.NewEndpoint(udp.ProtocolNumber, network, &wq)
	if err != nil {
		return nil, errors.New(err.String())
	}

	if err := ep.Bind(addr); err != nil {
		ep.Close()
		return nil, &net.OpError{
			Op:   "bind",
			Net:  "udp",
			Addr: fullToUDPAddr(addr),
			Err:  errors.New(err.String()),
		}
	}

	c := &PacketConn{
		stack: s,
		ep:    ep,
		wq:    &wq,
	}
	c.deadlineTimer.init()
	return c, nil
}
345762
func newPstring(s string) *pstring {
	length := len(s)
	p := pstring{int8(length), s}
	return &p
}
577350
func newBitmapFromBytes(data []byte) *bitmap {
	bitmap := newBitmap(len(data) << 3)
	copy(bitmap.data, data)
	return bitmap
}
559826
func NewPluginRoutingFromBytes(bytes []byte) (PluginRouting, error) {
	var routing PluginRouting
	if err := yaml.Unmarshal(bytes, &routing); err != nil {
		return PluginRouting{}, err
	}
	if err := routing.Validate(); err != nil {
		return PluginRouting{}, err
	}
	return routing, nil
}
508223
func NewValueFromBytes(b []byte) (*Value, error) {
	r := bytes.NewReader(b)
	return NewValueFromReader(r)
}
1148699
func (p *Packet) GetTCPBytes() []byte {

	pktBytes := []byte{}
	pktBytes = append(pktBytes, p.ipHdr.Buffer...)
	pktBytes = append(pktBytes, p.tcpHdr.tcpOptions...)
	pktBytes = append(pktBytes, p.tcpHdr.tcpData...)
	return pktBytes
}
650880
func NewPacket(challenge, typ int32, body string) (packet *Packet) {
	size := int32(len([]byte(body)) + int(PacketHeaderSize+PacketPaddingSize))
	return &Packet{Header{size, challenge, typ}, body}
}
586698
func NewPointFromBytes(b []byte) (Point, error) {
	p := &point{}
	if err := p.UnmarshalBinary(b); err != nil {
		return nil, err
	}

	// This does some basic validation to ensure there are fields and they
	// can be unmarshalled as well.
	iter := p.FieldIterator()
	var hasField bool
	for iter.Next() {
		if len(iter.FieldKey()) == 0 {
			continue
		}
		hasField = true
		switch iter.Type() {
		case Float:
			_, err := iter.FloatValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		case Integer:
			_, err := iter.IntegerValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		case Unsigned:
			_, err := iter.UnsignedValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		case String:
			// Skip since this won't return an error
		case Boolean:
			_, err := iter.BooleanValue()
			if err != nil {
				return nil, fmt.Errorf("unable to unmarshal field %s: %s", string(iter.FieldKey()), err)
			}
		}
	}

	if !hasField {
		return nil, ErrPointMustHaveAField
	}

	return p, nil
}
1338802
func NewControlPacket(packetType byte) (cp ControlPacket) {
	switch packetType {
	case Connect:
		cp = &ConnectPacket{FixedHeader: &FixedHeader{MessageType: Connect}}
	case Connack:
		cp = &ConnackPacket{FixedHeader: &FixedHeader{MessageType: Connack}}
	case Disconnect:
		cp = &DisconnectPacket{FixedHeader: &FixedHeader{MessageType: Disconnect}}
	case Publish:
		cp = &PublishPacket{FixedHeader: &FixedHeader{MessageType: Publish}}
	case Puback:
		cp = &PubackPacket{FixedHeader: &FixedHeader{MessageType: Puback}}
	case Pubrec:
		cp = &PubrecPacket{FixedHeader: &FixedHeader{MessageType: Pubrec}}
	case Pubrel:
		cp = &PubrelPacket{FixedHeader: &FixedHeader{MessageType: Pubrel, Qos: 1}}
	case Pubcomp:
		cp = &PubcompPacket{FixedHeader: &FixedHeader{MessageType: Pubcomp}}
	case Subscribe:
		cp = &SubscribePacket{FixedHeader: &FixedHeader{MessageType: Subscribe, Qos: 1}}
	case Suback:
		cp = &SubackPacket{FixedHeader: &FixedHeader{MessageType: Suback}}
	case Unsubscribe:
		cp = &UnsubscribePacket{FixedHeader: &FixedHeader{MessageType: Unsubscribe, Qos: 1}}
	case Unsuback:
		cp = &UnsubackPacket{FixedHeader: &FixedHeader{MessageType: Unsuback}}
	case Pingreq:
		cp = &PingreqPacket{FixedHeader: &FixedHeader{MessageType: Pingreq}}
	case Pingresp:
		cp = &PingrespPacket{FixedHeader: &FixedHeader{MessageType: Pingresp}}
	default:
		return nil
	}
	return cp
}
572446
func NewNgram(buf []byte) Ngram {
	ngram := make(Ngram, len(buf))
	copy(ngram, buf)
	return ngram
}
1373580
func NewHTTP(remote, wsEndpoint string) *HTTP {
	rc := rpcclient.NewJSONRPCClient(remote)
	cdc := rc.Codec()
	ctypes.RegisterAmino(cdc)
	rc.SetCodec(cdc)

	return &HTTP{
		rpc:      rc,
		remote:   remote,
		WSEvents: newWSEvents(cdc, remote, wsEndpoint),
	}
}