returns msg,buf_remaining or None,buf
487143
def complete_message(buf):
  ""
  # todo: read dollar-length for strings; I dont think I can blindly trust newlines. learn about escaping
  # note: all the length checks are +1 over what I need because I'm asking for *complete* lines.
  lines=buf.split('\r\n')
  if len(lines)<=1: return None,buf
  nargs_raw=lines.pop(0)
  assert nargs_raw[0]=='*'
  nargs=int(nargs_raw[1:])
  args=[]
  while len(lines)>=2: # 2 because if there isn't at least a blank at the end, we're missing a terminator
    if lines[0][0]=='+': args.append(lines.pop(0))
    elif lines[0][0]==':': args.append(int(lines.pop(0)[1:]))
    elif lines[0][0]=='$':
      if len(lines)<3: return None,buf
      slen,s=int(lines[0][1:]),lines[1]
      if slen!=len(s): raise ValueError('length mismatch %s %r'%(slen,s)) # probably an escaping issue
      lines=lines[2:]
      args.append(s)
    else: raise ValueError('expected initial code in %r'%lines)
  if len(args)==nargs: return args,'\r\n'.join(lines)
  else: return None,buf
72972
def parse(self, buf):
        
        self._tokenizer = tokenize_asdl(buf)
        self._advance()
        return self._parse_module()
1209111
public static String getString(ByteBuffer buf, Charset encoding) {
        return getString(buf, 0, buf.remaining(), encoding);
    }
205426
public static ByteBuffer minimalBufferFor(ByteBuffer buf)
    {
        return buf.capacity() > buf.remaining() || !buf.hasArray() ? ByteBuffer.wrap(getArray(buf)) : buf;
    }
609149
public static String checkNonEmpty(String s, String msg) {
    checkArgument(!s.isEmpty(), msg);
    return s;
  }
96394
def alt40fms(msg):
    
    d = hex2bin(data(msg))

    if d[13] == '0':
        return None

    alt = bin2int(d[14:26]) * 16    # ft
    return alt
887850
def last_commit_msg(self) -> str:
        
        last_msg: str = self.latest_commit().message.rstrip()
        LOGGER.debug('last msg: %s', last_msg)
        return last_msg
910832
def parse_buf(self, encoding="unicode"):
        
        buf_len = len(self.buf)
        replies = []
        reply = b""
        chop = 0
        skip = 0
        i = 0
        buf_len = len(self.buf)
        for i in range(0, buf_len):
            ch = self.buf[i:i + 1]
            if skip:
                skip -= 1
                i += 1
                continue

            nxt = i + 1
            if nxt < buf_len:
                if ch == b"\r" and self.buf[nxt:nxt + 1] == b"\n":

                    # Append new reply.
                    if reply != b"":
                        if encoding == "unicode":
                            replies.append(encode_str(reply, encoding))
                        else:
                            replies.append(reply)
                        reply = b""

                    # Truncate the whole buf if chop is out of bounds.
                    chop = nxt + 1
                    skip = 1
                    i += 1
                    continue

            reply += ch
            i += 1

        # Truncate buf.
        if chop:
            self.buf = self.buf[chop:]

        return replies
95229
def sp_msg(cmd, pipe=None, data=None):
    """"""
    msg = [SP_HEADER, cmd]
    if pipe is not None:
        msg.append(pipe)
    if data is not None:
        msg.append(data)
    return msg
713949
def next_msg
      data = ""
      crlf = "\r\n"
      left = 1024 # 1024 byte, no idea if it's ever getting bigger
      while left > 0
        buf = @socket.read(left > 1 ? 1 : left)
        break if buf.nil?
        left -= buf.bytesize
        data += buf
        break if data.include? crlf # crlf means line finished, the TCP socket keeps on listening, so we break
      end
      readline = data.chomp.split(" ")
      DBus.logger.debug "readline: #{readline.inspect}"
      readline
    end
220922
def trim_and_retry(buf)
      *lines, last = buf

      # For inner Array or Hash or Arguments list.
      lines << last.gsub(/,\s*$/, "")
      do_parse("a(#{lines.join})") # wrap dummy method
    rescue ::Parser::SyntaxError
    end
194304
def parse_done(self, buf: memoryview) -> Tuple[bool, memoryview]:
        
        match = self._pattern.match(buf)
        if not match:
            raise NotParseable(buf)
        done = match.group(1).upper() == self.continuation
        buf = buf[match.end(0):]
        return done, buf
825751
def buffer(self, buf):
        
        try:  # attempt python3 approach first
            return str(_buffer(self._magic_t, buf, len(buf)), 'utf-8')
        except:
            return _buffer(self._magic_t, buf, len(buf))
490409
def read_some(self):
        
        self.process_rawq()
        while self.cookedq.tell() == 0 and not self.eof:
            self.fill_rawq()
            self.process_rawq()
        buf = self.cookedq.getvalue()
        self.cookedq.seek(0)
        self.cookedq.truncate()
        return buf
73820
def alt40mcp(msg):
    
    d = hex2bin(data(msg))

    if d[0] == '0':
        return None

    alt = bin2int(d[1:13]) * 16    # ft
    return alt
1108287
def get_statusmsg(self) -> str:
        
        if self._last_status is None:
            return self._last_status
        return self._last_status.decode()
60228
def _extract_msg(args, kwargs, msg_idx, default_msg, non_msg_params):
    '''
    '''
    rem_args = []
    if 'msg' in kwargs:
        msg = kwargs.pop('msg')
    elif len(args) > non_msg_params and msg_idx < len(args):
        msg = args[msg_idx]
        if 0 <= msg_idx:
            rem_args = args[msg_idx + 1:]
        args = args[:msg_idx]
    else:
        msg = default_msg
    return msg, args, rem_args, kwargs