小编emi*_*dar的帖子

Julia - 从 UInt8 数组读取 UInt32

我有从 TCPSocket 获得的 UInt8 数据数组。

我想从不同的索引中读取 UInt32s 和 UInt16s。

例如:

data = UInt8[0xFF, 0x00, 0x00, 0x00, 0xAA, 0x00]

// Something like this:
extracted_UInt32 = data.readUInt32(1) # [1-4]
extracted_UInt16 = data.readUInt16(5) # [5-6]
Run Code Online (Sandbox Code Playgroud)

它就像 Node.js 的Buffer.readUInt16LE(offset)https : //nodejs.org/api/buffer.html#buffer_buf_readint16le_offset

谢谢!

arrays data-conversion julia

2
推荐指数
2
解决办法
216
查看次数

如何保持全球 Postgres 连接?

我想将 Postgres 连接存储在全局范围内,以便从模块中的任何函数进行访问。这是一个例子:

use postgres::{Client, NoTls};

static mut client: Option<Client> = None;

pub fn get_player(id: i32) {
    // Use global client connection object:
    for row in client.unwrap().query("SELECT * FROM public.\"User\" WHERE \"accountID\"=$1;",&[&id]).unwrap(){
        let id: i32 = row.get(0);
        let name: &str = row.get(1);

        println!("found player: {} {}", id, name);
    }
}

pub fn init() {
    let mut connection = Client::connect("host=localhost user=postgres", NoTls);
    match connection {
        Ok(cli) => {
            println!("Database connected.");
            client = Some(cli);
        }
        Err(_) => println!("Database ERROR while …
Run Code Online (Sandbox Code Playgroud)

postgresql static global-variables rust

1
推荐指数
1
解决办法
1923
查看次数