func parseBinaryCommand(parser *parser, buf *streambuf.Buffer) parseResult { debug("on binary message") if !buf.Avail(memcacheHeaderSize) { return parser.needMore() } msg := parser.message msg.isBinary = true magic, _ := buf.ReadNetUint8At(0) switch magic { case MemcacheMagicRequest: msg.IsRequest = true case MemcacheMagicResponse: msg.IsRequest = false default: return parser.failing(ErrInvalidMemcacheMagic) } opcode, _ := buf.ReadNetUint8At(1) keyLen, err := buf.ReadNetUint16At(2) extraLen, _ := buf.ReadNetUint8At(4) if err != nil { return parser.failing(err) } debug("magic: %v", magic) debug("opcode: %v", opcode) debug("extra len: %v", extraLen) debug("key len: %v", keyLen) totalHeaderLen := memcacheHeaderSize + int(extraLen) + int(keyLen) debug("total header len: %v", totalHeaderLen) if !buf.Avail(totalHeaderLen) { return parser.needMore() } command := memcacheBinaryCommandTable[memcacheOpcode(opcode)] if command == nil { debug("unknown command") command = binaryUnknownCommand } msg.opcode = memcacheOpcode(opcode) msg.command = command msg.isQuiet = isQuietOpcode(msg.opcode) return parser.contWithShallow(buf, command.parse) }