Skip to content

Commit

Permalink
basic decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-zippenfenig committed Oct 19, 2023
1 parent 25de87f commit 9daa66c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ async function test_api_fetch() {
const bb = await response.arrayBuffer();
const fb = new ByteBuffer(new Uint8Array(bb));

const result = WeatherApiResponse.getSizePrefixedRootAsWeatherApiResponse(fb);
return result;
const results: WeatherApiResponse[] = [];
let pos = 0;
while (pos < fb.capacity()) {
const len = fb.readInt32(fb.position());
results.push(
WeatherApiResponse.getSizePrefixedRootAsWeatherApiResponse(fb)
);
pos += len + 4;
fb.setPosition(pos);
}
return results;
}

export { test_api_fetch, WeatherApiResponse };
Expand Down
76 changes: 74 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,82 @@
import { test_api_fetch } from '../src';

global.fetch = jest.fn(() =>
Promise.resolve({
// 2 location data, with hourly temp and precip
/*
"latitude": [52.54, 48.1],
"longitude": [13.41, 9.31],
"hourly": ["temperature_2m", "precipitation"],
"start_date": "2023-08-01",
"end_date": "2023-08-01",
}*/
arrayBuffer: () =>
Promise.resolve(
new Uint8Array([
228, 1, 0, 0, 28, 0, 0, 0, 24, 0, 30, 0, 24, 0, 20, 0, 16, 0, 15, 0,
8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 24, 0, 0, 0, 184, 0, 0, 0, 0, 65,
135, 61, 0, 0, 0, 26, 0, 0, 112, 66, 112, 102, 86, 65, 0, 0, 82, 66,
0, 0, 158, 0, 36, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0,
158, 0, 0, 0, 32, 0, 0, 0, 148, 0, 0, 0, 0, 75, 200, 100, 0, 0, 0, 0,
128, 156, 201, 100, 0, 0, 0, 0, 16, 14, 0, 0, 0, 0, 0, 0, 144, 255,
255, 255, 0, 0, 0, 9, 4, 0, 0, 0, 24, 0, 0, 0, 154, 153, 217, 63, 102,
102, 6, 64, 0, 0, 128, 63, 205, 204, 76, 62, 205, 204, 204, 61, 0, 0,
128, 63, 102, 102, 38, 64, 205, 204, 76, 64, 0, 0, 0, 64, 102, 102,
102, 63, 154, 153, 153, 62, 205, 204, 44, 64, 154, 153, 153, 63, 205,
204, 76, 62, 0, 0, 0, 0, 205, 204, 204, 61, 154, 153, 153, 62, 102,
102, 102, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 8, 0, 12, 0, 8, 0, 7, 0, 8, 0, 0, 0, 0, 0, 0, 1, 4, 0,
0, 0, 24, 0, 0, 0, 104, 145, 135, 65, 207, 247, 135, 65, 207, 247,
135, 65, 156, 196, 134, 65, 104, 145, 133, 65, 207, 247, 133, 65, 207,
247, 135, 65, 207, 247, 135, 65, 156, 196, 136, 65, 53, 94, 140, 65,
207, 247, 145, 65, 53, 94, 144, 65, 156, 196, 144, 65, 104, 145, 151,
65, 207, 247, 161, 65, 156, 196, 166, 65, 207, 247, 163, 65, 104, 145,
145, 65, 53, 94, 144, 65, 2, 43, 137, 65, 53, 94, 134, 65, 53, 94,
134, 65, 207, 247, 131, 65, 207, 247, 129, 65, 228, 1, 0, 0, 28, 0, 0,
0, 24, 0, 30, 0, 24, 0, 20, 0, 16, 0, 15, 0, 8, 0, 0, 0, 0, 0, 0, 0,
0, 0, 4, 0, 24, 0, 0, 0, 184, 0, 0, 0, 0, 78, 237, 60, 0, 0, 0, 26, 0,
0, 33, 68, 208, 204, 20, 65, 104, 102, 64, 66, 0, 0, 158, 0, 36, 0,
12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 158, 0, 0, 0, 32, 0,
0, 0, 148, 0, 0, 0, 0, 75, 200, 100, 0, 0, 0, 0, 128, 156, 201, 100,
0, 0, 0, 0, 16, 14, 0, 0, 0, 0, 0, 0, 144, 255, 255, 255, 0, 0, 0, 9,
4, 0, 0, 0, 24, 0, 0, 0, 154, 153, 153, 62, 0, 0, 0, 63, 154, 153,
153, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 205, 204, 204, 61, 0, 0,
128, 63, 154, 153, 153, 63, 205, 204, 12, 64, 154, 153, 217, 63, 51,
51, 179, 63, 154, 153, 153, 62, 205, 204, 76, 63, 0, 0, 0, 64, 205,
204, 76, 64, 205, 204, 204, 62, 205, 204, 204, 61, 205, 204, 204, 61,
0, 0, 0, 0, 205, 204, 204, 61, 205, 204, 204, 61, 205, 204, 76, 62,
205, 204, 204, 61, 8, 0, 12, 0, 8, 0, 7, 0, 8, 0, 0, 0, 0, 0, 0, 1, 4,
0, 0, 0, 24, 0, 0, 0, 180, 72, 134, 65, 26, 175, 132, 65, 231, 123,
133, 65, 26, 175, 136, 65, 26, 175, 136, 65, 129, 21, 137, 65, 129,
21, 137, 65, 129, 21, 131, 65, 180, 72, 132, 65, 78, 226, 131, 65, 78,
226, 133, 65, 129, 21, 135, 65, 231, 123, 143, 65, 231, 123, 151, 65,
26, 175, 142, 65, 129, 21, 145, 65, 180, 72, 142, 65, 129, 21, 139,
65, 78, 226, 133, 65, 26, 175, 128, 65, 206, 247, 118, 65, 2, 43, 110,
65, 155, 196, 103, 65, 206, 247, 94, 65,
]).buffer
),
json: () => Promise.resolve({ test: 100 }),
})
) as jest.Mock;

describe('index', () => {
describe('myPackage', () => {
test('aaaaa', async () => {
//const a = await test_api_fetch();
//console.log(a.latitude());
const a = await test_api_fetch();
console.log(a[0].latitude());
console.log(a.length);
//expect(a.latitude()).toBe(47);
});
});
Expand Down

0 comments on commit 9daa66c

Please sign in to comment.