ReadStringHeader reads a string header off of the wire. The user is then responsible for dealing with the next 'sz' bytes from the reader in an application-specific manner.
()
| 1208 | // for dealing with the next 'sz' bytes from |
| 1209 | // the reader in an application-specific manner. |
| 1210 | func (m *Reader) ReadStringHeader() (sz uint32, err error) { |
| 1211 | lead, err := m.R.PeekByte() |
| 1212 | if err != nil { |
| 1213 | return |
| 1214 | } |
| 1215 | if isfixstr(lead) { |
| 1216 | sz = uint32(rfixstr(lead)) |
| 1217 | m.R.Skip(1) |
| 1218 | return |
| 1219 | } |
| 1220 | var p []byte |
| 1221 | switch lead { |
| 1222 | case mstr8: |
| 1223 | p, err = m.R.Next(2) |
| 1224 | if err != nil { |
| 1225 | return |
| 1226 | } |
| 1227 | sz = uint32(p[1]) |
| 1228 | return |
| 1229 | case mstr16: |
| 1230 | p, err = m.R.Next(3) |
| 1231 | if err != nil { |
| 1232 | return |
| 1233 | } |
| 1234 | sz = uint32(big.Uint16(p[1:])) |
| 1235 | return |
| 1236 | case mstr32: |
| 1237 | p, err = m.R.Next(5) |
| 1238 | if err != nil { |
| 1239 | return |
| 1240 | } |
| 1241 | sz = big.Uint32(p[1:]) |
| 1242 | return |
| 1243 | default: |
| 1244 | err = badPrefix(StrType, lead) |
| 1245 | return |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | // ReadString reads a utf-8 string from the reader |
| 1250 | func (m *Reader) ReadString() (s string, err error) { |