func (Websocket) Decode(reader io.Reader) (packet.Payload, error) {
	encoded, err := ioutil.ReadAll(reader)

	if err != nil {
		return nil, err
	}

	if len(encoded) == 0 {
		return nil, errors.New("invalid packet type")
	}

	var binary bool
	var packetType packet.Type

	typeByte := encoded[0]

	if unicode.IsNumber(rune(typeByte)) {
		binary = false
		packetType = packet.TypeFromChar(typeByte)
	} else {
		binary = true
		packetType = packet.TypeFromByte(typeByte)
	}

	data := encoded[1:]

	decoded := packet.Packet{
		Binary: binary,
		Type:   packetType,
		Data:   data,
	}

	return packet.Payload{decoded}, nil
}
// Decode decodes single packet from encoded payload
Decode decodes single packet from encoded payload
// Decode decodes single packet from encoded payload
func (Websocket) Decode(reader io.Reader) (packet.Payload, error) {
	encoded, err := ioutil.ReadAll(reader)
	if err != nil {
		return nil, err
	}
	if len(encoded) == 0 {
		return nil, errors.New("invalid packet type")
	}
	var binary bool
	var packetType packet.Type
	typeByte := encoded[0]
	if unicode.IsNumber(rune(typeByte)) {
		binary = false
		packetType = packet.TypeFromChar(typeByte)
	} else {
		binary = true
		packetType = packet.TypeFromByte(typeByte)
	}
	data := encoded[1:]
	decoded := packet.Packet{
		Binary: binary,
		Type:   packetType,
		Data:   data,
	}
	return packet.Payload{decoded}, nil
}
func ( Websocket ) Decode ( reader io . Reader ) ( packet . Payload , error ) { encoded , err := ioutil . ReadAll ( reader ) if err != nil { return nil , err } if len ( encoded ) == 0 { return nil , errors . New ( " " ) } var binary bool var packetType packet . Type typeByte := encoded [ 0 ] if unicode . IsNumber ( rune ( typeByte ) ) { binary = false packetType = packet . TypeFromChar ( typeByte ) } else { binary = true packetType = packet . TypeFromByte ( typeByte ) } data := encoded [ 1 : ] decoded := packet . Packet { Binary : binary , Type : packetType , Data : data , } return packet . Payload { decoded } , nil }
Decode decodes single packet from encoded payload
Decode decodes single packet from encoded payload