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x35, 0x2d, 0x30, 0x39, 0x2d, 0x31, 0x35, 0x54, 0x32, 0x32, 0x3a, 0x31, 0x38, 0x3a, 0x30, 0x35, 0x2b, 0x30, 0x38, 0x3a, 0x30, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x2d, 0xe7, 0x6f, 0xfd, 0x41, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x32, 0x30, 0x31, 0x35, 0x2d, 0x30, 0x39, 0x2d, 0x31, 0x35, 0x54, 0x32, 0x32, 0x3a, 0x31, 0x38, 0x3a, 0x35, 0x30, 0x2b, 0x30, 0x38, 0x3a, 0x30, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x2d, 0x41, 0x18, 0xf6, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x32, 0x30, 0x31, 0x35, 0x2d, 0x30, 0x39, 0x2d, 0x31, 0x35, 0x54, 0x32, 0x32, 0x3a, 0x31, 0x38, 0x3a, 0x35, 0x31, 0x2b, 0x30, 0x38, 0x3a, 0x30, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x2d, 0x13, 0x20, 0xd9, 0x52, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x32, 0x30, 0x31, 0x35, 0x2d, 0x30, 0x39, 0x2d, 0x31, 0x35, 0x54, 0x32, 0x32, 0x3a, 0x31, 0x38, 0x3a, 0x35, 0x34, 0x2b, 0x30, 0x38, 0x3a, 0x30, 0x30}, } messageCount := 6 { resp := FetchResponse{} (&RequestOrResponse{M: &Response{ResponseMessage: &resp}}).Unmarshal(&r) if r.Err != nil { t.Fatal(r.Err) } if len(resp) != 1 || len(resp[0].FetchMessageSetInPartitions) != 1 || len(resp[0].FetchMessageSetInPartitions[0].MessageSet) != messageCount { t.Fatal("fail to parse truncated message set") } } { r.Reset() size := r.ReadInt32() size -= 2 r.B = r.B[:size+4] (&wipro.Writer{B: r.B}).SetInt32(0, size) r.Reset() messageCount-- resp := FetchResponse{} (&RequestOrResponse{M: &Response{ResponseMessage: &resp}}).Unmarshal(&r) if r.Err != nil { t.Fatal(r.Err) } if len(resp) != 1 || len(resp[0].FetchMessageSetInPartitions) != 1 || len(resp[0].FetchMessageSetInPartitions[0].MessageSet) != 5 { t.Fatal("fail to parse truncated message set") } } }