public void WriteString(string value) { Grow(4); if (value == null) { IntToByte map = new IntToByte() { Value = 0 }; _buffer[_size++] = map.Byte0; _buffer[_size++] = map.Byte1; _buffer[_size++] = map.Byte2; _buffer[_size++] = map.Byte3; } else { byte[] utfBytes = Encoding.UTF8.GetBytes(value); int count = utfBytes.Length; IntToByte map = new IntToByte() { Value = count + 1 }; _buffer[_size++] = map.Byte0; _buffer[_size++] = map.Byte1; _buffer[_size++] = map.Byte2; _buffer[_size++] = map.Byte3; Grow(count); Buffer.BlockCopy(utfBytes, 0, _buffer, _size, count); _size += count; } }
public int ReadInt() { Check(4); IntToByte block = new IntToByte { Byte0 = _buffer[_position++], Byte1 = _buffer[_position++], Byte2 = _buffer[_position++], Byte3 = _buffer[_position++] }; return(block.Value); }
public void WriteInt(int value) { IntToByte block = new IntToByte() { Value = value }; Grow(4); _buffer[_size++] = block.Byte0; _buffer[_size++] = block.Byte1; _buffer[_size++] = block.Byte2; _buffer[_size++] = block.Byte3; }
public void EndSection() { int pos = _sectionsStack.Pop(); int sectionSize = _size - pos - 4; IntToByte block = new IntToByte() { Value = sectionSize }; _buffer[pos++] = block.Byte0; _buffer[pos++] = block.Byte1; _buffer[pos++] = block.Byte2; _buffer[pos++] = block.Byte3; }