var Frame = require('./frame').Frame;

function StompParse() { };

StompParse.prototype.extract_command = function(data) {
  var command,
      data_string = data.toString('utf8', start=0, end=data.length);
  command = data_string.split('\n');
  return command[0];
};

StompParse.prototype.extract_headers = function(data) {
  var command,
      the_headers = {},
      data_string = data.toString('utf8', start-0, end=data.length);

  headers_string = data_string.split('\n\n', 1);
  headers_split = headers_string[0].split('\n');

  for (var i = 0; i < headers_split.length; i++) {
        var one_header = headers_split[i].split(':');
        if (one_header.length > 1) {
            var header_key = one_header.shift();
            var header_val = one_header.join(':');
            the_headers[header_key] = header_val;
        }
        else {
            the_headers[one_header[0]] = one_header[1];
        }
  }

  var return_values = {
    length: headers_string[0].length,
    headers: the_headers
  }

  return return_values;

};

StompParse.prototype.parse_frame = function(data) {
  var args = {},
      header_data = {},
      command = null,
      headers = null,
      body = null;

  if (!data) {
    return null;
  }

  command = this.extract_command(data);
  if (command) {
    data = data.slice(command.length + 1, data.length);
  }
  header_data = this.extract_headers(data);

  if (header_data && header_data.length > 1) {
    data = data.slice(header_data.lenth + 1, data.length);
    headers = header_data.headers;
    if ('content-length' in headers) {
      headers['bytes_message'] = true;
    }
  }

  body = data;

  args = {
    command: command,
    headers: headers,
    body: body
  }

  var frame = new Frame();
  return frame.build_frame(args);

};


module.exports.StompParse = StompParse;

@@ -573,28 +573,24 @@
 gth; i++) %7B%0A
-    
     var one_
@@ -623,28 +623,24 @@
 split(':');%0A
-    
     if (one_
@@ -662,30 +662,24 @@
  1) %7B%0A      
-   
-   
 var header_k
@@ -709,22 +709,16 @@
 ;%0A      
-   
-   
 var head
@@ -750,30 +750,24 @@
 ':');%0A      
-  
-    
 the_headers%5B
@@ -800,35 +800,21 @@
     
-    %7D%0A   
+%7D%0A
     
- 
 else %7B%0A
-      
     
@@ -859,20 +859,16 @@
 der%5B1%5D;%0A
-    
     %7D%0A  
@@ -1734,17 +1734,16 @@
 );%0A%0A%7D;%0A%0A
-%0A
 module.e

clean up for great good