Skip to main content
Notice removed Comments only by CommunityBot
Post Unlocked by CommunityBot
Post Locked by CPlus
Notice added Comments only by CPlus
Mod Moved Comments To Chat
deleted 245 characters in body
Source Link
Ewan
  • 84.6k
  • 5
  • 91
  • 189

OK, so my understanding of the question is this:

  • You are processing an incoming stream of uint8 encoded characters.
  • After decoding from uint8, there is another encoding, the HTTP transfer encoding type "chunked". Which also needs decoding
  • However, the buffer on the incoming stream, and hence the data you get on read, doesn't match the "chunks" of the wrapped encoding.

I'm going to give you a prose answer, because its late and its going to be hard to write and test something with all the libs you are using and stuff. But I think the idea should be fairly simple. (Also because haters gona close the question before it can be answered!!)

Implement a second buffer. and keep track of whether you are at the end of a chunk or not.Implement a second buffer. and keep track of whether you are at the end of a chunk or not.

When you receive the first write, you are guaranteed to be at the start of a chunk, start decoding as normal,

  • Convert each character to unicode

    Convert each character to unicode (or request body encoding from the header?)

  • When you hit the 13, 10 you have the length. SAVE THIS

    When you hit the 13 (/r), 10 (/l) you have the length. SAVE THIS

    eg 49,48,48,48 utf-8 => 1000

    Read this as hex digits 1000 = 4096

  • Read the next length characters put this in your buffer

    Read the next length number of ints and put this in your buffer

  • Put the buffer in your decoded output.

    Put the buffer in your output.

  • Wipe the buffer data

    Wipe the buffer data

  • Loop

    Loop

All good so far, but OH NO! you hit the end of the array before you get to the end of a chunk!

  • Skip moving the buffer and wiping it.
  • Next write comes in
  • Is the buffer empty? No
  • continue decodingreading and adding to the buffer until the buffer length matches the length you stored earlier
  • Put the buffer in your decoded output.
  • Wipe the buffer data
  • Loop

OK, so my understanding of the question is this:

  • You are processing an incoming stream of uint8 encoded characters.
  • After decoding from uint8, there is another encoding, the HTTP transfer encoding type "chunked". Which also needs decoding
  • However, the buffer on the incoming stream, and hence the data you get on read, doesn't match the "chunks" of the wrapped encoding.

I'm going to give you a prose answer, because its late and its going to be hard to write and test something with all the libs you are using and stuff. But I think the idea should be fairly simple. (Also because haters gona close the question before it can be answered!!)

Implement a second buffer. and keep track of whether you are at the end of a chunk or not.

When you receive the first write, you are guaranteed to be at the start of a chunk, start decoding as normal,

  • Convert each character to unicode
  • When you hit the 13, 10 you have the length. SAVE THIS
  • Read the next length characters put this in your buffer
  • Put the buffer in your decoded output.
  • Wipe the buffer data
  • Loop

All good so far, but OH NO! you hit the end of the array before you get to the end of a chunk!

  • Skip moving the buffer and wiping it.
  • Next write comes in
  • Is the buffer empty? No
  • continue decoding and adding to the buffer until the buffer length matches the length you stored earlier
  • Put the buffer in your decoded output.
  • Wipe the buffer data
  • Loop

OK, so my understanding of the question is this:

  • You are processing an incoming stream of uint8 encoded characters.
  • After decoding from uint8, there is another encoding, the HTTP transfer encoding type "chunked". Which also needs decoding
  • However, the buffer on the incoming stream, and hence the data you get on read, doesn't match the "chunks" of the wrapped encoding.

I'm going to give you a prose answer, because its late and its going to be hard to write and test something with all the libs you are using and stuff. But I think the idea should be fairly simple. (Also because haters gona close the question before it can be answered!!)

Implement a second buffer. and keep track of whether you are at the end of a chunk or not.

When you receive the first write, you are guaranteed to be at the start of a chunk, start decoding as normal,

  • Convert each character to unicode (or request body encoding from the header?)

  • When you hit the 13 (/r), 10 (/l) you have the length. SAVE THIS

    eg 49,48,48,48 utf-8 => 1000

    Read this as hex digits 1000 = 4096

  • Read the next length number of ints and put this in your buffer

  • Put the buffer in your output.

  • Wipe the buffer data

  • Loop

All good so far, but OH NO! you hit the end of the array before you get to the end of a chunk!

  • Skip moving the buffer and wiping it.
  • Next write comes in
  • Is the buffer empty? No
  • continue reading and adding to the buffer until the buffer length matches the length you stored earlier
  • Put the buffer in your output.
  • Wipe the buffer data
  • Loop
deleted 245 characters in body
Source Link
Ewan
  • 84.6k
  • 5
  • 91
  • 189

OK, so my understanding of the question is this:

  • You are processing an incoming stream of uint8 encoded characters.
  • After decoding from uint8, there is another encoding, the HTTP transfer encoding type "chunked". Which also needs decoding
  • However, the buffer on the incoming stream, and hence the data you get on read, doesn't match the "chunks" of the wrapped encoding.

I'm going to give you a prose answer, because its late and its going to be hard to write and test something with all the libs you are using and stuff. But I think the idea should be fairly simple. (Also because haters gona close the question before it can be answered!!)

Implement a second buffer. and keep track of whether you are at the end of a chunk or not.

When you receive the first write, you are guaranteed to be at the start of a chunk, start decoding as normal,

  • Convert each character to unicode
  • When you hit the 13, 10 you have the length. SAVE THIS
  • Read the next length characters put this in your buffer
  • Hit another 13, 10
  • Put the buffer in your decoded output.
  • Wipe the buffer data
  • Loop

All good so far, but OH NO! you hit the end of the array before you get to the end of a chunk!

  • Skip moving the buffer and wiping it.
  • Next write comes in
  • Is the buffer empty? No
  • continue decoding and adding to the buffer until the buffer length matches the length you hit another 13, 10stored earlier
  • Put the buffer in your decoded output.
  • Wipe the buffer data
  • Loop

Loop

If your decoded output is another writable stream, maybe you can simplify this, just read chars and remember if you are in a length section or a data section and throw away the length sections?

Presumably you also get encoded header data and stuff to filter out as well

OK, so my understanding of the question is this:

  • You are processing an incoming stream of uint8 encoded characters.
  • After decoding from uint8, there is another encoding, the HTTP transfer encoding type "chunked". Which also needs decoding
  • However, the buffer on the incoming stream, and hence the data you get on read, doesn't match the "chunks" of the wrapped encoding.

I'm going to give you a prose answer, because its late and its going to be hard to write and test something with all the libs you are using and stuff. But I think the idea should be fairly simple. (Also because haters gona close the question before it can be answered!!)

Implement a second buffer. and keep track of whether you are at the end of a chunk or not.

When you receive the first write, you are guaranteed to be at the start of a chunk, start decoding as normal,

  • Convert each character to unicode
  • When you hit the 13, 10 you have the length
  • Read the next length characters put this in your buffer
  • Hit another 13, 10
  • Put the buffer in your decoded output.
  • Wipe the buffer data

All good so far, but OH NO! you hit the end of the array before you get to the end of a chunk!

  • Skip moving the buffer and wiping it.
  • Next write comes in
  • Is the buffer empty? No
  • continue decoding and adding to the buffer until you hit another 13, 10
  • Put the buffer in your decoded output.
  • Wipe the buffer data

Loop

If your decoded output is another writable stream, maybe you can simplify this, just read chars and remember if you are in a length section or a data section and throw away the length sections?

Presumably you also get encoded header data and stuff to filter out as well

OK, so my understanding of the question is this:

  • You are processing an incoming stream of uint8 encoded characters.
  • After decoding from uint8, there is another encoding, the HTTP transfer encoding type "chunked". Which also needs decoding
  • However, the buffer on the incoming stream, and hence the data you get on read, doesn't match the "chunks" of the wrapped encoding.

I'm going to give you a prose answer, because its late and its going to be hard to write and test something with all the libs you are using and stuff. But I think the idea should be fairly simple. (Also because haters gona close the question before it can be answered!!)

Implement a second buffer. and keep track of whether you are at the end of a chunk or not.

When you receive the first write, you are guaranteed to be at the start of a chunk, start decoding as normal,

  • Convert each character to unicode
  • When you hit the 13, 10 you have the length. SAVE THIS
  • Read the next length characters put this in your buffer
  • Put the buffer in your decoded output.
  • Wipe the buffer data
  • Loop

All good so far, but OH NO! you hit the end of the array before you get to the end of a chunk!

  • Skip moving the buffer and wiping it.
  • Next write comes in
  • Is the buffer empty? No
  • continue decoding and adding to the buffer until the buffer length matches the length you stored earlier
  • Put the buffer in your decoded output.
  • Wipe the buffer data
  • Loop
Source Link
Ewan
  • 84.6k
  • 5
  • 91
  • 189

OK, so my understanding of the question is this:

  • You are processing an incoming stream of uint8 encoded characters.
  • After decoding from uint8, there is another encoding, the HTTP transfer encoding type "chunked". Which also needs decoding
  • However, the buffer on the incoming stream, and hence the data you get on read, doesn't match the "chunks" of the wrapped encoding.

I'm going to give you a prose answer, because its late and its going to be hard to write and test something with all the libs you are using and stuff. But I think the idea should be fairly simple. (Also because haters gona close the question before it can be answered!!)

Implement a second buffer. and keep track of whether you are at the end of a chunk or not.

When you receive the first write, you are guaranteed to be at the start of a chunk, start decoding as normal,

  • Convert each character to unicode
  • When you hit the 13, 10 you have the length
  • Read the next length characters put this in your buffer
  • Hit another 13, 10
  • Put the buffer in your decoded output.
  • Wipe the buffer data

All good so far, but OH NO! you hit the end of the array before you get to the end of a chunk!

  • Skip moving the buffer and wiping it.
  • Next write comes in
  • Is the buffer empty? No
  • continue decoding and adding to the buffer until you hit another 13, 10
  • Put the buffer in your decoded output.
  • Wipe the buffer data

Loop

If your decoded output is another writable stream, maybe you can simplify this, just read chars and remember if you are in a length section or a data section and throw away the length sections?

Presumably you also get encoded header data and stuff to filter out as well