Example 1 · empty
- Arguments
- chunks
[]
maxFrame16
- Expected return
{ "frames": [], "remaining": [], "error": "" }
Test data
- Input
{"chunks":[],"maxFrame":16}- Expected output
{"frames":[],"remaining":[],"error":""}
func DecodeFrames(chunks [][]byte, maxFrame int) DecodeResultFrames [][]byteRemaining []byteError stringThe runner calls your functions directly; you do not need to parse JSON.
[]
16
{
"frames": [],
"remaining": [],
"error": ""
}{"chunks":[],"maxFrame":16}{"frames":[],"remaining":[],"error":""}[
[
0
],
[
2,
65
],
[
66,
0,
0
]
]4
{
"frames": [
[
65,
66
],
[]
],
"remaining": [],
"error": ""
}{"chunks":[[0],[2,65],[66,0,0]],"maxFrame":4}{"frames":[[65,66],[]],"remaining":[],"error":""}[
[
0,
1,
0,
0
]
]1
{
"frames": [
[
0
]
],
"remaining": [
0
],
"error": ""
}{"chunks":[[0,1,0,0]],"maxFrame":1}{"frames":[[0]],"remaining":[0],"error":""}[
[
0,
1,
65,
0,
3
],
[
9
],
[
9,
9
]
]2
{
"frames": [
[
65
]
],
"remaining": [
0,
3,
9,
9,
9
],
"error": "frame_too_large"
}{"chunks":[[0,1,65,0,3],[9],[9,9]],"maxFrame":2}{"frames":[[65]],"remaining":[0,3,9,9,9],"error":"frame_too_large"}The cursor advances only over complete frames, preserving incomplete header and payload bytes for later input. Header-plus-payload checks prevent slicing beyond available input. Testing declared length before waiting for payload makes oversized input fail at the correct boundary.
O(B + F) time for B total bytes and F emitted frames when buffering and cursor movement avoid repeated copying; O(B + F) retained input/output space in the bounded exercise. Repeatedly copying the full retained buffer can be quadratic across many small chunks.
Checking execution availability…
View inputs and expected outputs. Examples do not run your code.