Osc.InsertString C# (CSharp) Method

InsertString() private static method

Inserts a string, correctly padded into a packet. Used internally.
private static InsertString ( string s, byte packet, int start, int length ) : int
s string
packet byte The packet of bytes to be parsed.
start int The index of where to start looking in the packet.
length int The length of the packet.
return int
    private static int InsertString(string s, byte[] packet, int start, int length)
    {
      int index = start;
      foreach (char c in s)
      {
        packet[index++] = (byte)c;
        if (index == length)
          return index;
      }
      packet[index++] = 0;
      int pad = (s.Length+1) % 4;
      if (pad != 0)
      {
        pad = 4 - pad;
        while (pad-- > 0)
          packet[index++] = 0;
      }
      return index;
    }