@hazae41/binary
Advanced tools
Comparing version 1.2.11 to 1.2.12
@@ -9,8 +9,8 @@ import { Cursor } from '@hazae41/cursor'; | ||
constructor(); | ||
prepare(): Result<this, never>; | ||
size(): number; | ||
write(cursor: Cursor): Result<void, never>; | ||
static read(cursor: Cursor): Result<Empty, never>; | ||
tryPrepare(): Result<this, never>; | ||
trySize(): Result<number, never>; | ||
tryWrite(cursor: Cursor): Result<void, never>; | ||
static tryRead(cursor: Cursor): Result<Empty, never>; | ||
} | ||
export { Empty }; |
@@ -19,5 +19,5 @@ import { Bytes, Sized } from '@hazae41/bytes'; | ||
static random<N extends number>(length: N): Opaque<Bytes<N>>; | ||
prepare(): Result<this, never>; | ||
size(): number; | ||
write(cursor: Cursor): Result<void, Error>; | ||
tryPrepare(): Result<this, never>; | ||
trySize(): Result<number, never>; | ||
tryWrite(cursor: Cursor): Result<void, Error>; | ||
/** | ||
@@ -40,3 +40,3 @@ * Transform this opaque into a binary data type | ||
declare namespace UnsafeOpaque { | ||
function read(cursor: Cursor): Result<Opaque, Error>; | ||
function tryRead(cursor: Cursor): Result<Opaque, Error>; | ||
} | ||
@@ -47,5 +47,5 @@ /** | ||
declare namespace SafeOpaque { | ||
function read(cursor: Cursor): Result<Opaque, Error>; | ||
function tryRead(cursor: Cursor): Result<Opaque, Error>; | ||
} | ||
export { Opaque, SafeOpaque, UnsafeOpaque }; |
@@ -12,3 +12,3 @@ import { Bytes } from '@hazae41/bytes'; | ||
*/ | ||
prepare(): Result<Writable, Error>; | ||
tryPrepare(): Result<Writable, Error>; | ||
} | ||
@@ -21,5 +21,5 @@ declare namespace Preparable { | ||
*/ | ||
function toBytes(preparable: Preparable): Result<Bytes, Error>; | ||
function tryPreparetoBytes(preparable: Preparable): Result<Bytes, Error>; | ||
} | ||
export { Preparable }; |
@@ -12,3 +12,3 @@ import { Cursor } from '@hazae41/cursor'; | ||
*/ | ||
read(cursor: Cursor): Result<T, Error>; | ||
tryRead(cursor: Cursor): Result<T, Error>; | ||
} | ||
@@ -24,3 +24,3 @@ declare namespace Readable { | ||
*/ | ||
function tryRead<T>(readable: Readable<T>, cursor: Cursor): Result<T, Error>; | ||
function tryReadOrRollback<T>(readable: Readable<T>, cursor: Cursor): Result<T, Error>; | ||
/** | ||
@@ -32,5 +32,5 @@ * Read a binary data type from bytes | ||
*/ | ||
function fromBytes<T>(readable: Readable<T>, bytes: Uint8Array): Result<T, Error>; | ||
function tryReadFromBytes<T>(readable: Readable<T>, bytes: Uint8Array): Result<T, Error>; | ||
} | ||
export { Readable }; |
@@ -12,3 +12,3 @@ import { Bytes } from '@hazae41/bytes'; | ||
*/ | ||
size(): number; | ||
trySize(): Result<number, Error>; | ||
/** | ||
@@ -18,3 +18,3 @@ * Write bytes to a cursor | ||
*/ | ||
write(cursor: Cursor): Result<void, Error>; | ||
tryWrite(cursor: Cursor): Result<void, Error>; | ||
} | ||
@@ -27,5 +27,5 @@ declare namespace Writable { | ||
*/ | ||
function toBytes(writable: Writable): Result<Bytes, Error>; | ||
function tryToBytes(writable: Writable): Result<Bytes, Error>; | ||
} | ||
export { Writable }; |
{ | ||
"type": "module", | ||
"name": "@hazae41/binary", | ||
"version": "1.2.11", | ||
"version": "1.2.12", | ||
"description": "Zero-copy binary data types", | ||
@@ -25,5 +25,5 @@ "homepage": "https://github.com/hazae41/binary", | ||
"dependencies": { | ||
"@hazae41/bytes": "^1.1.3", | ||
"@hazae41/cursor": "^1.1.3", | ||
"@hazae41/result": "^1.0.6" | ||
"@hazae41/bytes": "^1.1.4", | ||
"@hazae41/cursor": "^1.1.4", | ||
"@hazae41/result": "^1.0.7" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
@@ -36,10 +36,10 @@ <div align="center"> | ||
write(cursor: Cursor): Result<this, Error> { | ||
write(cursor: Cursor): Result<void, Error> { | ||
try { | ||
cursor.writeUint8(this.x).unwrap() | ||
cursor.writeUint16(this.y).unwrap() | ||
cursor.tryWriteUint8(this.x).throw() | ||
cursor.tryWriteUint16(this.y).throw() | ||
return Ok.void() | ||
} catch(e: unknown) { | ||
return Err.cast(e, Error) | ||
return Err.catch(e, Error) | ||
} | ||
@@ -53,3 +53,3 @@ } | ||
const myobject = new MyObject(1, 515) | ||
const bytes = Writable.toBytes(myobject).unwrap() // Uint8Array([1, 2, 3]) | ||
const bytes = Writable.tryToBytes(myobject).unwrap() // Uint8Array([1, 2, 3]) | ||
``` | ||
@@ -67,10 +67,10 @@ | ||
static read(cursor: Cursor) { | ||
static read(cursor: Cursor): Result<MyObject, Error> { | ||
try { | ||
const x = cursor.readUint8().unwrap() | ||
const y = cursor.readUint16().unwrap() | ||
const x = cursor.tryReadUint8().throw() | ||
const y = cursor.tryReadUint16().throw() | ||
return new Ok(new this(x, y)) | ||
} catch(e: unknown) { | ||
return Err.cast(e, Error) | ||
return Err.catch(e, Error) | ||
} | ||
@@ -84,3 +84,3 @@ } | ||
const bytes = new Uint8Array([1, 2, 3]) | ||
const myobject = Readable.fromBytes(MyObject, bytes).unwrap() // MyObject(1, 515) | ||
const myobject = Readable.tryFromBytes(MyObject, bytes).unwrap() // MyObject(1, 515) | ||
``` | ||
@@ -87,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44138
603
0
Updated@hazae41/bytes@^1.1.4
Updated@hazae41/cursor@^1.1.4
Updated@hazae41/result@^1.0.7