+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/boc/utils/strings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { readString, stringToCell } from "./strings";

describe('strings', () => {
let cases: string[][] = [
[''],
['123'],
['12345678901234567890123456789012345678901234567890123456789012345678901234567890'],
['привет мир 👀 привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀привет мир 👀']
Expand Down
33 changes: 22 additions & 11 deletions src/boc/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,29 @@ export function readString(slice: Slice) {
}

function writeBuffer(src: Buffer, builder: Builder) {
if (src.length > 0) {
let bytes = Math.floor(builder.availableBits / 8);
if (src.length > bytes) {
let a = src.subarray(0, bytes);
let t = src.subarray(bytes);
builder = builder.storeBuffer(a);
let bb = beginCell();
writeBuffer(t, bb);
builder = builder.storeRef(bb.endCell());
} else {
builder = builder.storeBuffer(src);
if (src.length === 0) {
return;
}

const rootOffset = Math.floor(builder.availableBits / 8);
builder.storeBuffer(src.subarray(0, rootOffset));

const bytesPerCell = 127;
const tailSize = Math.ceil((src.length - rootOffset) / bytesPerCell);
let head: Cell | undefined;

for (let i = tailSize - 1; i >= 0; i--) {
const offset = rootOffset + i * bytesPerCell;
const piece = src.subarray(offset, offset + bytesPerCell);
const nextHead = beginCell().storeBuffer(piece);
if (head) {
nextHead.storeRef(head);
}
head = nextHead.endCell();
}

if (head) {
builder.storeRef(head);
}
}

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载