readStreamEntries read entries
()
| 79 | |
| 80 | // readStreamEntries read entries |
| 81 | func (dec *Decoder) readStreamEntries() ([]*model.StreamEntry, error) { |
| 82 | length, _, err := dec.readLength() |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | var result []*model.StreamEntry |
| 87 | for i := uint64(0); i < length; i++ { |
| 88 | header, err := dec.readString() |
| 89 | if err != nil { |
| 90 | return nil, err |
| 91 | } |
| 92 | cursor := 0 |
| 93 | msBin, err := readBytes(header, &cursor, 8) |
| 94 | if err != nil { |
| 95 | return nil, err |
| 96 | } |
| 97 | ms := binary.BigEndian.Uint64(msBin) |
| 98 | seqBin, err := readBytes(header, &cursor, 8) |
| 99 | if err != nil { |
| 100 | return nil, err |
| 101 | } |
| 102 | seq := binary.BigEndian.Uint64(seqBin) |
| 103 | firstId := &model.StreamId{ |
| 104 | Ms: ms, |
| 105 | Sequence: seq, |
| 106 | } |
| 107 | |
| 108 | buf, err := dec.readString() |
| 109 | if err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | cursor = 0 |
| 113 | // skip 4Byte total-bytes + 2Byte num-elements |
| 114 | _, _ = readBytes(buf, &cursor, 6) |
| 115 | entry, err := dec.readStreamEntryContent(buf, &cursor, firstId) |
| 116 | if err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | entry.FirstMsgId = firstId |
| 120 | result = append(result, entry) |
| 121 | } |
| 122 | return result, nil |
| 123 | } |
| 124 | |
| 125 | // readStreamEntryContent read messages in a stream entry |
| 126 | func (dec *Decoder) readStreamEntryContent(buf []byte, cursor *int, firstId *model.StreamId) (*model.StreamEntry, error) { |
no test coverage detected