Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message type identifier and 4 byte message length.
(src []byte)
| 22 | // Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message |
| 23 | // type identifier and 4 byte message length. |
| 24 | func (dst *Parse) Decode(src []byte) error { |
| 25 | *dst = Parse{} |
| 26 | |
| 27 | buf := bytes.NewBuffer(src) |
| 28 | |
| 29 | b, err := buf.ReadBytes(0) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | dst.Name = string(b[:len(b)-1]) |
| 34 | |
| 35 | b, err = buf.ReadBytes(0) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | dst.Query = string(b[:len(b)-1]) |
| 40 | |
| 41 | if buf.Len() < 2 { |
| 42 | return &invalidMessageFormatErr{messageType: "Parse"} |
| 43 | } |
| 44 | parameterOIDCount := int(binary.BigEndian.Uint16(buf.Next(2))) |
| 45 | |
| 46 | for range parameterOIDCount { |
| 47 | if buf.Len() < 4 { |
| 48 | return &invalidMessageFormatErr{messageType: "Parse"} |
| 49 | } |
| 50 | dst.ParameterOIDs = append(dst.ParameterOIDs, binary.BigEndian.Uint32(buf.Next(4))) |
| 51 | } |
| 52 | |
| 53 | return nil |
| 54 | } |
| 55 | |
| 56 | // Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length. |
| 57 | func (src *Parse) Encode(dst []byte) ([]byte, error) { |