int SetCharSequence0(int index, ICharSequence sequence, Encoding encoding, bool expand) { if (ReferenceEquals(encoding, Encoding.UTF8)) { int length = ByteBufferUtil.Utf8MaxBytes(sequence); if (expand) { this.EnsureWritable0(length); this.CheckIndex0(index, length); } else { this.CheckIndex(index, length); } return(ByteBufferUtil.WriteUtf8(this, index, sequence, sequence.Count)); } if (ReferenceEquals(encoding, Encoding.ASCII)) { int length = sequence.Count; if (expand) { this.EnsureWritable0(length); this.CheckIndex0(index, length); } else { this.CheckIndex(index, length); } return(ByteBufferUtil.WriteAscii(this, index, sequence, length)); } byte[] bytes = encoding.GetBytes(sequence.ToString()); if (expand) { this.EnsureWritable0(bytes.Length); // setBytes(...) will take care of checking the indices. } this.SetBytes(index, bytes); return(bytes.Length); }
static IByteBuffer CopiedBuffer(string value, Encoding encoding) => ByteBufferUtil.EncodeString0(Allocator, true, value, encoding, 0);
public float ReadFloatLE() => ByteBufferUtil.Int32BitsToSingle(this.ReadIntLE());
public IByteBuffer SetFloatLE(int index, float value) => this.SetIntLE(index, ByteBufferUtil.SingleToInt32Bits(value));
public float GetFloatLE(int index) => ByteBufferUtil.Int32BitsToSingle(this.GetIntLE(index));
public virtual IByteBuffer SetFloat(int index, float value) { this.SetInt(index, ByteBufferUtil.SingleToInt32Bits(value)); return(this); }
public virtual bool Equals(IByteBuffer buffer) => ReferenceEquals(this, buffer) || buffer != null && ByteBufferUtil.Equals(this, buffer);
public virtual int CompareTo(IByteBuffer that) => ByteBufferUtil.Compare(this, that);
public override int GetHashCode() => ByteBufferUtil.HashCode(this);
public virtual int IndexOf(int fromIndex, int toIndex, byte value) => ByteBufferUtil.IndexOf(this, fromIndex, toIndex, value);
public virtual string ToString(int index, int length, Encoding encoding) => ByteBufferUtil.DecodeString(this, index, length, encoding);
public IByteBuffer WriteFloatLE(float value) => this.WriteIntLE(ByteBufferUtil.SingleToInt32Bits(value));
public virtual IByteBuffer WriteFloat(float value) { this.WriteInt(ByteBufferUtil.SingleToInt32Bits(value)); return(this); }