internal OpusTags(_OpusTags opusTags) { var commentPtrs = new IntPtr[opusTags.comments]; Marshal.Copy(opusTags.user_comments, commentPtrs, 0, opusTags.comments); var lengths = new int[opusTags.comments]; Marshal.Copy(opusTags.comment_lengths, lengths, 0, opusTags.comments); byte[] buf; _comments = new List <KeyValuePair <string, string> >(); for (int i = 0; i < opusTags.comments; i++) { buf = new byte[lengths[i]]; Marshal.Copy(commentPtrs[i], buf, 0, lengths[i]); var str = System.Text.Encoding.UTF8.GetString(buf); var halves = str.Split(new[] { '=' }, 2); _comments.Add(new KeyValuePair <string, string>(halves[0], halves[1])); } int len = 0; while (Marshal.ReadByte(opusTags.vendor, len) != 0) { len++; } buf = new byte[len]; Marshal.Copy(opusTags.vendor, buf, 0, len); _vendor = System.Text.Encoding.UTF8.GetString(buf); }
internal OpusTags(_OpusTags opusTags) { var commentPtrs = new IntPtr[opusTags.comments]; Marshal.Copy(opusTags.user_comments, commentPtrs, 0, opusTags.comments); var lengths = new int[opusTags.comments]; Marshal.Copy(opusTags.comment_lengths, lengths, 0, opusTags.comments); byte[] buf; _comments = new List<KeyValuePair<string, string>>(); for (int i = 0; i < opusTags.comments; i++) { buf = new byte[lengths[i]]; Marshal.Copy(commentPtrs[i], buf, 0, lengths[i]); var str = System.Text.Encoding.UTF8.GetString(buf); var halves = str.Split(new[] { '=' }, 2); _comments.Add(new KeyValuePair<string, string>(halves[0], halves[1])); } int len = 0; while (Marshal.ReadByte(opusTags.vendor, len) != 0) len++; buf = new byte[len]; Marshal.Copy(opusTags.vendor, buf, 0, len); _vendor = System.Text.Encoding.UTF8.GetString(buf); }