private void WriteBytes(MemoryHolder address, int offset, Bytes bytes) { SimpleType st = (SimpleType)_type; Debug.Assert(st._type == SimpleTypeKind.Char && bytes.Count <= _length); address.WriteSpan(offset, bytes.AsSpan()); if (bytes.Count < _length) { address.WriteByte(checked (offset + bytes.Count), 0); } }
internal void SetRawValue(MemoryHolder owner, int offset, object value) { Debug.Assert(_type is SimpleType st && st._type == SimpleTypeKind.Char); if (value is IBufferProtocol bufferProtocol) { var buffer = bufferProtocol.GetBuffer(); var span = buffer.AsReadOnlySpan(); if (span.Length > _length) { throw PythonOps.ValueError("byte string too long ({0}, maximum length {1})", span.Length, _length); } owner.WriteSpan(offset, span); return; } throw PythonOps.TypeErrorForBytesLikeTypeMismatch(value); }