Frame-by-frame IMQ with an outgoing filter; HTTP interceptor hook
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2551888ed6
commit
2190230f81
6 files changed
+485
-24
No files matched your search
@@ -40,10 +40,11 @@ func TypeName(t uint64) string {
|
||||
return fmt.Sprintf("type %d", t)
|
||||
}
|
||||
|
||||
// Frame is one message: its type and the size of its data.
|
||||
// Frame is one message: its type and data (Size is len(Data)).
|
||||
type Frame struct {
|
||||
Type uint64
|
||||
Size int
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// ErrMalformed means the stream isn't IMQ framing; a Reader stops decoding after it.
|
||||
@@ -76,6 +77,12 @@ func (r *Reader) Write(data []byte) ([]Frame, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Next reads the frame at the start of b: the frame and its length in b, a length of 0 if b holds only part of it,
|
||||
// or ErrMalformed.
|
||||
func Next(b []byte) (Frame, int, error) {
|
||||
return parse(b)
|
||||
}
|
||||
|
||||
// maxFrame bounds a frame's size, so a stream that isn't IMQ isn't buffered without end.
|
||||
const maxFrame = 16 << 20
|
||||
|
||||
@@ -116,6 +123,7 @@ func parse(b []byte) (Frame, int, error) {
|
||||
return f, 0, nil
|
||||
}
|
||||
f.Size = int(size)
|
||||
f.Data = b[i : i+int(size) : i+int(size)]
|
||||
return f, i + int(size), nil
|
||||
default:
|
||||
return f, 0, ErrMalformed
|
||||
|
||||
Reference in new issue
Block a user