D
Deno

help

Kv encodes integer as double

ABAltair 680b8/10/2023
Anyone know why Deno.kv encodes an integer in a mutli-part key as a double?
const key = ["int", 3]
encodes to: [2,105,110,116,0,33,192,8,0,0,0,0,0,0]
const key = ["int", 3]
encodes to: [2,105,110,116,0,33,192,8,0,0,0,0,0,0]
the - 33, 192, 8 above represents a Double (code 33 = Double) with value 3 It should encode to:
[2,105,110,116,0,21,3]
[2,105,110,116,0,21,3]
21, 3 represents (code 21 = integer) 3
IioB8/10/2023
doubles are a safe way to represent JS numbers I assume that's about as deep as the reasoning goes
ABAltair 680b8/10/2023
It's very inefficient. The lib I've ported handles integers without issue. Also the rust codec seems to handle integers, but my testing shows that it is not working.
pub fn encode_key(key: &Key) -> std::io::Result<Vec<u8>> {
let mut output: Vec<u8> = vec![];
for part in &key.0 {
match part {
KeyPart::String(key) => {
output.push(STRING);
escape_raw_bytes_into(&mut output, key.as_bytes());
output.push(0);
}
KeyPart::Int(key) => {
bigint::encode_into(&mut output, key)?;
}
KeyPart::Float(key) => {
double::encode_into(&mut output, *key);
}
KeyPart::Bytes(key) => {
output.push(BYTES);
escape_raw_bytes_into(&mut output, key);
output.push(0);
}
KeyPart::False => {
output.push(FALSE);
}
KeyPart::True => {
output.push(TRUE);
}
}
}
Ok(output)
}
pub fn encode_key(key: &Key) -> std::io::Result<Vec<u8>> {
let mut output: Vec<u8> = vec![];
for part in &key.0 {
match part {
KeyPart::String(key) => {
output.push(STRING);
escape_raw_bytes_into(&mut output, key.as_bytes());
output.push(0);
}
KeyPart::Int(key) => {
bigint::encode_into(&mut output, key)?;
}
KeyPart::Float(key) => {
double::encode_into(&mut output, *key);
}
KeyPart::Bytes(key) => {
output.push(BYTES);
escape_raw_bytes_into(&mut output, key);
output.push(0);
}
KeyPart::False => {
output.push(FALSE);
}
KeyPart::True => {
output.push(TRUE);
}
}
}
Ok(output)
}
IioB8/10/2023
could you share the rest of the code in the match? I don't think this is a bug
ABAltair 680b8/10/2023
Thanks for looking! I'll have to modify my FDB-codec to match this odd behaviour. I'm building a KV utility that will display the raw k: blob and v: blob from the SQLite kv table. I re-read the docs. Looks like the only 'int' supported is Bigint, 1n. I'll modify my lib to match. Thanks again. 😊 Yes changing the key to 3n does allow encoding to integer. This returns [21, 3] where (code 21 = integer, and 3 is the value) For a large data sets, this saves 7 bytes per key.
IioB8/10/2023
good to know
ABAltair 680b8/10/2023
// key = ["int", "3"] <string, string>
[2,105,110,116,0,2,51,0]

// key = ["int", 3n] <string, Bigint>
[2,105,110,116,0,21,3]

// key = ["int", 3] <string, number>
[2,105,110,116,0,33,192,8,0,0,0,0,0,0]
// key = ["int", "3"] <string, string>
[2,105,110,116,0,2,51,0]

// key = ["int", 3n] <string, Bigint>
[2,105,110,116,0,21,3]

// key = ["int", 3] <string, number>
[2,105,110,116,0,33,192,8,0,0,0,0,0,0]

Looking for more? Join the community!

Recommended Posts
Looking for caching API ResponsesHello there, I'm looking for a package/or examples to cache API responses for a fresh project whicUsing ZeroMQ from NPMAnyone got fixed the same error as this issue? https://github.com/denoland/deno/issues/18345Trying to pass parameters to runtime from rustHi, I'm launching a deno runtime from my project's code. I'm trying to pass some dynamic json variconsole.log in a worker - capture or hide output?Running under `deno repl` with no permissions, this prints 'yee'. In a browser's dev tools it would Deno debugging configuration is missing?```json "deno.enable": true, "deno.unstable": true, "deno.enablePaths": ["./api"], "deno.docIs there a way to show permissions used on start up during runtime?For example: If I was to run an App with `permissions: --allow-net=${hostname}:${port}` is there a wrestrict path applied for import mapshi, is it possible to restrict importmap application to only specific path? the rationale is: - vscoBest way to pass backend data to SSR rendered view?Looking for the "proper" way to pass data to an SSR rendered view. My first idea is setting custom pImport mapHi I have this in deno.json: ``` "imports": { "./app.controller": "./app.controller.ts", ``` butWhat should I specify to pass a "char *" in Deno.dlopen?For example, this is how you would use it in Python: ```python import ctypes lib = ctypes.cdll.LoadOverride NPM package dependencyRelating to my question yesterday (https://canary.discord.com/channels/684898665143206084/1137532072VS Code's debugger terminates before finishedI notice that occasionally the debugger terminates at the middle of the running, or at least doesn'tI need some guidance regarding interprocess communication with DenoWhat are good cross-platform (Windows, Linux) options for interprocess communication / data sharing What is the Deno class?What is Deno in Deno.cwd() ? Can someone link me to documentation? Why doesn't the Deno class need tGetIP + Ctx from middleware to a route not passedHi, I have test to retrieve IP visitor Code taken from Discord is always returning "localhost" (wheerror: No config file found in VS CodeI'm new in Deno and in coding, and need help with the following issue. I have installed Deno throughDeclaration merging for external packagesHi! I'm using unoCSS with Deno Fresh and have been attempting to use the attributify preset (https:Deno.serve AbortController onError. How?When I run my new Deno.serve() updated implementation I get a type error. Perhaps I'm doing it wrongLocalStorage OverrideI'm using a library (@supabase/supabase-js), and I'm compiling my Deno app into an executable, howevBad implementation of X25519?I can't generate a shared secret with the current implementation of X25519 ```ts const alice = awai