@hazae41/binary
Advanced tools
Comparing version 1.2.19 to 1.2.20
import { Bytes } from '@hazae41/bytes'; | ||
import { Result } from '@hazae41/result'; | ||
import { Writable } from './writable.js'; | ||
import { Writable, BinaryWriteUnderflowError } from './writable.js'; | ||
@@ -8,7 +8,7 @@ /** | ||
*/ | ||
interface Preparable { | ||
interface Preparable<T extends Writable = Writable> { | ||
/** | ||
* Prepare to a writable | ||
*/ | ||
tryPrepare(): Result<Writable, Error>; | ||
tryPrepare(): Result<T, Error>; | ||
} | ||
@@ -21,5 +21,5 @@ declare namespace Preparable { | ||
*/ | ||
function tryPrepareToBytes(preparable: Preparable): Result<Bytes, Error>; | ||
function tryPrepareToBytes(preparable: Preparable): Result<Bytes, Error | BinaryWriteUnderflowError>; | ||
} | ||
export { Preparable }; |
{ | ||
"type": "module", | ||
"name": "@hazae41/binary", | ||
"version": "1.2.19", | ||
"version": "1.2.20", | ||
"description": "Zero-copy binary data types", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/hazae41/binary", |
@@ -37,3 +37,3 @@ <div align="center"> | ||
write(cursor: Cursor): Result<void, Error> { | ||
try { | ||
return Result.unthrowSync(() => { | ||
cursor.tryWriteUint8(this.x).throw() | ||
@@ -43,5 +43,3 @@ cursor.tryWriteUint16(this.y).throw() | ||
return Ok.void() | ||
} catch(e: unknown) { | ||
return Err.catch(e, Error) | ||
} | ||
}, Error) | ||
} | ||
@@ -54,3 +52,3 @@ | ||
const myobject = new MyObject(1, 515) | ||
const bytes = Writable.tryToBytes(myobject).unwrap() // Uint8Array([1, 2, 3]) | ||
const bytes = Writable.tryWriteToBytes(myobject).unwrap() // Uint8Array([1, 2, 3]) | ||
``` | ||
@@ -69,3 +67,3 @@ | ||
static read(cursor: Cursor): Result<MyObject, Error> { | ||
try { | ||
return Result.unthrowSync(() => { | ||
const x = cursor.tryReadUint8().throw() | ||
@@ -75,5 +73,3 @@ const y = cursor.tryReadUint16().throw() | ||
return new Ok(new this(x, y)) | ||
} catch(e: unknown) { | ||
return Err.catch(e, Error) | ||
} | ||
}, Error) | ||
} | ||
@@ -86,3 +82,3 @@ | ||
const bytes = new Uint8Array([1, 2, 3]) | ||
const myobject = Readable.tryFromBytes(MyObject, bytes).unwrap() // MyObject(1, 515) | ||
const myobject = Readable.tryReadFromBytes(MyObject, bytes).unwrap() // MyObject(1, 515) | ||
``` | ||
@@ -96,3 +92,3 @@ | ||
const bytes = new Uint8Array([1, 2, 3]) | ||
const opaque = Readable.fromBytes(SafeOpaque, bytes).unwrap() // Opaque(Uint8Array([1, 2, 3])) | ||
const opaque = Readable.tryReadFromBytes(SafeOpaque, bytes).unwrap() // Opaque(Uint8Array([1, 2, 3])) | ||
const myobject = opaque.tryInto(MyObject).unwrap() // MyObject(1, 515) | ||
@@ -104,3 +100,3 @@ ``` | ||
const opaque = Opaque.tryFrom(myobject).unwrap() // Opaque(Uint8Array([1, 2, 3])) | ||
const bytes = Writable.toBytes(opaque).unwrap() // Uint8Array([1, 2, 3]) | ||
const bytes = Writable.tryWriteToBytes(opaque).unwrap() // Uint8Array([1, 2, 3]) | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46915
95