hex
This commit is contained in:
parent
c5cc2f35a5
commit
8ae2353cab
|
@ -443,6 +443,18 @@ proc globFunc(env: Env; args: NodeObj): NodeRef =
|
|||
else:
|
||||
result = newNodeError("invalid glob argument", n)
|
||||
|
||||
proc hexFunc(env: Env; args: NodeObj): NodeRef =
|
||||
assertArgCount(args, 1)
|
||||
let a = args.atom
|
||||
case a.kind
|
||||
of atomBlob:
|
||||
a.blob.toHex.newAtomString.newNode
|
||||
of atomSet:
|
||||
let cold = commit(env.store, a.bs)
|
||||
cold.setId.toHex.newAtomString.newNode
|
||||
else:
|
||||
newNodeError("cannot convert to hex", args)
|
||||
|
||||
proc keyFunc(env: Env; args: NodeObj): NodeRef =
|
||||
assertArgCount(args, 1)
|
||||
args.atom.str.toKey.newAtom.newNode
|
||||
|
@ -557,6 +569,7 @@ proc newEnv(store: BlobStore): Env =
|
|||
#result.bindEnv "copy", copyFunc
|
||||
result.bindEnv "define", defineFunc
|
||||
result.bindEnv "glob", globFunc
|
||||
result.bindEnv "hex", hexFunc
|
||||
result.bindEnv "ingest", ingestFunc
|
||||
result.bindEnv "insert", insertFunc
|
||||
result.bindEnv "key", keyFunc
|
||||
|
|
|
@ -13,6 +13,7 @@ const
|
|||
blobLeafSize* = 1 shl 14
|
||||
## Size of blob leaves.
|
||||
blobLeafSizeMask* = not(not(0) shl 14)
|
||||
blobHexLen* = 32 * 2
|
||||
blobVisualLen* = 32 * 3
|
||||
|
||||
maxChunkSize* {.deprecated} = blobLeafSize
|
||||
|
@ -37,13 +38,18 @@ func `$`*(bh: BlobId): string =
|
|||
fastToUTF8Copy(r, result, pos, true)
|
||||
|
||||
func parseStringId[T](s: string): T =
|
||||
if s.len == blobVisualLen:
|
||||
case s.len
|
||||
of blobHexLen:
|
||||
hex.decode s, result.data
|
||||
of blobVisualLen:
|
||||
var
|
||||
pos: int
|
||||
r: Rune
|
||||
for b in result.data.mitems:
|
||||
fastRuneAt(s, pos, r, true)
|
||||
b = r.byte
|
||||
else:
|
||||
raise newException(ValueError, "invalid blobset id encoding")
|
||||
|
||||
func parseCborId[T](c: CborNode): T =
|
||||
## Parse a CBOR node to binary.
|
||||
|
@ -94,7 +100,7 @@ proc toBlobId*(cbor: CborNode): BlobId =
|
|||
|
||||
{.deprecated: [newCborBytes: toCbor].}
|
||||
|
||||
proc toHex*(cid: BlobId): string = hex.encode(cid.data)
|
||||
proc toHex*(id: BlobId|SetId): string = hex.encode(id.data)
|
||||
## Return BlobId encoded in hexidecimal.
|
||||
|
||||
proc writeUvarint*(s: Stream; n: SomeInteger) =
|
||||
|
|
Loading…
Reference in New Issue