(pd packetDecoder)
| 67 | } |
| 68 | |
| 69 | func (ms *MessageSet) decode(pd packetDecoder) (err error) { |
| 70 | ms.Messages = nil |
| 71 | |
| 72 | for pd.remaining() > 0 { |
| 73 | magic, err := magicValue(pd) |
| 74 | if err != nil { |
| 75 | if errors.Is(err, ErrInsufficientData) { |
| 76 | ms.PartialTrailingMessage = true |
| 77 | return nil |
| 78 | } |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | if magic > 1 { |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | msb := new(MessageBlock) |
| 87 | err = msb.decode(pd) |
| 88 | if err == nil { |
| 89 | ms.Messages = append(ms.Messages, msb) |
| 90 | } else if errors.Is(err, ErrInsufficientData) { |
| 91 | // As an optimization the server is allowed to return a partial message at the |
| 92 | // end of the message set. Clients should handle this case. So we just ignore such things. |
| 93 | if msb.Offset == -1 { |
| 94 | // This is an overflow message caused by chunked down conversion |
| 95 | ms.OverflowMessage = true |
| 96 | } else { |
| 97 | ms.PartialTrailingMessage = true |
| 98 | } |
| 99 | return nil |
| 100 | } else { |
| 101 | return err |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | func (ms *MessageSet) addMessage(msg *Message) { |
| 109 | block := new(MessageBlock) |
nothing calls this directly
no test coverage detected