在C#中,我有一个32位值,我将其存储在int中.我需要查看是否设置了特定位.我需要的是0x00010000
.
我想出了这个解决方案:
这是我正在寻找的:
Hex: 0 0 0 1 0 0 0 0 0 Binary 0000|0000|0000|0001|0000|0000|0000|0000|0000
所以我右移16号,这会给我:
Hex: 0 0 0 0 0 0 0 0 1 Binary 0000|0000|0000|0000|0000|0000|0000|0000|0001
我然后向左移3,这会给我:
Hex: 0 0 0 0 0 0 0 0 8 Binary 0000|0000|0000|0000|0000|0000|0000|0000|1000
然后我将我的32位值设置为一个字节,看看它是否等于8.
所以我的代码将是这样的:
int value = 0x102F1032;
value = value >> 16;
byte bits = (byte)value << 3;
bits == 8 ? true : false;
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法来检查是否在没有所有移位的情况下设置了特定位?
我必须在 Rust 二进制文件中发送一个json
和一个文件。toml
它是一个独立的应用程序,人们不想在运行时传递配置文件。
include_str!
做我想做的事。我可以写:
static SETTINGS_FILE_STR: &str = include_str!(r"../my_config/settings.toml");
Run Code Online (Sandbox Code Playgroud)
有没有比 更好的方法来写入文件路径r"../my_config/settings.toml"
?
我似乎无法从orstring literal
内部的任何内容构造 a 。我想知道是否可以从文件中读取一些内容。没有运气。use std::path::{Path, PathBuf};
env
cargo.toml
我总是打:
error: argument must be a string literal
--> src/main.rs:23:42
|
23 | static SETTINGS_STR: &str = include_str!(FANCY_PATH_TO_TOML_FILE);
| ^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
我无法执行以下操作,因为String
不是字符串文字:
fn get_config_path() -> String {
let root_dir = project_root::get_project_root().with_context(|| format!("Failed to get project root directory"))?;
const path: PathBuf = root_dir.join("my_config/settings.toml");
path.to_string()
}
Run Code Online (Sandbox Code Playgroud)
如果这是 C / Objective-C,我可以使用构造函数或类函数来实现我想要的。正如您可能已经猜到的,我是 …
如何让 Poetrydev
仅更新依赖项latest
?
我原来有:
[tool.poetry.dev-dependencies]
pytest = "^4.6"
Run Code Online (Sandbox Code Playgroud)
但我想要:
[tool.poetry.dev-dependencies]
pytest = "^6.0"
Run Code Online (Sandbox Code Playgroud)
我通过手动编辑文件来实现它pyproject.toml
。
当我运行poetry update
它时(出色地)碰撞了我所有正常的(非开发)依赖项。
使用 lldb,我想在我的发布 iOS 构建和发布动态框架中实例化一个 Swift 类。
我在模拟器上将 lldb 附加到我的发布版本。
主应用程序 - 有效
(lldb) exp let $c = hello_class()
error: <EXPR>:3:10: error: use of unresolved identifier 'hello_class'
let $c = hello_class()
^~~~~~~~~~~
(lldb) expr import My_App
(lldb) exp let $c = hello_class()
(lldb) po $c.hello()
hello
Run Code Online (Sandbox Code Playgroud)
动态框架 - 失败
(lldb) dclass -m myframework
Dumping classes
************************************************************
myframework.RustyAppInfo
(lldb) expr import myframework
(lldb) expr let $d = RustyAppInfo()
error: Couldn't lookup symbols:
__T011myframework12RustyAppInfoCACycfC
Run Code Online (Sandbox Code Playgroud)
应用程序和动态框架都是在没有优化的情况下构建的。
更新
静态框架 - 失败
更改时的结果相同 - Xcode 9 …
如何在带有HTTPRequest
结构的Vapor 3中发送API请求?
我尝试了以下代码的变体..
var headers: HTTPHeaders = .init()
let body = HTTPBody(string: a)
let httpReq = HTTPRequest(
method: .POST,
url: URL(string: "/post")!,
headers: headers,
body: body)
let httpRes: EventLoopFuture<HTTPResponse> = HTTPClient.connect(hostname: "httpbin.org", on: req).map(to: HTTPResponse.self) { client in
return client.send(httpReq)
}
Run Code Online (Sandbox Code Playgroud)
编译错误 Cannot convert value of type '(HTTPClient) -> EventLoopFuture<HTTPResponse>' to expected argument type '(HTTPClient) -> _'
我尝试了其他有效的代码变体。
let client = try req.make(Client.self)
let response: Future<Response> = client.get("http://example.vapor.codes/json")
Run Code Online (Sandbox Code Playgroud)
我阅读并重新阅读:
let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification,
object: nil,
queue: mainQueue) { notification in
print("[!]detected screenshot")
}
Run Code Online (Sandbox Code Playgroud)
它位于 viewDidLoad() 中,每次我访问 viewController 时,它都会添加另一个屏幕截图观察器。因此,如果我在同一个会话中访问视图控制器两次,那么当我截图时它会执行两次。如果我要访问视图控制器,该函数将运行四次,那么屏幕截图观察者将执行四次。如何防止在视图控制器会话之间重新声明它?感谢您的帮助。
在我的Package.swift文件中尝试更新的版本后,我的Vapor和Vapor-MySQL设置就死了.
最终,我想要一个包含以下内容的Package.swift:
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 0, minor: 16),
.Package(url: "https://github.com/vapor/mysql-provider.git", majorVersion: 0, minor: 4)
然后我跑了
vapor build --mysql
那工作.没有错误报告.
然后我转到Xcode来构建项目并点击运行.
然后我遇到了很多框架错误."Pathindexable"."CryptoEssentials"和"Node"框架.似乎是链接器错误.
然后我跑了vapor clean
.在Xcode中清理了我的项目.没有快乐.
知道为什么这不起作用吗?
我已经打了好几个星期了.为什么以下macOS设置会产生Alamofire链接器错误?
重新创建链接器错误的步骤:
创建以下podfile:
平台:osx,'10 .10'目标'testMacOS'做use_frameworks!pod'Alamofire','〜> 4.0'结束
跑pod install
.打开和构建工作区
错误:dyld:未加载库:@ rpath/Alamofire.framework/Versions/A/Alamofire 原因:找不到图像
在这一点上,这个错误是有道理的.您需要转到Target的/ General/Linked Frameworks和Libraries.然后添加Alamofire.现在,Alamofire位于工作区的Framework目录中.
建立并运行.同样的错误.为什么?
使用我的调试器(lldb)我可以在Objective-C代码时轻松创建Instances类.
(lldb) e id $my_hello = [hello_from_objc new]
(lldb) po $my_hello
<hello_from_objc: 0x1c4013020>
(lldb) po [$my_hello secret_objc_method]
0x000000000000002a
(lldb) po (int) [$my_hello secret_objc_method]
42
Run Code Online (Sandbox Code Playgroud)
但是当代码是纯Swift时,我无法弄清楚如何用lldb的表达式命令做同样的事情.我很容易在Swift代码中创建一个实例.
let my_swift_framework = Hello_Class()
print("?? \(my_swift_framework.samplePublicVariable)")
Run Code Online (Sandbox Code Playgroud) 这个问题是关于Swift Web Framework,Vapor.
我正在尝试使用Swift的Package Manager导入VaporMySQL框架.
我已经在本地运行数据库,mySQL端口打开并正常工作,mySQL数据库正在运行,Vapor应用程序正在运行[我写了几个GET/POST请求有效].
但我无法导入VaporMySQL. 这可能与我对Package.swift缺乏了解有关.
let package = Package(
name: "HelloWorld",
dependencies: [
.Package(url: "https://github.com/qutheory/vapor.git", majorVersion: 0, minor: 10),
.Package(url: "https://github.com/qutheory/cmysql.git", majorVersion: 0, minor: 2)
Run Code Online (Sandbox Code Playgroud) 我按照如何memset char数组与空终止字符?使用C memset
api 时添加空终止符.
代码有效; 由于null终止符,我不再在malloc'd char数组的末尾添加奇怪的内存中字符.
/* memset does not add a null terminator */
static void yd_vanilla_stars(size_t *number_of_chars, char *chars_to_pad)
{
memset(chars_to_pad, 0, *number_of_chars+1);
memset(chars_to_pad,'*',*number_of_chars);
}
Run Code Online (Sandbox Code Playgroud)
是否有更优雅的方式实现同样的目标?