mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: utf8
This commit is contained in:
1 parent
63084d1855
commit
2de077a3ab
3 files changed
+19
-6
No files matched your search
+1
-1
@@ -14,7 +14,7 @@ A compact binary representation similar to JSON objects. This documentation uses
|
||||
```cpp
|
||||
struct String {
|
||||
uint32 length;
|
||||
ascii[length] value;
|
||||
utf8[length] value;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export class BkonReadStream extends ReadStream {
|
||||
}
|
||||
|
||||
magic() {
|
||||
const magic = this.ascii(4);
|
||||
const magic = this.utf8(4);
|
||||
|
||||
if (magic !== 'BKON') {
|
||||
throw new Error(`Invalid Bkon magic number: "${magic}"`);
|
||||
@@ -100,7 +100,7 @@ export class BkonReadStream extends ReadStream {
|
||||
|
||||
string() {
|
||||
const length = this.uint32();
|
||||
const string = this.ascii(length);
|
||||
const string = this.utf8(length);
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -332,11 +332,11 @@ export class BkonWriteStream extends WriteStream {
|
||||
}
|
||||
|
||||
string(value: string) {
|
||||
this.uint32(value.length);
|
||||
this.ascii(value);
|
||||
this.uint32(Buffer.byteLength(value));
|
||||
this.utf8(value);
|
||||
}
|
||||
|
||||
magic() {
|
||||
this.ascii('BKON');
|
||||
this.utf8('BKON');
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,9 @@ export class ReadStream {
|
||||
ascii(size: number) {
|
||||
return this.buffer.toString('ascii', this.increment(size), this.index);
|
||||
}
|
||||
utf8(size: number) {
|
||||
return this.buffer.toString('utf8', this.increment(size), this.index);
|
||||
}
|
||||
|
||||
int8() {
|
||||
return this.buffer.readInt8(this.increment(1));
|
||||
@@ -94,6 +97,16 @@ export class WriteStream {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
utf8(value: string) {
|
||||
const buffer = Buffer.alloc(Buffer.byteLength(value));
|
||||
|
||||
buffer.write(value, 'utf8');
|
||||
buffer.forEach((value) => {
|
||||
this.array.push(value);
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private uintN(bytes: number, value: number) {
|
||||
for (let index = 0; index < bytes; index++) {
|
||||
|
||||
Reference in new issue
Block a user