Skip to content

Commit 11de3e0

Browse files
committed
Support non-transparent-framing
1 parent 858a415 commit 11de3e0

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

format/rfc6587.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ func rfc6587ScannerSplit(data []byte, atEOF bool) (advance int, token []byte, er
2727
pLength := data[0:i]
2828
length, err := strconv.Atoi(string(pLength))
2929
if err != nil {
30+
if string(data[0:1]) == "<" {
31+
// Assume this frame uses non-transparent-framing
32+
return len(data), data, nil
33+
}
3034
return 0, nil, err
3135
}
3236
end := length + i + 1
3337
if len(data) >= end {
34-
//Return the frame with the length removed
38+
// Return the frame with the length removed
3539
return end, data[i+1 : end], nil
3640
}
3741
}

format/rfc6587_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ func (s *FormatSuite) TestRFC6587_GetSplitFuncMultiSplit(c *C) {
4545
c.Assert(i, Equals, len(find))
4646
}
4747

48+
func (s *FormatSuite) TestRFC6587_GetSplitFuncMultiSplitNonTransparentFraming(c *C) {
49+
f := RFC6587{}
50+
51+
find := []string{
52+
"<1> I am a test.",
53+
"<2> I am a test 2.",
54+
"<3> hahahah",
55+
}
56+
buf := new(bytes.Buffer)
57+
for _, i := range find {
58+
fmt.Fprintf(buf, "%s", i)
59+
}
60+
scanner := bufio.NewScanner(buf)
61+
scanner.Split(f.GetSplitFunc())
62+
63+
i := 0
64+
for scanner.Scan() {
65+
c.Assert(scanner.Text(), Equals, strings.Join(find, ""))
66+
i++
67+
}
68+
69+
c.Assert(i, Equals, 1)
70+
}
71+
4872
func (s *FormatSuite) TestRFC6587_GetSplitBadSplit(c *C) {
4973
f := RFC6587{}
5074

0 commit comments

Comments
 (0)