Ejemplo n.º 1
0
 // Parses a field from bytes starting from position 'start' and ending at 'end'.
 // Advances 'start' to the start of the next field. Throws if there is no field between
 // start and end.
 public static Field ParseField(byte[] bytes, ref int start, int end)
 {
     int fieldMiddle = Find(Delimiters.TagValueSeparator, bytes, start, end);
     int fieldEnd = Find(Delimiters.FieldDelimiter, bytes, fieldMiddle + 1, end);
     var res = new Field(
         new ArraySegment<byte>(bytes, start, fieldMiddle - start),
         new ArraySegment<byte>(bytes, fieldMiddle + 1, fieldEnd - fieldMiddle - 1));
     start = fieldEnd + 1;
     return res;
 }
Ejemplo n.º 2
0
 static void WriteField(Stream strm, Field field, ref byte checksum, StringBuilder log)
 {
     if (log != null)
     {
         log.Append(field);
         log.Append((char)Delimiters.FieldDelimiter);
     }
     WriteBytes(strm, field.Tag, ref checksum);
     WriteByte(strm, Delimiters.TagValueSeparator, ref checksum);
     WriteBytes(strm, field.Value, ref checksum);
     WriteByte(strm, Delimiters.FieldDelimiter, ref checksum);
 }