oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2
3// Network awaits alone do not move JSON processing off the main actor.
4actor SheetWireWorker {
5 func decode(_ data: Data) throws -> GridResponse {
6 try JSONDecoder().decode(GridResponse.self, from: data)
7 }
8
9 func encode(_ writes: [CellWrite], startingAt offset: Int) throws -> (data: Data, count: Int) {
10 struct Batch: Encodable { let cells: [CellWrite] }
11 var count = min(500, writes.count - offset)
12 var data = try JSONEncoder().encode(Batch(cells: Array(writes[offset..<offset + count])))
13 while data.count > 1 << 20 && count > 1 {
14 count /= 2
15 data = try JSONEncoder().encode(Batch(cells: Array(writes[offset..<offset + count])))
16 }
17 return (data, count)
18 }
19}
20