func readMessage(length uint32, reader *bufio.Reader) (proto.Message, error) {
	nameLengthByte, err := reader.ReadByte()
	if err != nil {
		return nil, err
	}
	nameLength := uint8(nameLengthByte)
	nameBytes := make([]byte, nameLength)

	_, err = io.ReadFull(reader, nameBytes)
	if err != nil {
		return nil, err
	}
	messageName := string(nameBytes)
	if !strings.HasPrefix(messageName, "pb.") {
		return nil, fmt.Errorf("invalid message name")
	}
	messageType := proto.MessageType(messageName)
	if messageType == nil {
		return nil, fmt.Errorf("could not get message type")
	}

	t := messageType.Elem()
	messagePtr := reflect.New(t)
	message := messagePtr.Interface().(proto.Message)
	if message == nil {
		return nil, fmt.Errorf("could not find message type \"%s\"", messageName)
	}

	data := make([]byte, length-1-uint32(nameLength))
	_, err = io.ReadFull(reader, data)
	if err != nil {
		return nil, err
	}
	err = proto.Unmarshal(data, message)
	if err != nil {
		return nil, err
	}

	return message, nil
}
// readMessage reads a message name and message from the provided reader.
readMessage reads a message name and message from the provided reader.
// readMessage reads a message name and message from the provided reader .
func readMessage(length uint32, reader *bufio.Reader) (proto.Message, error) {
	nameLengthByte, err := reader.ReadByte()
	if err != nil {
		return nil, err
	}
	nameLength := uint8(nameLengthByte)
	nameBytes := make([]byte, nameLength)
	_, err = io.ReadFull(reader, nameBytes)
	if err != nil {
		return nil, err
	}
	messageName := string(nameBytes)
	if !strings.HasPrefix(messageName, "pb.") {
		return nil, fmt.Errorf("invalid message name")
	}
	messageType := proto.MessageType(messageName)
	if messageType == nil {
		return nil, fmt.Errorf("could not get message type")
	}
	t := messageType.Elem()
	messagePtr := reflect.New(t)
	message := messagePtr.Interface().(proto.Message)
	if message == nil {
		return nil, fmt.Errorf("could not find message type \"%s\"", messageName)
	}
	data := make([]byte, length-1-uint32(nameLength))
	_, err = io.ReadFull(reader, data)
	if err != nil {
		return nil, err
	}
	err = proto.Unmarshal(data, message)
	if err != nil {
		return nil, err
	}
	return message, nil
}
func readMessage ( length uint32 , reader * bufio . Reader ) ( proto . Message , error ) { nameLengthByte , err := reader . ReadByte ( ) if err != nil { return nil , err } nameLength := uint8 ( nameLengthByte ) nameBytes := make ( [ ] byte , nameLength ) _ , err = io . ReadFull ( reader , nameBytes ) if err != nil { return nil , err } messageName := string ( nameBytes ) if ! strings . HasPrefix ( messageName , " " ) { return nil , fmt . Errorf ( " " ) } messageType := proto . MessageType ( messageName ) if messageType == nil { return nil , fmt . Errorf ( " " ) } t := messageType . Elem ( ) messagePtr := reflect . New ( t ) message := messagePtr . Interface ( ) . ( proto . Message ) if message == nil { return nil , fmt . Errorf ( " \" \" " , messageName ) } data := make ( [ ] byte , length - 1 - uint32 ( nameLength ) ) _ , err = io . ReadFull ( reader , data ) if err != nil { return nil , err } err = proto . Unmarshal ( data , message ) if err != nil { return nil , err } return message , nil }
readMessage reads a message name and message from the provided reader.
readMessage reads a message name and message from the provided reader .